import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { RestClient } from '../../../clients'; import { IOTPCodeState, IOTPMetaData, IOTPTokenExists, IOTPTokenState } from '../models/interfaces'; /** * Crap API designed by Clite Ogiashvili */ @Injectable() export class OTPService { //#region Private Members private readonly _client: RestClient; //#endregion //#region Constructor constructor(private _configService: ConfigService) { this._client = new RestClient({ name: 'OTP_SERVICE', baseUrl: this._configService.get('EH_OTPS__REST__BASE_URL', ''), timeout: 30000, accessToken: this._configService.get('EH_OTPS__REST__ACCESS_TOKEN', ''), }); } //#endregion //#region Public APIs public async init(senderName: string, email: string, appKeyword: string) { const requestBody = { data: { senderName, email, appKeyword } }; return this._client.post(`/otp/email`, requestBody); } public async validateCode(token: string, code: string, email: string, appKeyword: string) { const requestBody = { data: { email, code, appKeyword, token } }; return this._client.post(`/otp/email/validate`, requestBody); } public async validateToken(token: string, email: string, appKeyword: string) { const requestBody = { data: { email, appKeyword, token } }; return this._client.post(`/otp/check`, requestBody); } public async validateTokenForResend(token: string, email: string, appKeyword: string) { const requestBody = { data: { email, appKeyword, token } }; return this._client.post(`/otp/resend/check`, requestBody); } //#endregion }