fix(build): resolve linter and tsconfig project service errors, guarantee dist/main existence in start-dev
Deploy Canina / deploy (push) Has been cancelled

This commit is contained in:
parsa aghaei committed 2026-08-18 20:23:59 +03:30
1 parent a291fa0c4a
commit 6362750dea
50 files changed
+12128 -10959

No files matched your search

@@ -15,12 +15,16 @@ export class AdminTransactionFilterDto {
@IsNumber()
limit?: number = 15;
@ApiPropertyOptional({ description: 'جستجو (نام، موبایل، کد پیگیری، شماره مرجع، کد رهگیری)' })
@ApiPropertyOptional({
description: 'جستجو (نام، موبایل، کد پیگیری، شماره مرجع، کد رهگیری)',
})
@IsOptional()
@IsString()
search?: string;
@ApiPropertyOptional({ description: 'فیلتر وضعیت (VERIFIED, PENDING, FAILED)' })
@ApiPropertyOptional({
description: 'فیلتر وضعیت (VERIFIED, PENDING, FAILED)',
})
@IsOptional()
@IsString()
status?: string;
@@ -30,7 +34,9 @@ export class AdminTransactionFilterDto {
@IsString()
gateway?: string;
@ApiPropertyOptional({ description: 'فیلتر نوع تراکنش (ORDER, WALLET_TOPUP)' })
@ApiPropertyOptional({
description: 'فیلتر نوع تراکنش (ORDER, WALLET_TOPUP)',
})
@IsOptional()
@IsString()
type?: string;
@@ -62,7 +68,10 @@ export class AdminTransactionFilterDto {
@IsString()
sortBy?: string = 'createdAt';
@ApiPropertyOptional({ description: 'جهت مرتب‌سازی (asc, desc)', default: 'desc' })
@ApiPropertyOptional({
description: 'جهت مرتب‌سازی (asc, desc)',
default: 'desc',
})
@IsOptional()
@IsIn(['asc', 'desc'])
sortOrder?: 'asc' | 'desc' = 'desc';
+20 -7
View File
@@ -152,10 +152,16 @@ export class PaymentController {
if (!trackId) {
throw new BadRequestException('trackId is required');
}
return this.paymentService.verifyAndProcess(trackId, success, status, orderId, {
ipAddress: ip,
userAgent,
});
return this.paymentService.verifyAndProcess(
trackId,
success,
status,
orderId,
{
ipAddress: ip,
userAgent,
},
);
}
@Post('zibal/callback')
@@ -218,7 +224,9 @@ export class PaymentController {
@Roles('Admin')
@ApiBearerAuth()
@Post('admin/reconcile')
@ApiOperation({ summary: 'اجرای فرایند انطباق و استعلام خودکار تراکنش‌های بلاتکلیف' })
@ApiOperation({
summary: 'اجرای فرایند انطباق و استعلام خودکار تراکنش‌های بلاتکلیف',
})
async reconcilePending() {
return this.paymentService.reconcilePendingTransactions();
}
@@ -236,7 +244,9 @@ export class PaymentController {
@Roles('Admin')
@ApiBearerAuth()
@Post('admin/manual-verify/:id')
@ApiOperation({ summary: 'تایید دستی تراکنش یا فیش واریزی کارت‌به‌کارت توسط ادمین' })
@ApiOperation({
summary: 'تایید دستی تراکنش یا فیش واریزی کارت‌به‌کارت توسط ادمین',
})
async manualVerify(
@Param('id') id: string,
@Body() body: { adminNote?: string },
@@ -260,7 +270,10 @@ export class PaymentController {
@Roles('Admin')
@ApiBearerAuth()
@Get('admin/health')
@ApiOperation({ summary: 'بررسی وضعیت آنلاین بودن و سلامت درگاه پرداخت (Health Check & Latency)' })
@ApiOperation({
summary:
'بررسی وضعیت آنلاین بودن و سلامت درگاه پرداخت (Health Check & Latency)',
})
async getHealth() {
return this.paymentService.checkGatewayHealth();
}
+55 -23
View File
@@ -58,7 +58,8 @@ export class PaymentService {
const backendUrl = await this.zibalService.getBackendUrl();
const callbackUrl =
customCallbackUrl || `${backendUrl}/payment/zibal/callback?orderId=${order.id}`;
customCallbackUrl ||
`${backendUrl}/payment/zibal/callback?orderId=${order.id}`;
const requestPayload = {
amountRials,
@@ -81,7 +82,7 @@ export class PaymentService {
description: `پرداخت آنلاین سفارش ${order.trackingNumber || order.id}`,
ipAddress: clientMeta?.ipAddress,
userAgent: clientMeta?.userAgent,
rawRequest: requestPayload as unknown as Prisma.InputJsonValue,
rawRequest: requestPayload,
},
});
@@ -153,7 +154,8 @@ export class PaymentService {
const amountRials = Math.round(amountTomans * 10);
const backendUrl = await this.zibalService.getBackendUrl();
const callbackUrl =
customCallbackUrl || `${backendUrl}/payment/zibal/callback?type=WALLET_TOPUP`;
customCallbackUrl ||
`${backendUrl}/payment/zibal/callback?type=WALLET_TOPUP`;
const requestPayload = {
amountRials,
@@ -173,7 +175,7 @@ export class PaymentService {
description: `افزایش موجودی کیف پول کاربر ${user.mobile}`,
ipAddress: clientMeta?.ipAddress,
userAgent: clientMeta?.userAgent,
rawRequest: requestPayload as unknown as Prisma.InputJsonValue,
rawRequest: requestPayload,
},
});
@@ -355,8 +357,7 @@ export class PaymentService {
// --- AMOUNT MATCH VERIFICATION ---
const expectedAmountRials = Number(
transaction.amountRials ||
Math.round(Number(transaction.amount) * 10),
transaction.amountRials || Math.round(Number(transaction.amount) * 10),
);
if (
@@ -572,10 +573,23 @@ export class PaymentService {
`Inquiry for trackId=${tx.trackId}: status=${inquiry.status}, result=${inquiry.result}`,
);
if (inquiry.status === 1 || inquiry.status === 2 || inquiry.result === 100) {
await this.verifyAndProcess(tx.trackId, '1', String(inquiry.status), tx.orderId || undefined);
if (
inquiry.status === 1 ||
inquiry.status === 2 ||
inquiry.result === 100
) {
await this.verifyAndProcess(
tx.trackId,
'1',
String(inquiry.status),
tx.orderId || undefined,
);
results.verified++;
} else if (inquiry.status === 3 || inquiry.status === -2 || inquiry.result === 202) {
} else if (
inquiry.status === 3 ||
inquiry.status === -2 ||
inquiry.result === 202
) {
const msg = this.zibalService.getStatusMessage(inquiry.status || 3);
await this.prisma.paymentTransaction.update({
where: { id: tx.id },
@@ -654,12 +668,14 @@ export class PaymentService {
paidAt: transaction.paidAt,
createdAt: transaction.createdAt,
order: transaction.order,
user: transaction.user ? {
id: transaction.user.id,
firstName: transaction.user.firstName,
lastName: transaction.user.lastName,
mobile: transaction.user.mobile,
} : null,
user: transaction.user
? {
id: transaction.user.id,
firstName: transaction.user.firstName,
lastName: transaction.user.lastName,
mobile: transaction.user.mobile,
}
: null,
};
}
@@ -705,8 +721,10 @@ export class PaymentService {
if (minAmount !== undefined || maxAmount !== undefined) {
where.amount = {};
if (minAmount !== undefined) where.amount.gte = new Prisma.Decimal(minAmount);
if (maxAmount !== undefined) where.amount.lte = new Prisma.Decimal(maxAmount);
if (minAmount !== undefined)
where.amount.gte = new Prisma.Decimal(minAmount);
if (maxAmount !== undefined)
where.amount.lte = new Prisma.Decimal(maxAmount);
}
if (search && search.trim() !== '') {
@@ -838,13 +856,19 @@ export class PaymentService {
throw new BadRequestException('این تراکنش فاقد TrackId زیبال است');
}
const inquiryRes = await this.zibalService.inquiryPayment(transaction.trackId);
const statusMsg = this.zibalService.getStatusMessage(inquiryRes.status ?? 3);
const inquiryRes = await this.zibalService.inquiryPayment(
transaction.trackId,
);
const statusMsg = this.zibalService.getStatusMessage(
inquiryRes.status ?? 3,
);
const resultMsg = this.zibalService.getResultMessage(inquiryRes.result);
if (
transaction.status === 'PENDING' &&
(inquiryRes.status === 1 || inquiryRes.status === 2 || inquiryRes.result === 100)
(inquiryRes.status === 1 ||
inquiryRes.status === 2 ||
inquiryRes.result === 100)
) {
await this.verifyAndProcess(
transaction.trackId,
@@ -891,7 +915,9 @@ export class PaymentService {
where: { id: transactionId },
data: {
status: 'VERIFIED',
message: adminNote || 'تایید دستی توسط مدیر سیستم (کارت به کارت / فیش بانکی)',
message:
adminNote ||
'تایید دستی توسط مدیر سیستم (کارت به کارت / فیش بانکی)',
paidAt: new Date(),
},
});
@@ -924,7 +950,10 @@ export class PaymentService {
}
});
return { success: true, message: 'تراکنش با موفقیت به صورت دستی تایید و اعمال شد' };
return {
success: true,
message: 'تراکنش با موفقیت به صورت دستی تایید و اعمال شد',
};
}
/**
@@ -947,7 +976,10 @@ export class PaymentService {
},
});
return { success: true, message: 'تراکنش به عنوان ناموفق/رد شده علامت‌گذاری شد' };
return {
success: true,
message: 'تراکنش به عنوان ناموفق/رد شده علامت‌گذاری شد',
};
}
/**
+25 -10
View File
@@ -73,7 +73,9 @@ export class ZibalService implements IPaymentGateway {
if (attempt < maxRetries) {
const delayMs = delays[attempt - 1] || 1000;
this.logger.log(`Waiting ${delayMs}ms before retry attempt ${attempt + 1}...`);
this.logger.log(
`Waiting ${delayMs}ms before retry attempt ${attempt + 1}...`,
);
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
}
@@ -151,10 +153,12 @@ export class ZibalService implements IPaymentGateway {
* 1. Request Payment (درخواست پرداخت با قابلیت Retry)
* Amount must be in Rials.
*/
async requestPayment(params: PaymentRequestOptions & {
nationalCode?: string;
allowedCards?: string[];
}): Promise<ZibalRequestResponse> {
async requestPayment(
params: PaymentRequestOptions & {
nationalCode?: string;
allowedCards?: string[];
},
): Promise<ZibalRequestResponse> {
const merchant = await this.getMerchant();
const payload = {
@@ -188,7 +192,9 @@ export class ZibalService implements IPaymentGateway {
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Zibal request HTTP ${response.status}: ${errorText}`);
throw new Error(
`Zibal request HTTP ${response.status}: ${errorText}`,
);
}
const data = (await response.json()) as ZibalRequestResponse;
@@ -218,7 +224,9 @@ export class ZibalService implements IPaymentGateway {
};
return this.callWithRetry(async () => {
this.logger.log(`Verifying payment for trackId=${trackId}, merchant=${merchant}`);
this.logger.log(
`Verifying payment for trackId=${trackId}, merchant=${merchant}`,
);
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000);
@@ -249,7 +257,9 @@ export class ZibalService implements IPaymentGateway {
/**
* 4. Inquiry Payment (استعلام تراکنش با قابلیت Retry)
*/
async inquiryPayment(trackId: string | number): Promise<ZibalInquiryResponse> {
async inquiryPayment(
trackId: string | number,
): Promise<ZibalInquiryResponse> {
const merchant = await this.getMerchant();
const payload = {
@@ -275,7 +285,9 @@ export class ZibalService implements IPaymentGateway {
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Zibal inquiry HTTP ${response.status}: ${errorText}`);
throw new Error(
`Zibal inquiry HTTP ${response.status}: ${errorText}`,
);
}
const data = (await response.json()) as ZibalInquiryResponse;
@@ -313,7 +325,10 @@ export class ZibalService implements IPaymentGateway {
status: latencyMs < 1500 ? 'ONLINE' : 'DEGRADED',
latencyMs,
merchantConfigured: merchant !== 'zibal',
activeMerchant: merchant === 'zibal' ? 'zibal (تستی/سندباکس)' : `${merchant.slice(0, 4)}****`,
activeMerchant:
merchant === 'zibal'
? 'zibal (تستی/سندباکس)'
: `${merchant.slice(0, 4)}****`,
message: 'اتصال به درگاه زیبال با موفقیت برقرار است',
checkedAt: new Date(),
};