fix some extention bug

This commit is contained in:
2026-09-16 13:44:58 +03:30
parent cf92635c0e
commit 6ba6a9cd45
3 changed files with 43 additions and 22 deletions
+12
View File
@@ -40,6 +40,10 @@ export class CreatePluginDto {
@IsISO8601()
chargedAt?: string;
@IsOptional()
@IsISO8601()
expiresAt?: string;
@IsOptional()
@Type(() => Number)
@IsInt()
@@ -90,6 +94,10 @@ export class UpdatePluginDto {
@IsISO8601()
chargedAt?: string | null;
@IsOptional()
@IsISO8601()
expiresAt?: string | null;
@IsOptional()
@Type(() => Number)
@IsInt()
@@ -122,6 +130,10 @@ export class RenewPluginDto {
@IsISO8601()
chargedAt?: string;
@IsOptional()
@IsISO8601()
expiresAt?: string;
@Type(() => Number)
@IsInt()
@IsIn(PLUGIN_PLAN_MONTHS as unknown as number[])
+27 -4
View File
@@ -248,11 +248,20 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
let planMonths = dto.planMonths ?? null;
let expiresAt: Date | null = null;
if (dto.expiresAt) {
expiresAt = new Date(dto.expiresAt);
if (Number.isNaN(expiresAt.getTime())) {
throw new BadRequestException('تاریخ انقضا نامعتبر است');
}
}
if (chargedAt && planMonths) {
if (!PLUGIN_PLAN_MONTHS.includes(planMonths as any)) {
throw new BadRequestException('مدت اشتراک نامعتبر است');
}
expiresAt = addIranPlanExpiry(chargedAt, planMonths);
if (!expiresAt) {
expiresAt = addIranPlanExpiry(chargedAt, planMonths);
}
}
const settingKey =
@@ -330,7 +339,16 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
if (dto.planMonths !== undefined) {
planMonths = dto.planMonths;
}
if (
if (dto.expiresAt !== undefined) {
if (dto.expiresAt) {
expiresAt = new Date(dto.expiresAt);
if (Number.isNaN(expiresAt.getTime())) {
throw new BadRequestException('تاریخ انقضا نامعتبر است');
}
} else {
expiresAt = null;
}
} else if (
(dto.chargedAt !== undefined || dto.planMonths !== undefined) &&
chargedAt &&
planMonths
@@ -358,7 +376,9 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
...(dto.priceRials !== undefined && { priceRials: dto.priceRials }),
...(dto.chargedAt !== undefined && { chargedAt }),
...(dto.planMonths !== undefined && { planMonths }),
...(dto.chargedAt !== undefined || dto.planMonths !== undefined
...(dto.chargedAt !== undefined ||
dto.planMonths !== undefined ||
dto.expiresAt !== undefined
? { expiresAt }
: {}),
...(dto.alertDaysBefore !== undefined && {
@@ -406,7 +426,10 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
if (Number.isNaN(chargedAt.getTime())) {
throw new BadRequestException('تاریخ شارژ نامعتبر است');
}
const expiresAt = addIranPlanExpiry(chargedAt, dto.planMonths);
let expiresAt = dto.expiresAt ? new Date(dto.expiresAt) : addIranPlanExpiry(chargedAt, dto.planMonths);
if (Number.isNaN(expiresAt.getTime())) {
throw new BadRequestException('تاریخ انقضا نامعتبر است');
}
await this.prisma.$transaction([
this.prisma.pluginSubscription.update({