dcb-orange-mock/dist/controllers/otp.controller.js
Mamadou Khoussa [028918 DSI/DAC/DIF/DS] 2e2724c7a6 fix it
2025-09-21 22:47:06 +00:00

109 lines
4.4 KiB
JavaScript

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OtpController = void 0;
const common_1 = require("@nestjs/common");
const mock_data_service_1 = require("../services/mock-data.service");
let OtpController = class OtpController {
constructor(mockData) {
this.mockData = mockData;
}
createChallenge(body) {
console.log('[MOCK] OTP Challenge creation:', body);
const { challenge } = body;
if (!challenge || challenge.method !== 'OTP-SMS-AUTH') {
throw new common_1.HttpException({
error: {
code: 232740003,
message: 'Invalid input value',
description: 'Invalid challenge method'
}
}, common_1.HttpStatus.BAD_REQUEST);
}
const msisdnInput = challenge.inputs.find(i => i.type === 'MSISDN');
if (!msisdnInput) {
throw new common_1.HttpException({
error: {
code: 232740000,
message: 'Missing input',
description: 'MSISDN is required'
}
}, common_1.HttpStatus.BAD_REQUEST);
}
const challengeId = this.mockData.createOtpChallenge(msisdnInput.value, challenge.country);
return {
challenge: {
...challenge,
result: []
},
location: `/challenge/v1/challenges/${challengeId}`
};
}
validateChallenge(challengeId, body) {
console.log('[MOCK] OTP Challenge validation:', { challengeId, body });
const { challenge } = body;
const otpInput = challenge.inputs.find(i => i.type === 'confirmationCode');
if (!otpInput || !otpInput.value) {
throw new common_1.HttpException({
error: {
code: 232740203,
message: 'Invalid challenge inputs',
description: 'OTP code is required'
}
}, common_1.HttpStatus.BAD_REQUEST);
}
const result = this.mockData.validateOtp(challengeId, otpInput.value);
if (!result.success) {
throw new common_1.HttpException({
error: {
code: 232740201,
message: 'Authorization denied',
description: result.error
}
}, common_1.HttpStatus.FORBIDDEN);
}
return {
challenge: {
...challenge,
result: [
{
type: 'ise2',
value: result.ise2
}
]
}
};
}
};
exports.OtpController = OtpController;
__decorate([
(0, common_1.Post)('challenges'),
__param(0, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], OtpController.prototype, "createChallenge", null);
__decorate([
(0, common_1.Post)('challenges/:id'),
__param(0, (0, common_1.Param)('id')),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", void 0)
], OtpController.prototype, "validateChallenge", null);
exports.OtpController = OtpController = __decorate([
(0, common_1.Controller)('challenge/v1'),
__metadata("design:paramtypes", [mock_data_service_1.MockDataService])
], OtpController);
//# sourceMappingURL=otp.controller.js.map