async verifyUserPin({ user, ...payload }: PinDto & Pick) { let pin = await this.getCachedPin(user.toString()); if (!pin) { const { pin: existingPin = null } = (await this.pinModel.findOne({ user: user }).exec()) || {}; if (!existingPin) { return false; } pin = existingPin; await this.cachePin(user.toString(), pin); } await this.decryptPin(payload.pin, pin); return true; } async verifyPin({ user, ...payload }: PinDto & Pick): Promise { try { const verified = await this.verifyUserPin({ user, pin: payload.pin }); if (!verified) { throw new BadRequestException({ statusCode: HttpStatus.BAD_REQUEST, message: 'User pin does not exist', }); } return { status: 'success', statusCode: HttpStatus.OK, message: 'Pin verified successfully', data: null, error: null, }; } catch (error) { this.logger.error(error); errorHandler(error); } } async verifyUser({ userId, pin, biometric }) { if (!pin) { return biometric === this.configService.get(BIOMETRICSKEY.BIOMETRIC_ENCRYPTION_KEY); } return this.verifyUserPin({ user: userId, pin }); }