fix some extention bug
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/** Shared Iran timezone helpers for SuperAdmin API. */
|
/** 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';
|
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. */
|
/** Jalali Y/M/D for a Date in Asia/Tehran. */
|
||||||
export function iranJalaliParts(date: Date): IranJalaliYmd {
|
export function iranJalaliParts(date: Date): IranJalaliYmd {
|
||||||
const parts = new Intl.DateTimeFormat('en-u-ca-persian', {
|
const [gy, gm, gd] = iranYmd(date).split('-').map(Number);
|
||||||
timeZone: IRAN_TZ,
|
const { jy, jm, jd } = toJalaali(gy, gm, gd);
|
||||||
year: 'numeric',
|
return { year: jy, month: jm, day: jd };
|
||||||
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') };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Noon Iran (+03:30) for a Jalali calendar day. */
|
/** Noon Iran (+03:30) for a Jalali calendar day. */
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ export class CreatePluginDto {
|
|||||||
@IsISO8601()
|
@IsISO8601()
|
||||||
chargedAt?: string;
|
chargedAt?: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsISO8601()
|
||||||
|
expiresAt?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@@ -90,6 +94,10 @@ export class UpdatePluginDto {
|
|||||||
@IsISO8601()
|
@IsISO8601()
|
||||||
chargedAt?: string | null;
|
chargedAt?: string | null;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsISO8601()
|
||||||
|
expiresAt?: string | null;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@@ -122,6 +130,10 @@ export class RenewPluginDto {
|
|||||||
@IsISO8601()
|
@IsISO8601()
|
||||||
chargedAt?: string;
|
chargedAt?: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsISO8601()
|
||||||
|
expiresAt?: string;
|
||||||
|
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@IsIn(PLUGIN_PLAN_MONTHS as unknown as number[])
|
@IsIn(PLUGIN_PLAN_MONTHS as unknown as number[])
|
||||||
|
|||||||
@@ -248,11 +248,20 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
let planMonths = dto.planMonths ?? null;
|
let planMonths = dto.planMonths ?? null;
|
||||||
let expiresAt: Date | null = 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 (chargedAt && planMonths) {
|
||||||
if (!PLUGIN_PLAN_MONTHS.includes(planMonths as any)) {
|
if (!PLUGIN_PLAN_MONTHS.includes(planMonths as any)) {
|
||||||
throw new BadRequestException('مدت اشتراک نامعتبر است');
|
throw new BadRequestException('مدت اشتراک نامعتبر است');
|
||||||
}
|
}
|
||||||
expiresAt = addIranPlanExpiry(chargedAt, planMonths);
|
if (!expiresAt) {
|
||||||
|
expiresAt = addIranPlanExpiry(chargedAt, planMonths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const settingKey =
|
const settingKey =
|
||||||
@@ -330,7 +339,16 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
if (dto.planMonths !== undefined) {
|
if (dto.planMonths !== undefined) {
|
||||||
planMonths = dto.planMonths;
|
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) &&
|
(dto.chargedAt !== undefined || dto.planMonths !== undefined) &&
|
||||||
chargedAt &&
|
chargedAt &&
|
||||||
planMonths
|
planMonths
|
||||||
@@ -358,7 +376,9 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
...(dto.priceRials !== undefined && { priceRials: dto.priceRials }),
|
...(dto.priceRials !== undefined && { priceRials: dto.priceRials }),
|
||||||
...(dto.chargedAt !== undefined && { chargedAt }),
|
...(dto.chargedAt !== undefined && { chargedAt }),
|
||||||
...(dto.planMonths !== undefined && { planMonths }),
|
...(dto.planMonths !== undefined && { planMonths }),
|
||||||
...(dto.chargedAt !== undefined || dto.planMonths !== undefined
|
...(dto.chargedAt !== undefined ||
|
||||||
|
dto.planMonths !== undefined ||
|
||||||
|
dto.expiresAt !== undefined
|
||||||
? { expiresAt }
|
? { expiresAt }
|
||||||
: {}),
|
: {}),
|
||||||
...(dto.alertDaysBefore !== undefined && {
|
...(dto.alertDaysBefore !== undefined && {
|
||||||
@@ -406,7 +426,10 @@ export class PluginsService implements OnModuleInit, OnModuleDestroy {
|
|||||||
if (Number.isNaN(chargedAt.getTime())) {
|
if (Number.isNaN(chargedAt.getTime())) {
|
||||||
throw new BadRequestException('تاریخ شارژ نامعتبر است');
|
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([
|
await this.prisma.$transaction([
|
||||||
this.prisma.pluginSubscription.update({
|
this.prisma.pluginSubscription.update({
|
||||||
|
|||||||
Reference in New Issue
Block a user