feat: implement module otp verification

pull/144/head
Firman Ramdhani 2025-06-04 20:08:55 +07:00
parent 538abb122f
commit ee52a35af2
5 changed files with 26 additions and 15 deletions

View File

@ -1,6 +1,6 @@
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import {
OPT_ACTION_TYPE,
OTP_ACTION_TYPE,
OTP_SOURCE,
OtpVerificationEntity,
} from '../../domain/entities/otp-verification.entity';
@ -15,8 +15,8 @@ export class OtpVerificationModel
@Column({ type: 'varchar', nullable: false })
otp_code: string;
@Column({ type: 'enum', enum: OPT_ACTION_TYPE })
action_type: OPT_ACTION_TYPE;
@Column({ type: 'enum', enum: OTP_ACTION_TYPE })
action_type: OTP_ACTION_TYPE;
@Column({ type: 'varchar', nullable: true })
target_id: string;

View File

@ -35,18 +35,16 @@ export class OtpVerificationService {
const otpCode = otpService.generateSecureOTP();
const dateNow = this.generateTimestamp();
const expiredAt = this.generateOtpExpiration();
const source = OTP_SOURCE.WEB;
const creator = {
id: 'c59f811e-873c-4472-bd58-21c111902114',
name: 'dev',
};
//TODO implementation from auth
const creator = { id: null, name: null };
const newOtp: OtpVerificationEntity = {
otp_code: otpCode,
action_type: payload.action_type,
target_id: payload.target_id,
reference: payload.reference,
source: source,
source: payload.source,
is_used: false,
is_replaced: false,
expired_at: expiredAt,

View File

@ -1,6 +1,6 @@
import { BaseEntity } from 'src/core/modules/domain/entities//base.entity';
export enum OPT_ACTION_TYPE {
export enum OTP_ACTION_TYPE {
CREATE_DISCOUNT = 'CREATE_DISCOUNT',
CANCEL_TRANSACTION = 'CANCEL_TRANSACTION',
}
@ -12,7 +12,7 @@ export enum OTP_SOURCE {
export interface OtpVerificationEntity extends BaseEntity {
otp_code: string;
action_type: OPT_ACTION_TYPE;
action_type: OTP_ACTION_TYPE;
target_id: string;
reference: string;
source: OTP_SOURCE;
@ -23,7 +23,8 @@ export interface OtpVerificationEntity extends BaseEntity {
}
export interface OtpRequestEntity {
action_type: OPT_ACTION_TYPE;
action_type: OTP_ACTION_TYPE;
source: OTP_SOURCE;
target_id: string;
reference: string;
}

View File

@ -1,6 +1,7 @@
import { IsNotEmpty, IsString, ValidateIf } from 'class-validator';
import {
OPT_ACTION_TYPE,
OTP_ACTION_TYPE,
OTP_SOURCE,
OtpRequestEntity,
OtpVerifyEntity,
} from '../../domain/entities/otp-verification.entity';
@ -10,12 +11,22 @@ export class OtpRequestDto implements OtpRequestEntity {
@ApiProperty({
type: String,
required: true,
example: OPT_ACTION_TYPE.CANCEL_TRANSACTION,
example: OTP_ACTION_TYPE.CANCEL_TRANSACTION,
description: 'CANCEL_TRANSACTION || CREATE_DISCOUNT',
})
@IsString()
@IsNotEmpty()
action_type: OPT_ACTION_TYPE;
action_type: OTP_ACTION_TYPE;
@ApiProperty({
type: String,
required: true,
example: OTP_SOURCE.POS,
description: 'POS || WEB',
})
@IsString()
@IsNotEmpty()
source: OTP_SOURCE;
@ApiProperty({
name: 'target_id',

View File

@ -5,6 +5,7 @@ import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { OtpVerificationService } from '../data/services/otp-verification.service';
import { OtpRequestDto, OtpVerifyDto } from './dto/otp-verification.dto';
//TODO implementation auth
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
@Controller(`v1/${MODULE_NAME.OTP_VERIFICATIONS}`)
@Public()