feat: setup verifier
parent
67129a8c69
commit
6a0b1f6e05
|
@ -104,6 +104,8 @@ import { TimeGroupModel } from './modules/item-related/time-group/data/models/ti
|
|||
|
||||
import { OtpVerificationModule } from './modules/configuration/otp-verification/otp-verification.module';
|
||||
import { OtpVerificationModel } from './modules/configuration/otp-verification/data/models/otp-verification.model';
|
||||
import { OtpVerifierModel } from './modules/configuration/otp-verification/data/models/otp-verifier.model';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ApmModule.register(),
|
||||
|
@ -168,7 +170,9 @@ import { OtpVerificationModel } from './modules/configuration/otp-verification/d
|
|||
|
||||
// Booking Online
|
||||
VerificationModel,
|
||||
|
||||
OtpVerificationModel,
|
||||
OtpVerifierModel,
|
||||
],
|
||||
synchronize: false,
|
||||
}),
|
||||
|
@ -234,7 +238,6 @@ import { OtpVerificationModel } from './modules/configuration/otp-verification/d
|
|||
|
||||
BookingOnlineAuthModule,
|
||||
BookingOrderModule,
|
||||
|
||||
OtpVerificationModule,
|
||||
],
|
||||
controllers: [],
|
||||
|
|
|
@ -46,4 +46,5 @@ export enum TABLE_NAME {
|
|||
|
||||
TIME_GROUPS = 'time_groups',
|
||||
OTP_VERIFICATIONS = 'otp_verifications',
|
||||
OTP_VERIFIER = 'otp_verifier',
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddTableOtpVerifier1749043616622 implements MigrationInterface {
|
||||
name = 'AddTableOtpVerifier1749043616622';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "otp_verifier" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "name" character varying, "phone_number" character varying NOT NULL, CONSTRAINT "PK_884e2d0873fc589a1bdc477b2ea" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE "otp_verifier"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class UpdateEnumOtpActionType1749046285398
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'UpdateEnumOtpActionType1749046285398';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."otp_verifications_action_type_enum" RENAME TO "otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_action_type_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_action_type_enum_old" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum_old" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_action_type_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."otp_verifications_action_type_enum_old" RENAME TO "otp_verifications_action_type_enum"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { OtpVerifierEntity } from '../../domain/entities/otp-verification.entity';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseModel } from 'src/core/modules/data/model/base.model';
|
||||
|
||||
@Entity(TABLE_NAME.OTP_VERIFIER)
|
||||
export class OtpVerifierModel
|
||||
extends BaseModel<OtpVerifierEntity>
|
||||
implements OtpVerifierEntity
|
||||
{
|
||||
@Column({ type: 'varchar', nullable: true })
|
||||
name: string;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false })
|
||||
phone_number: string;
|
||||
}
|
|
@ -3,19 +3,26 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|||
import { Repository } from 'typeorm';
|
||||
import { OtpVerificationModel } from '../models/otp-verification.model';
|
||||
import {
|
||||
OTP_SOURCE,
|
||||
OtpRequestEntity,
|
||||
OtpVerificationEntity,
|
||||
OtpVerifierEntity,
|
||||
// OtpVerifierEntity,
|
||||
OtpVerifyEntity,
|
||||
} from '../../domain/entities/otp-verification.entity';
|
||||
import * as moment from 'moment';
|
||||
import { OtpService } from 'src/core/helpers/otp/otp-service';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||
import { OtpVerifierModel } from '../models/otp-verifier.model';
|
||||
|
||||
@Injectable()
|
||||
export class OtpVerificationService {
|
||||
constructor(
|
||||
@InjectRepository(OtpVerificationModel)
|
||||
private readonly otpVerificationRepo: Repository<OtpVerificationModel>,
|
||||
|
||||
@InjectRepository(OtpVerifierModel)
|
||||
private readonly otpVerifierRepo: Repository<OtpVerifierModel>,
|
||||
) {}
|
||||
|
||||
private generateOtpExpiration(minutes = 5): number {
|
||||
|
@ -82,6 +89,15 @@ export class OtpVerificationService {
|
|||
|
||||
// save otp to database
|
||||
await this.otpVerificationRepo.save(newOtp);
|
||||
const verifiers: OtpVerifierEntity[] = await this.otpVerifierRepo.find();
|
||||
const notificationService = new WhatsappService();
|
||||
|
||||
// verifiers.map((v) => {
|
||||
// notificationService.sendOtpNotification({
|
||||
// phone: v.phone_number,
|
||||
// code: otpCode,
|
||||
// });
|
||||
// });
|
||||
|
||||
return {
|
||||
message: `OTP has been sent to the admin's WhatsApp.`,
|
||||
|
|
|
@ -3,6 +3,7 @@ import { BaseEntity } from 'src/core/modules/domain/entities//base.entity';
|
|||
export enum OTP_ACTION_TYPE {
|
||||
CREATE_DISCOUNT = 'CREATE_DISCOUNT',
|
||||
CANCEL_TRANSACTION = 'CANCEL_TRANSACTION',
|
||||
REJECT_RECONCILIATION = 'REJECT_RECONCILIATION',
|
||||
}
|
||||
|
||||
export enum OTP_SOURCE {
|
||||
|
@ -32,3 +33,8 @@ export interface OtpRequestEntity {
|
|||
export interface OtpVerifyEntity extends OtpRequestEntity {
|
||||
otp_code: string;
|
||||
}
|
||||
|
||||
export interface OtpVerifierEntity {
|
||||
name: string;
|
||||
phone_number: string;
|
||||
}
|
||||
|
|
|
@ -6,10 +6,14 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||
import { OtpVerificationModel } from './data/models/otp-verification.model';
|
||||
import { OtpVerificationController } from './infrastructure/otp-verification-data.controller';
|
||||
import { OtpVerificationService } from './data/services/otp-verification.service';
|
||||
import { OtpVerifierModel } from './data/models/otp-verifier.model';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature([OtpVerificationModel], CONNECTION_NAME.DEFAULT),
|
||||
TypeOrmModule.forFeature(
|
||||
[OtpVerificationModel, OtpVerifierModel],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
],
|
||||
controllers: [OtpVerificationController],
|
||||
providers: [OtpVerificationService],
|
||||
|
|
Loading…
Reference in New Issue