feat: add profiles session API

This commit is contained in:
Matthieu
2025-09-17 23:11:25 +02:00
parent 83251b532c
commit df5bbeecb7
78 changed files with 3000 additions and 836 deletions

24
dist/session/session.controller.d.ts vendored Normal file
View File

@@ -0,0 +1,24 @@
import { Request } from 'express';
import { ProfilesService } from '../profiles/profiles.service';
import { ActivateProfileDto } from '../shared/dto/profile.dto';
export declare class ProfileSessionController {
private readonly profilesService;
constructor(profilesService: ProfilesService);
getActiveProfile(req: Request): Promise<{
id: string;
createdAt: Date;
updatedAt: Date;
firstName: string;
lastName: string;
isActive: boolean;
}>;
activateProfile(req: Request, dto: ActivateProfileDto): Promise<{
id: string;
createdAt: Date;
updatedAt: Date;
firstName: string;
lastName: string;
isActive: boolean;
}>;
logout(req: Request): Promise<unknown>;
}

87
dist/session/session.controller.js vendored Normal file
View File

@@ -0,0 +1,87 @@
"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

View File

@@ -0,0 +1 @@
{"version":3,"file":"session.controller.js","sourceRoot":"","sources":["../../src/session/session.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CASuB;AAEvB,mEAA8D;AAC9D,2DAA8D;AAGvD,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACN;IAA7B,YAA6B,eAAgC;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AO,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC1B,IAAI,GAAG,EAAE,CAAC;oBACR,OAAO,MAAM,CAAC,IAAI,4BAAmB,CAAC,uCAAuC,CAAC,CAAC,CAAA;gBACjF,CAAC;gBACD,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;YAC5B,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAhDY,4DAAwB;AAI7B;IADL,IAAA,YAAG,GAAE;IACkB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;gEAY5B;AAGK;IADL,IAAA,aAAI,GAAE;IACgB,WAAA,IAAA,YAAG,GAAE,CAAA;IAAgB,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,gCAAkB;;+DAYzE;AAGK;IADL,IAAA,eAAM,GAAE;IACK,WAAA,IAAA,YAAG,GAAE,CAAA;;;;sDAalB;mCA/CU,wBAAwB;IADpC,IAAA,mBAAU,EAAC,iBAAiB,CAAC;qCAEkB,kCAAe;GADlD,wBAAwB,CAgDpC"}

2
dist/session/session.module.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export declare class SessionModule {
}

22
dist/session/session.module.js vendored Normal file
View File

@@ -0,0 +1,22 @@
"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionModule = void 0;
const common_1 = require("@nestjs/common");
const session_controller_1 = require("./session.controller");
const profiles_module_1 = require("../profiles/profiles.module");
let SessionModule = class SessionModule {
};
exports.SessionModule = SessionModule;
exports.SessionModule = SessionModule = __decorate([
(0, common_1.Module)({
imports: [profiles_module_1.ProfilesModule],
controllers: [session_controller_1.ProfileSessionController],
})
], SessionModule);
//# sourceMappingURL=session.module.js.map

1
dist/session/session.module.js.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"session.module.js","sourceRoot":"","sources":["../../src/session/session.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAuC;AACvC,6DAA+D;AAC/D,iEAA4D;AAMrD,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IAJzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,gCAAc,CAAC;QACzB,WAAW,EAAE,CAAC,6CAAwB,CAAC;KACxC,CAAC;GACW,aAAa,CAAG"}