up
This commit is contained in:
@@ -123,6 +123,7 @@ export class Migration20260626140000 extends Migration {
|
|||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`);
|
||||||
this.addSql(`
|
this.addSql(`
|
||||||
CREATE TRIGGER trg_invoice_items_recalc
|
CREATE TRIGGER trg_invoice_items_recalc
|
||||||
AFTER INSERT OR UPDATE OR DELETE
|
AFTER INSERT OR UPDATE OR DELETE
|
||||||
@@ -131,6 +132,7 @@ export class Migration20260626140000 extends Migration {
|
|||||||
EXECUTE FUNCTION recalc_invoice_totals();
|
EXECUTE FUNCTION recalc_invoice_totals();
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`);
|
||||||
this.addSql(`
|
this.addSql(`
|
||||||
CREATE TRIGGER trg_payments_recalc
|
CREATE TRIGGER trg_payments_recalc
|
||||||
AFTER INSERT OR UPDATE OR DELETE
|
AFTER INSERT OR UPDATE OR DELETE
|
||||||
@@ -138,6 +140,12 @@ export class Migration20260626140000 extends Migration {
|
|||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE FUNCTION recalc_invoice_payments();
|
EXECUTE FUNCTION recalc_invoice_payments();
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
this.addSql(`
|
||||||
|
UPDATE invoice_items
|
||||||
|
SET quantity = quantity
|
||||||
|
WHERE deleted_at IS NULL;
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
override async down(): Promise<void> {
|
override async down(): Promise<void> {
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { Migration } from '@mikro-orm/migrations';
|
||||||
|
|
||||||
|
export class Migration20260626150000 extends Migration {
|
||||||
|
|
||||||
|
override async up(): Promise<void> {
|
||||||
|
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<void> {
|
||||||
|
this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`);
|
||||||
|
this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
-1
@@ -26,7 +26,11 @@ async function bootstrap() {
|
|||||||
await app.register(fastifyCookie);
|
await app.register(fastifyCookie);
|
||||||
|
|
||||||
await app.register(multipart);
|
await app.register(multipart);
|
||||||
app.useGlobalPipes(new ValidationPipe());
|
app.useGlobalPipes(
|
||||||
|
new ValidationPipe({
|
||||||
|
transform: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
app.useGlobalInterceptors(
|
app.useGlobalInterceptors(
|
||||||
new ResponseInterceptor(),
|
new ResponseInterceptor(),
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { AdminRepository } from 'src/modules/admin/repositories/admin.repository
|
|||||||
import { AdminLoginTransformer } from '../transformers/admin-login.transformer';
|
import { AdminLoginTransformer } from '../transformers/admin-login.transformer';
|
||||||
import { UserLoginTransformer } from '../transformers/user-login.transformer';
|
import { UserLoginTransformer } from '../transformers/user-login.transformer';
|
||||||
import { OtpService } from './otp.service';
|
import { OtpService } from './otp.service';
|
||||||
|
import { normalizePhoneToLocal } from 'src/modules/util/phone.util';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
@@ -25,7 +26,7 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {
|
async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {
|
||||||
const { phone } = dto;
|
const phone = normalizePhoneToLocal(dto.phone);
|
||||||
|
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
await this.valdateAdmin(phone)
|
await this.valdateAdmin(phone)
|
||||||
@@ -41,6 +42,7 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async verifyOtp(phone: string, code: string) {
|
async verifyOtp(phone: string, code: string) {
|
||||||
|
phone = normalizePhoneToLocal(phone);
|
||||||
|
|
||||||
const cachedCode = await this.otpService.get(phone);
|
const cachedCode = await this.otpService.get(phone);
|
||||||
if (!cachedCode) throw new BadRequestException('OTP expired or not found');
|
if (!cachedCode) throw new BadRequestException('OTP expired or not found');
|
||||||
@@ -63,6 +65,7 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async verifyOtpAdmin(phone: string, code: string) {
|
async verifyOtpAdmin(phone: string, code: string) {
|
||||||
|
phone = normalizePhoneToLocal(phone);
|
||||||
|
|
||||||
const cachedCode = await this.otpService.get(phone);
|
const cachedCode = await this.otpService.get(phone);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user