This repository has been archived on 2026-04-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Inventory_backend/dist/session/session.controller.js
2025-09-17 23:11:25 +02:00

87 lines
3.8 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.ProfileSessionController = void 0;
const common_1 = require("@nestjs/common");
const profiles_service_1 = require("../profiles/profiles.service");
const profile_dto_1 = require("../shared/dto/profile.dto");
let ProfileSessionController = class ProfileSessionController {
profilesService;
constructor(profilesService) {
this.profilesService = profilesService;
}
async getActiveProfile(req) {
if (!req.session?.profileId) {
throw new common_1.UnauthorizedException('Aucun profil actif.');
}
const profile = await this.profilesService.findActiveById(req.session.profileId);
if (!profile) {
req.session.profileId = undefined;
throw new common_1.UnauthorizedException('Profil introuvable ou inactif.');
}
return profile;
}
async activateProfile(req, dto) {
if (!dto.profileId) {
throw new common_1.BadRequestException('profileId est requis.');
}
const profile = await this.profilesService.findActiveById(dto.profileId);
if (!profile) {
throw new common_1.UnauthorizedException('Profil introuvable ou inactif.');
}
req.session.profileId = profile.id;
return profile;
}
async logout(req) {
if (!req.session) {
return { success: true };
}
return new Promise((resolve, reject) => {
req.session.destroy((err) => {
if (err) {
return reject(new common_1.BadRequestException('Impossible de déconnecter la session.'));
}
resolve({ success: true });
});
});
}
};
exports.ProfileSessionController = ProfileSessionController;
__decorate([
(0, common_1.Get)(),
__param(0, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], ProfileSessionController.prototype, "getActiveProfile", null);
__decorate([
(0, common_1.Post)(),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, profile_dto_1.ActivateProfileDto]),
__metadata("design:returntype", Promise)
], ProfileSessionController.prototype, "activateProfile", null);
__decorate([
(0, common_1.Delete)(),
__param(0, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], ProfileSessionController.prototype, "logout", null);
exports.ProfileSessionController = ProfileSessionController = __decorate([
(0, common_1.Controller)('session/profile'),
__metadata("design:paramtypes", [profiles_service_1.ProfilesService])
], ProfileSessionController);
//# sourceMappingURL=session.controller.js.map