From c1931528cf68b82bcb545f5550f71ef908b2caa1 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Fri, 26 Jun 2026 13:24:52 +0330 Subject: [PATCH] up --- .../migrations/Migration20260626140000.ts | 8 +++++ .../migrations/Migration20260626150000.ts | 36 +++++++++++++++++++ src/main.ts | 6 +++- src/modules/auth/services/auth.service.ts | 5 ++- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 database/migrations/Migration20260626150000.ts diff --git a/database/migrations/Migration20260626140000.ts b/database/migrations/Migration20260626140000.ts index e84d28c..767d33d 100644 --- a/database/migrations/Migration20260626140000.ts +++ b/database/migrations/Migration20260626140000.ts @@ -123,6 +123,7 @@ export class Migration20260626140000 extends Migration { $$ LANGUAGE plpgsql; `); + this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`); this.addSql(` CREATE TRIGGER trg_invoice_items_recalc AFTER INSERT OR UPDATE OR DELETE @@ -131,6 +132,7 @@ export class Migration20260626140000 extends Migration { EXECUTE FUNCTION recalc_invoice_totals(); `); + this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`); this.addSql(` CREATE TRIGGER trg_payments_recalc AFTER INSERT OR UPDATE OR DELETE @@ -138,6 +140,12 @@ export class Migration20260626140000 extends Migration { FOR EACH ROW EXECUTE FUNCTION recalc_invoice_payments(); `); + + this.addSql(` + UPDATE invoice_items + SET quantity = quantity + WHERE deleted_at IS NULL; + `); } override async down(): Promise { diff --git a/database/migrations/Migration20260626150000.ts b/database/migrations/Migration20260626150000.ts new file mode 100644 index 0000000..f6cb291 --- /dev/null +++ b/database/migrations/Migration20260626150000.ts @@ -0,0 +1,36 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20260626150000 extends Migration { + + override async up(): Promise { + this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`); + this.addSql(` + CREATE TRIGGER trg_invoice_items_recalc + AFTER INSERT OR UPDATE OR DELETE + ON invoice_items + FOR EACH ROW + EXECUTE FUNCTION recalc_invoice_totals(); + `); + + this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`); + this.addSql(` + CREATE TRIGGER trg_payments_recalc + AFTER INSERT OR UPDATE OR DELETE + ON payments + FOR EACH ROW + EXECUTE FUNCTION recalc_invoice_payments(); + `); + + this.addSql(` + UPDATE invoice_items + SET quantity = quantity + WHERE deleted_at IS NULL; + `); + } + + override async down(): Promise { + this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`); + this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`); + } + +} diff --git a/src/main.ts b/src/main.ts index 77c1815..efff05e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,7 +26,11 @@ async function bootstrap() { await app.register(fastifyCookie); await app.register(multipart); - app.useGlobalPipes(new ValidationPipe()); + app.useGlobalPipes( + new ValidationPipe({ + transform: true, + }), + ); app.useGlobalInterceptors( new ResponseInterceptor(), diff --git a/src/modules/auth/services/auth.service.ts b/src/modules/auth/services/auth.service.ts index f09c475..46f576b 100644 --- a/src/modules/auth/services/auth.service.ts +++ b/src/modules/auth/services/auth.service.ts @@ -9,6 +9,7 @@ import { AdminRepository } from 'src/modules/admin/repositories/admin.repository import { AdminLoginTransformer } from '../transformers/admin-login.transformer'; import { UserLoginTransformer } from '../transformers/user-login.transformer'; import { OtpService } from './otp.service'; +import { normalizePhoneToLocal } from 'src/modules/util/phone.util'; @Injectable() export class AuthService { @@ -25,7 +26,7 @@ export class AuthService { } async requestOtp(dto: RequestOtpDto, isAdmin: boolean) { - const { phone } = dto; + const phone = normalizePhoneToLocal(dto.phone); if (isAdmin) { await this.valdateAdmin(phone) @@ -41,6 +42,7 @@ export class AuthService { } async verifyOtp(phone: string, code: string) { + phone = normalizePhoneToLocal(phone); const cachedCode = await this.otpService.get(phone); if (!cachedCode) throw new BadRequestException('OTP expired or not found'); @@ -63,6 +65,7 @@ export class AuthService { } async verifyOtpAdmin(phone: string, code: string) { + phone = normalizePhoneToLocal(phone); const cachedCode = await this.otpService.get(phone);