fix some extention bug
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/** Shared Iran timezone helpers for SuperAdmin API. */
|
||||
|
||||
import { toGregorian, jalaaliMonthLength } from 'jalaali-js';
|
||||
import { toGregorian, jalaaliMonthLength, toJalaali } from 'jalaali-js';
|
||||
|
||||
export const IRAN_TZ = 'Asia/Tehran';
|
||||
|
||||
@@ -45,23 +45,9 @@ export type IranJalaliYmd = { year: number; month: number; day: number };
|
||||
|
||||
/** Jalali Y/M/D for a Date in Asia/Tehran. */
|
||||
export function iranJalaliParts(date: Date): IranJalaliYmd {
|
||||
const parts = new Intl.DateTimeFormat('en-u-ca-persian', {
|
||||
timeZone: IRAN_TZ,
|
||||
year: 'numeric',
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
}).formatToParts(date);
|
||||
|
||||
const num = (type: Intl.DateTimeFormatPartTypes) => {
|
||||
const raw = parts.find((p) => p.type === type)?.value ?? '';
|
||||
const n = Number(raw);
|
||||
if (!Number.isFinite(n)) {
|
||||
throw new Error(`Cannot read Jalali ${type} from ${date.toISOString()}`);
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
return { year: num('year'), month: num('month'), day: num('day') };
|
||||
const [gy, gm, gd] = iranYmd(date).split('-').map(Number);
|
||||
const { jy, jm, jd } = toJalaali(gy, gm, gd);
|
||||
return { year: jy, month: jm, day: jd };
|
||||
}
|
||||
|
||||
/** Noon Iran (+03:30) for a Jalali calendar day. */
|
||||
|
||||
@@ -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[])
|
||||
|
||||
@@ -248,12 +248,21 @@ 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('مدت اشتراک نامعتبر است');
|
||||
}
|
||||
if (!expiresAt) {
|
||||
expiresAt = addIranPlanExpiry(chargedAt, planMonths);
|
||||
}
|
||||
}
|
||||
|
||||
const settingKey =
|
||||
tenant.product === 'khanegi'
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user