fase(17): licensing module with RSA validation
This commit is contained in:
36
dist/modules/licensing/infrastructure/http/LicensingController.js
vendored
Normal file
36
dist/modules/licensing/infrastructure/http/LicensingController.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LicensingController = void 0;
|
||||
const express_1 = require("express");
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
class LicensingController {
|
||||
constructor(licenseService) {
|
||||
this.licenseService = licenseService;
|
||||
this.router = (0, express_1.Router)();
|
||||
this.registerRoutes();
|
||||
}
|
||||
registerRoutes() {
|
||||
this.router.get('/status', this.getStatus.bind(this));
|
||||
this.router.post('/activate', this.activate.bind(this));
|
||||
}
|
||||
getStatus(_req, res) {
|
||||
res.json(this.licenseService.getStatus());
|
||||
}
|
||||
async activate(req, res) {
|
||||
const { licenseKey } = req.body;
|
||||
if (!licenseKey || typeof licenseKey !== 'string') {
|
||||
res.status(400).json({ error: 'licenseKey is required' });
|
||||
return;
|
||||
}
|
||||
const result = await this.licenseService.activate(licenseKey.trim());
|
||||
if ((0, Result_1.isErr)(result)) {
|
||||
res.status(422).json({ error: result.error });
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
message: 'License activated successfully',
|
||||
license: this.licenseService.getStatus(),
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.LicensingController = LicensingController;
|
||||
Reference in New Issue
Block a user