feat: implement module otp verification
parent
538abb122f
commit
ee52a35af2
|
@ -1,6 +1,6 @@
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import {
|
import {
|
||||||
OPT_ACTION_TYPE,
|
OTP_ACTION_TYPE,
|
||||||
OTP_SOURCE,
|
OTP_SOURCE,
|
||||||
OtpVerificationEntity,
|
OtpVerificationEntity,
|
||||||
} from '../../domain/entities/otp-verification.entity';
|
} from '../../domain/entities/otp-verification.entity';
|
||||||
|
@ -15,8 +15,8 @@ export class OtpVerificationModel
|
||||||
@Column({ type: 'varchar', nullable: false })
|
@Column({ type: 'varchar', nullable: false })
|
||||||
otp_code: string;
|
otp_code: string;
|
||||||
|
|
||||||
@Column({ type: 'enum', enum: OPT_ACTION_TYPE })
|
@Column({ type: 'enum', enum: OTP_ACTION_TYPE })
|
||||||
action_type: OPT_ACTION_TYPE;
|
action_type: OTP_ACTION_TYPE;
|
||||||
|
|
||||||
@Column({ type: 'varchar', nullable: true })
|
@Column({ type: 'varchar', nullable: true })
|
||||||
target_id: string;
|
target_id: string;
|
||||||
|
|
|
@ -35,18 +35,16 @@ export class OtpVerificationService {
|
||||||
const otpCode = otpService.generateSecureOTP();
|
const otpCode = otpService.generateSecureOTP();
|
||||||
const dateNow = this.generateTimestamp();
|
const dateNow = this.generateTimestamp();
|
||||||
const expiredAt = this.generateOtpExpiration();
|
const expiredAt = this.generateOtpExpiration();
|
||||||
const source = OTP_SOURCE.WEB;
|
|
||||||
const creator = {
|
//TODO implementation from auth
|
||||||
id: 'c59f811e-873c-4472-bd58-21c111902114',
|
const creator = { id: null, name: null };
|
||||||
name: 'dev',
|
|
||||||
};
|
|
||||||
|
|
||||||
const newOtp: OtpVerificationEntity = {
|
const newOtp: OtpVerificationEntity = {
|
||||||
otp_code: otpCode,
|
otp_code: otpCode,
|
||||||
action_type: payload.action_type,
|
action_type: payload.action_type,
|
||||||
target_id: payload.target_id,
|
target_id: payload.target_id,
|
||||||
reference: payload.reference,
|
reference: payload.reference,
|
||||||
source: source,
|
source: payload.source,
|
||||||
is_used: false,
|
is_used: false,
|
||||||
is_replaced: false,
|
is_replaced: false,
|
||||||
expired_at: expiredAt,
|
expired_at: expiredAt,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { BaseEntity } from 'src/core/modules/domain/entities//base.entity';
|
import { BaseEntity } from 'src/core/modules/domain/entities//base.entity';
|
||||||
|
|
||||||
export enum OPT_ACTION_TYPE {
|
export enum OTP_ACTION_TYPE {
|
||||||
CREATE_DISCOUNT = 'CREATE_DISCOUNT',
|
CREATE_DISCOUNT = 'CREATE_DISCOUNT',
|
||||||
CANCEL_TRANSACTION = 'CANCEL_TRANSACTION',
|
CANCEL_TRANSACTION = 'CANCEL_TRANSACTION',
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ export enum OTP_SOURCE {
|
||||||
|
|
||||||
export interface OtpVerificationEntity extends BaseEntity {
|
export interface OtpVerificationEntity extends BaseEntity {
|
||||||
otp_code: string;
|
otp_code: string;
|
||||||
action_type: OPT_ACTION_TYPE;
|
action_type: OTP_ACTION_TYPE;
|
||||||
target_id: string;
|
target_id: string;
|
||||||
reference: string;
|
reference: string;
|
||||||
source: OTP_SOURCE;
|
source: OTP_SOURCE;
|
||||||
|
@ -23,7 +23,8 @@ export interface OtpVerificationEntity extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OtpRequestEntity {
|
export interface OtpRequestEntity {
|
||||||
action_type: OPT_ACTION_TYPE;
|
action_type: OTP_ACTION_TYPE;
|
||||||
|
source: OTP_SOURCE;
|
||||||
target_id: string;
|
target_id: string;
|
||||||
reference: string;
|
reference: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { IsNotEmpty, IsString, ValidateIf } from 'class-validator';
|
import { IsNotEmpty, IsString, ValidateIf } from 'class-validator';
|
||||||
import {
|
import {
|
||||||
OPT_ACTION_TYPE,
|
OTP_ACTION_TYPE,
|
||||||
|
OTP_SOURCE,
|
||||||
OtpRequestEntity,
|
OtpRequestEntity,
|
||||||
OtpVerifyEntity,
|
OtpVerifyEntity,
|
||||||
} from '../../domain/entities/otp-verification.entity';
|
} from '../../domain/entities/otp-verification.entity';
|
||||||
|
@ -10,12 +11,22 @@ export class OtpRequestDto implements OtpRequestEntity {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
example: OPT_ACTION_TYPE.CANCEL_TRANSACTION,
|
example: OTP_ACTION_TYPE.CANCEL_TRANSACTION,
|
||||||
description: 'CANCEL_TRANSACTION || CREATE_DISCOUNT',
|
description: 'CANCEL_TRANSACTION || CREATE_DISCOUNT',
|
||||||
})
|
})
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@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({
|
@ApiProperty({
|
||||||
name: 'target_id',
|
name: 'target_id',
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { OtpVerificationService } from '../data/services/otp-verification.service';
|
import { OtpVerificationService } from '../data/services/otp-verification.service';
|
||||||
import { OtpRequestDto, OtpVerifyDto } from './dto/otp-verification.dto';
|
import { OtpRequestDto, OtpVerifyDto } from './dto/otp-verification.dto';
|
||||||
|
|
||||||
|
//TODO implementation auth
|
||||||
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.OTP_VERIFICATIONS}`)
|
@Controller(`v1/${MODULE_NAME.OTP_VERIFICATIONS}`)
|
||||||
@Public()
|
@Public()
|
||||||
|
|
Loading…
Reference in New Issue