103 lines
4.4 KiB
JavaScript
103 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.SubscriptionController = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const mock_data_service_1 = require("../services/mock-data.service");
|
|
let SubscriptionController = class SubscriptionController {
|
|
constructor(mockData) {
|
|
this.mockData = mockData;
|
|
}
|
|
createSubscription(ise2, mco, body) {
|
|
console.log('[MOCK] Création subscription:', { ise2, mco, body });
|
|
if (Math.random() < 0.1) {
|
|
throw new common_1.HttpException({
|
|
requestError: {
|
|
serviceException: {
|
|
messageId: '3010',
|
|
text: 'The subscription already exists',
|
|
},
|
|
},
|
|
}, common_1.HttpStatus.CONFLICT);
|
|
}
|
|
const subscription = this.mockData.createSubscription(body);
|
|
setTimeout(() => {
|
|
this.sendSubscriptionNotification(subscription, 'orderCreation');
|
|
}, 2000);
|
|
return subscription;
|
|
}
|
|
getSubscription(id) {
|
|
const subscription = this.mockData.getSubscription(id);
|
|
if (!subscription) {
|
|
throw new common_1.HttpException({
|
|
requestError: {
|
|
serviceException: {
|
|
messageId: '3011',
|
|
text: 'Subscription not found',
|
|
},
|
|
},
|
|
}, common_1.HttpStatus.NOT_FOUND);
|
|
}
|
|
return subscription;
|
|
}
|
|
deleteSubscription(id) {
|
|
const deleted = this.mockData.deleteSubscription(id);
|
|
if (!deleted) {
|
|
throw new common_1.HttpException({
|
|
requestError: {
|
|
serviceException: {
|
|
messageId: '3011',
|
|
text: 'Subscription not found',
|
|
},
|
|
},
|
|
}, common_1.HttpStatus.NOT_FOUND);
|
|
}
|
|
setTimeout(() => {
|
|
this.sendSubscriptionNotification({ id }, 'orderDeletion');
|
|
}, 1000);
|
|
return '';
|
|
}
|
|
sendSubscriptionNotification(subscription, eventType) {
|
|
console.log(`[MOCK] Notification ${eventType} pour subscription ${subscription.id}`);
|
|
}
|
|
};
|
|
exports.SubscriptionController = SubscriptionController;
|
|
__decorate([
|
|
(0, common_1.Post)('digipay_sub/productOrder'),
|
|
__param(0, (0, common_1.Headers)('x-orange-ise2')),
|
|
__param(1, (0, common_1.Headers)('x-orange-mco')),
|
|
__param(2, (0, common_1.Body)()),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String, String, Object]),
|
|
__metadata("design:returntype", void 0)
|
|
], SubscriptionController.prototype, "createSubscription", null);
|
|
__decorate([
|
|
(0, common_1.Get)('digipay_sub/productOrder/:id'),
|
|
__param(0, (0, common_1.Param)('id')),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String]),
|
|
__metadata("design:returntype", void 0)
|
|
], SubscriptionController.prototype, "getSubscription", null);
|
|
__decorate([
|
|
(0, common_1.Delete)('digipay_sub/productOrder/:id'),
|
|
__param(0, (0, common_1.Param)('id')),
|
|
__metadata("design:type", Function),
|
|
__metadata("design:paramtypes", [String]),
|
|
__metadata("design:returntype", void 0)
|
|
], SubscriptionController.prototype, "deleteSubscription", null);
|
|
exports.SubscriptionController = SubscriptionController = __decorate([
|
|
(0, common_1.Controller)('payment/mea/v1'),
|
|
__metadata("design:paramtypes", [mock_data_service_1.MockDataService])
|
|
], SubscriptionController);
|
|
//# sourceMappingURL=subscription.controller.js.map
|