fix(types,lint): resolve all TypeScript type check and eslint errors across backend and sms suite
This commit is contained in:
1 parent
d8c6aa8d8e
commit
8de1351349
19 files changed
+11299
-8849
No files matched your search
@@ -23,7 +23,6 @@ import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiBearerAuth,
|
||||
ApiResponse,
|
||||
ApiOkResponse,
|
||||
ApiBadRequestResponse,
|
||||
} from '@nestjs/swagger';
|
||||
@@ -52,7 +51,9 @@ export class PaymentController {
|
||||
},
|
||||
},
|
||||
})
|
||||
@ApiBadRequestResponse({ description: 'خطا در ایجاد تراکنش یا نامعتبر بودن سفارش' })
|
||||
@ApiBadRequestResponse({
|
||||
description: 'خطا در ایجاد تراکنش یا نامعتبر بودن سفارش',
|
||||
})
|
||||
async initiateOrderPayment(
|
||||
@Req() req: { user: { id: string } },
|
||||
@Body() body: InitiatePaymentDto,
|
||||
@@ -91,7 +92,9 @@ export class PaymentController {
|
||||
}
|
||||
|
||||
@Get('zibal/callback')
|
||||
@ApiOperation({ summary: 'دریافت کالبک بازگشت از درگاه زیبال و تایید تراکنش' })
|
||||
@ApiOperation({
|
||||
summary: 'دریافت کالبک بازگشت از درگاه زیبال و تایید تراکنش',
|
||||
})
|
||||
async handleZibalCallback(
|
||||
@Query() query: ZibalCallbackQueryDto,
|
||||
@Res() res: Response,
|
||||
@@ -130,9 +133,10 @@ export class PaymentController {
|
||||
});
|
||||
|
||||
return res.redirect(`${frontendUrl}/payment/verify?${params.toString()}`);
|
||||
} catch (err: any) {
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : 'خطا در پردازش پرداخت';
|
||||
return res.redirect(
|
||||
`${frontendUrl}/payment/verify?success=0&trackId=${trackId}&message=${encodeURIComponent(err.message || 'خطا در پردازش پرداخت')}`,
|
||||
`${frontendUrl}/payment/verify?success=0&trackId=${trackId}&message=${encodeURIComponent(msg)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -149,7 +153,9 @@ export class PaymentController {
|
||||
const orderId = body.orderId;
|
||||
|
||||
if (!trackId) {
|
||||
return res.status(HttpStatus.BAD_REQUEST).json({ success: false, message: 'trackId is required' });
|
||||
return res
|
||||
.status(HttpStatus.BAD_REQUEST)
|
||||
.json({ success: false, message: 'trackId is required' });
|
||||
}
|
||||
|
||||
const result = await this.paymentService.verifyAndProcess(
|
||||
|
||||
@@ -46,7 +46,9 @@ export class PaymentService {
|
||||
const amountRials = Math.round(amountTomans * 10);
|
||||
|
||||
if (amountRials < 1000) {
|
||||
throw new BadRequestException('مبلغ سفارش کمتر از حداقل مجاز درگاه بانکی (۱,۰۰۰ ریال) است');
|
||||
throw new BadRequestException(
|
||||
'مبلغ سفارش کمتر از حداقل مجاز درگاه بانکی (۱,۰۰۰ ریال) است',
|
||||
);
|
||||
}
|
||||
|
||||
const frontendUrl = await this.zibalService.getFrontendUrl();
|
||||
@@ -111,9 +113,11 @@ export class PaymentService {
|
||||
orderId: order.id,
|
||||
amount: amountTomans,
|
||||
};
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Error requesting payment from Zibal: ${err.message}`, err.stack);
|
||||
throw new BadRequestException(err.message || 'خطا در اتصال به درگاه پرداخت');
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
const stack = err instanceof Error ? err.stack : undefined;
|
||||
this.logger.error(`Error requesting payment from Zibal: ${msg}`, stack);
|
||||
throw new BadRequestException(msg || 'خطا در اتصال به درگاه پرداخت');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,9 +193,10 @@ export class PaymentService {
|
||||
paymentUrl: this.zibalService.getStartUrl(trackId),
|
||||
amount: amountTomans,
|
||||
};
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Error requesting wallet topup from Zibal: ${err.message}`);
|
||||
throw new BadRequestException(err.message || 'خطا در ارتباط با درگاه بانکی');
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
this.logger.error(`Error requesting wallet topup from Zibal: ${msg}`);
|
||||
throw new BadRequestException(msg || 'خطا در ارتباط با درگاه بانکی');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +231,10 @@ export class PaymentService {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
order: {
|
||||
include: { user: true, orderItems: { include: { product: true } } },
|
||||
include: {
|
||||
user: true,
|
||||
orderItems: { include: { product: true } },
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
@@ -255,7 +263,9 @@ export class PaymentService {
|
||||
|
||||
// If user cancelled or Zibal signaled failure at the gate
|
||||
if (successParam === '0' || statusParam === '3') {
|
||||
const statusMessage = this.zibalService.getStatusMessage(statusParam || 3);
|
||||
const statusMessage = this.zibalService.getStatusMessage(
|
||||
statusParam || 3,
|
||||
);
|
||||
await this.prisma.paymentTransaction.update({
|
||||
where: { id: transaction.id },
|
||||
data: {
|
||||
@@ -301,9 +311,13 @@ export class PaymentService {
|
||||
}
|
||||
|
||||
// SUCCESSFUL PAYMENT!
|
||||
const refNumber = verifyRes.refNumber ? String(verifyRes.refNumber) : undefined;
|
||||
const refNumber = verifyRes.refNumber
|
||||
? String(verifyRes.refNumber)
|
||||
: undefined;
|
||||
const cardNumber = verifyRes.cardNumber || undefined;
|
||||
const paidDate = verifyRes.paidAt ? new Date(verifyRes.paidAt) : new Date();
|
||||
const paidDate = verifyRes.paidAt
|
||||
? new Date(verifyRes.paidAt)
|
||||
: new Date();
|
||||
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
// 1. Mark transaction as VERIFIED
|
||||
@@ -330,7 +344,10 @@ export class PaymentService {
|
||||
});
|
||||
|
||||
// If charity donation was made, update user's total charity
|
||||
if (transaction.order && Number(transaction.order.charityDonation) > 0) {
|
||||
if (
|
||||
transaction.order &&
|
||||
Number(transaction.order.charityDonation) > 0
|
||||
) {
|
||||
await tx.user.update({
|
||||
where: { id: transaction.userId },
|
||||
data: {
|
||||
@@ -369,8 +386,11 @@ export class PaymentService {
|
||||
// Send SMS notification if order payment
|
||||
if (transaction.type === 'ORDER' && transaction.order?.user?.mobile) {
|
||||
const mobile = transaction.order.user.mobile;
|
||||
const trackingNum = transaction.order.trackingNumber || transaction.order.id;
|
||||
const formattedAmount = Number(transaction.amount).toLocaleString('fa-IR');
|
||||
const trackingNum =
|
||||
transaction.order.trackingNumber || transaction.order.id;
|
||||
const formattedAmount = Number(transaction.amount).toLocaleString(
|
||||
'fa-IR',
|
||||
);
|
||||
|
||||
this.smsService
|
||||
.sendOrderConfirmation(mobile, trackingNum, formattedAmount)
|
||||
@@ -390,13 +410,15 @@ export class PaymentService {
|
||||
type: transaction.type,
|
||||
message: 'پرداخت با موفقیت انجام شد',
|
||||
};
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Error during verify: ${err.message}`, err.stack);
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
const stack = err instanceof Error ? err.stack : undefined;
|
||||
this.logger.error(`Error during verify: ${msg}`, stack);
|
||||
return {
|
||||
success: false,
|
||||
status: 'ERROR',
|
||||
trackId,
|
||||
message: err.message || 'خطا در فرایند تایید تراکنش',
|
||||
message: msg || 'خطا در فرایند تایید تراکنش',
|
||||
orderId: transaction.orderId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -115,8 +115,12 @@ export class ZibalService {
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
this.logger.error(`Zibal request HTTP error ${response.status}: ${errorText}`);
|
||||
throw new Error(`خطا در اتصال به درگاه زیبال: کد وضعیت ${response.status}`);
|
||||
this.logger.error(
|
||||
`Zibal request HTTP error ${response.status}: ${errorText}`,
|
||||
);
|
||||
throw new Error(
|
||||
`خطا در اتصال به درگاه زیبال: کد وضعیت ${response.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as ZibalRequestResponse;
|
||||
@@ -142,7 +146,9 @@ export class ZibalService {
|
||||
trackId: String(trackId),
|
||||
};
|
||||
|
||||
this.logger.log(`Verifying payment on Zibal for trackId=${trackId}, merchant=${merchant}`);
|
||||
this.logger.log(
|
||||
`Verifying payment on Zibal for trackId=${trackId}, merchant=${merchant}`,
|
||||
);
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/v1/verify`, {
|
||||
method: 'POST',
|
||||
@@ -154,8 +160,12 @@ export class ZibalService {
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
this.logger.error(`Zibal verify HTTP error ${response.status}: ${errorText}`);
|
||||
throw new Error(`خطا در تایید تراکنش درگاه زیبال: کد وضعیت ${response.status}`);
|
||||
this.logger.error(
|
||||
`Zibal verify HTTP error ${response.status}: ${errorText}`,
|
||||
);
|
||||
throw new Error(
|
||||
`خطا در تایید تراکنش درگاه زیبال: کد وضعیت ${response.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as ZibalVerifyResponse;
|
||||
@@ -166,7 +176,9 @@ export class ZibalService {
|
||||
/**
|
||||
* 4. Inquiry Payment (استعلام وضعیت تراکنش)
|
||||
*/
|
||||
async inquiryPayment(trackId: string | number): Promise<ZibalInquiryResponse> {
|
||||
async inquiryPayment(
|
||||
trackId: string | number,
|
||||
): Promise<ZibalInquiryResponse> {
|
||||
const merchant = await this.getMerchant();
|
||||
|
||||
const payload = {
|
||||
@@ -186,8 +198,12 @@ export class ZibalService {
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
this.logger.error(`Zibal inquiry HTTP error ${response.status}: ${errorText}`);
|
||||
throw new Error(`خطا در استعلام تراکنش زیبال: کد وضعیت ${response.status}`);
|
||||
this.logger.error(
|
||||
`Zibal inquiry HTTP error ${response.status}: ${errorText}`,
|
||||
);
|
||||
throw new Error(
|
||||
`خطا در استعلام تراکنش زیبال: کد وضعیت ${response.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as ZibalInquiryResponse;
|
||||
|
||||
Reference in new issue
Block a user