From 3034c59319510fba6eaff86f5c2f32862cf3df8f Mon Sep 17 00:00:00 2001 From: adonis Date: Thu, 27 Aug 2026 18:59:38 +0330 Subject: [PATCH] fix(build): ship jalaali types with production dependencies Move @types/jalaali-js into dependencies and add a local module declaration so nest build works when installing without devDependencies. Co-authored-by: Cursor --- package-lock.json | 3 +-- package.json | 2 +- src/tenants/tenants.service.ts | 11 ++++++----- src/types/jalaali-js.d.ts | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/types/jalaali-js.d.ts diff --git a/package-lock.json b/package-lock.json index 83272fb..6b3dd8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "@nestjs/passport": "^11.0.5", "@nestjs/platform-express": "^11.0.1", "@prisma/client": "6.16.0", + "@types/jalaali-js": "^1.2.0", "axios": "^1.11.0", "bcrypt": "5.1.1", "class-transformer": "^0.5.1", @@ -36,7 +37,6 @@ "@nestjs/testing": "^11.0.1", "@types/bcrypt": "5.0.2", "@types/express": "^5.0.0", - "@types/jalaali-js": "^1.2.0", "@types/jest": "^30.0.0", "@types/multer": "^2.2.0", "@types/node": "^22.0.0", @@ -3013,7 +3013,6 @@ "version": "1.2.0", "resolved": "https://registry.npmmirror.com/@types/jalaali-js/-/jalaali-js-1.2.0.tgz", "integrity": "sha512-DRQKjbfFe0/v3siCou9eFzYjDxJItkJpxbU+/CSptvoRqq2/VmTA6y8QvqK/VELKW6xX3qb174nLZlrFV9OT3Q==", - "dev": true, "license": "MIT" }, "node_modules/@types/jest": { diff --git a/package.json b/package.json index f1dd779..73fd789 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "class-transformer": "^0.5.1", "class-validator": "^0.14.2", "jalaali-js": "^2.0.1", + "@types/jalaali-js": "^1.2.0", "mysql2": "^3.23.1", "passport": "^0.7.0", "passport-jwt": "^4.0.1", @@ -72,7 +73,6 @@ "@nestjs/testing": "^11.0.1", "@types/bcrypt": "5.0.2", "@types/express": "^5.0.0", - "@types/jalaali-js": "^1.2.0", "@types/jest": "^30.0.0", "@types/multer": "^2.2.0", "@types/node": "^22.0.0", diff --git a/src/tenants/tenants.service.ts b/src/tenants/tenants.service.ts index 96cb197..fbe5225 100644 --- a/src/tenants/tenants.service.ts +++ b/src/tenants/tenants.service.ts @@ -434,12 +434,12 @@ export class TenantsService { } private handleUnique(error: unknown) { - if ( - error instanceof Prisma.PrismaClientKnownRequestError && - error.code === 'P2002' - ) { + if (!(error instanceof Prisma.PrismaClientKnownRequestError)) { + return; + } + if (error.code === 'P2002') { const targets = Array.isArray(error.meta?.target) - ? (error.meta?.target as string[]) + ? (error.meta.target as string[]) : []; if (targets.includes('slug')) { throw new ConflictException('slug تکراری است — این slug قبلاً برای نسخه دیگری ثبت شده'); @@ -451,5 +451,6 @@ export class TenantsService { } throw new ConflictException('slug یا domain تکراری است'); } + } } } diff --git a/src/types/jalaali-js.d.ts b/src/types/jalaali-js.d.ts new file mode 100644 index 0000000..ce109a2 --- /dev/null +++ b/src/types/jalaali-js.d.ts @@ -0,0 +1,19 @@ +declare module 'jalaali-js' { + export function toJalaali( + gy: number, + gm: number, + gd: number, + ): { jy: number; jm: number; jd: number } + + export function toGregorian( + jy: number, + jm: number, + jd: number, + ): { gy: number; gm: number; gd: number } + + export function isValidJalaaliDate(jy: number, jm: number, jd: number): boolean + + export function isLeapJalaaliYear(jy: number): boolean + + export function jalaaliMonthLength(jy: number, jm: number): number +}