feat: complete scheduled publishing, security remediation and DEV_TICKETS implementation
This commit is contained in:
1 parent
d6d4158cbe
commit
efb3c473c4
35 files changed
+685
-185
No files matched your search
@@ -219,10 +219,19 @@ export class PaymentController {
|
||||
return res.status(HttpStatus.OK).json(result);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('verify-status/:trackId')
|
||||
@ApiOperation({ summary: 'استعلام و دریافت وضعیت تراکنش پرداخت با TrackID' })
|
||||
async getTransactionStatus(@Param('trackId') trackId: string) {
|
||||
return this.paymentService.getTransaction(trackId);
|
||||
async getTransactionStatus(
|
||||
@Req() req: { user: { id: string; role?: string } },
|
||||
@Param('trackId') trackId: string,
|
||||
) {
|
||||
const isAdmin =
|
||||
req.user?.role === 'Admin' ||
|
||||
req.user?.role === 'ADMIN' ||
|
||||
req.user?.role === 'SuperAdmin';
|
||||
return this.paymentService.getTransaction(trackId, req.user?.id, isAdmin);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
@@ -452,6 +453,16 @@ export class PaymentService {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Increment coupon usedCount if coupon was applied
|
||||
if (transaction.order && transaction.order.couponId) {
|
||||
await tx.coupon
|
||||
.update({
|
||||
where: { id: transaction.order.couponId },
|
||||
data: { usedCount: { increment: 1 } },
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
// 3. If it's a Wallet Top-up
|
||||
@@ -765,7 +776,11 @@ export class PaymentService {
|
||||
/**
|
||||
* 5. Get Payment Transaction Details by TrackID
|
||||
*/
|
||||
async getTransaction(trackId: string) {
|
||||
async getTransaction(
|
||||
trackId: string,
|
||||
requestingUserId?: string,
|
||||
isAdmin = false,
|
||||
) {
|
||||
const transaction = await this.prisma.paymentTransaction.findUnique({
|
||||
where: { trackId },
|
||||
include: {
|
||||
@@ -784,6 +799,21 @@ export class PaymentService {
|
||||
throw new NotFoundException('تراکنش یافت نشد');
|
||||
}
|
||||
|
||||
if (
|
||||
!isAdmin &&
|
||||
requestingUserId &&
|
||||
transaction.userId &&
|
||||
transaction.userId !== requestingUserId
|
||||
) {
|
||||
throw new ForbiddenException(
|
||||
'شما دسترسی به اطلاعات این تراکنش را ندارید',
|
||||
);
|
||||
}
|
||||
|
||||
const maskedCard = transaction.cardNumber
|
||||
? transaction.cardNumber.replace(/(\d{6})\d{6}(\d{4})/, '$1******$2')
|
||||
: null;
|
||||
|
||||
return {
|
||||
id: transaction.id,
|
||||
trackId: transaction.trackId,
|
||||
@@ -793,11 +823,7 @@ export class PaymentService {
|
||||
message: transaction.message,
|
||||
gateway: transaction.gateway,
|
||||
type: transaction.type,
|
||||
cardNumber: transaction.cardNumber,
|
||||
ipAddress: transaction.ipAddress,
|
||||
userAgent: transaction.userAgent,
|
||||
rawRequest: transaction.rawRequest,
|
||||
rawResponse: transaction.rawResponse,
|
||||
cardNumber: isAdmin ? transaction.cardNumber : maskedCard,
|
||||
paidAt: transaction.paidAt,
|
||||
createdAt: transaction.createdAt,
|
||||
order: transaction.order,
|
||||
@@ -806,9 +832,17 @@ export class PaymentService {
|
||||
id: transaction.user.id,
|
||||
firstName: transaction.user.firstName,
|
||||
lastName: transaction.user.lastName,
|
||||
mobile: transaction.user.mobile,
|
||||
mobile: isAdmin ? transaction.user.mobile : undefined,
|
||||
}
|
||||
: null,
|
||||
...(isAdmin
|
||||
? {
|
||||
ipAddress: transaction.ipAddress,
|
||||
userAgent: transaction.userAgent,
|
||||
rawRequest: transaction.rawRequest,
|
||||
rawResponse: transaction.rawResponse,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user