feat: add profiles session API
This commit is contained in:
29
dist/profiles/profiles.controller.d.ts
vendored
Normal file
29
dist/profiles/profiles.controller.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ProfilesService } from './profiles.service';
|
||||
import { CreateProfileDto } from '../shared/dto/profile.dto';
|
||||
export declare class ProfilesController {
|
||||
private readonly profilesService;
|
||||
constructor(profilesService: ProfilesService);
|
||||
findAll(): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
}[]>;
|
||||
create(dto: CreateProfileDto): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
isActive: boolean;
|
||||
}>;
|
||||
delete(id: string): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
isActive: boolean;
|
||||
} | null>;
|
||||
}
|
||||
59
dist/profiles/profiles.controller.js
vendored
Normal file
59
dist/profiles/profiles.controller.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"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.ProfilesController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const profiles_service_1 = require("./profiles.service");
|
||||
const profile_dto_1 = require("../shared/dto/profile.dto");
|
||||
let ProfilesController = class ProfilesController {
|
||||
profilesService;
|
||||
constructor(profilesService) {
|
||||
this.profilesService = profilesService;
|
||||
}
|
||||
async findAll() {
|
||||
return this.profilesService.findAllActive();
|
||||
}
|
||||
async create(dto) {
|
||||
return this.profilesService.create(dto);
|
||||
}
|
||||
async delete(id) {
|
||||
return this.profilesService.deactivate(id);
|
||||
}
|
||||
};
|
||||
exports.ProfilesController = ProfilesController;
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ProfilesController.prototype, "findAll", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [profile_dto_1.CreateProfileDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ProfilesController.prototype, "create", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(':id'),
|
||||
__param(0, (0, common_1.Param)('id')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ProfilesController.prototype, "delete", null);
|
||||
exports.ProfilesController = ProfilesController = __decorate([
|
||||
(0, common_1.Controller)('profiles'),
|
||||
__metadata("design:paramtypes", [profiles_service_1.ProfilesService])
|
||||
], ProfilesController);
|
||||
//# sourceMappingURL=profiles.controller.js.map
|
||||
1
dist/profiles/profiles.controller.js.map
vendored
Normal file
1
dist/profiles/profiles.controller.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"profiles.controller.js","sourceRoot":"","sources":["../../src/profiles/profiles.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,yDAAoD;AACpD,2DAA4D;AAGrD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACA;IAA7B,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAG3D,AAAN,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,CAAA;IAC7C,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAS,GAAqB;QACxC,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAc,EAAU;QAClC,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF,CAAA;AAjBY,gDAAkB;AAIvB;IADL,IAAA,YAAG,GAAE;;;;iDAGL;AAGK;IADL,IAAA,aAAI,GAAE;IACO,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAM,8BAAgB;;gDAEzC;AAGK;IADL,IAAA,eAAM,EAAC,KAAK,CAAC;IACA,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;;;;gDAExB;6BAhBU,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,UAAU,CAAC;qCAEyB,kCAAe;GADlD,kBAAkB,CAiB9B"}
|
||||
2
dist/profiles/profiles.module.d.ts
vendored
Normal file
2
dist/profiles/profiles.module.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare class ProfilesModule {
|
||||
}
|
||||
23
dist/profiles/profiles.module.js
vendored
Normal file
23
dist/profiles/profiles.module.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"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.ProfilesModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const profiles_controller_1 = require("./profiles.controller");
|
||||
const profiles_service_1 = require("./profiles.service");
|
||||
let ProfilesModule = class ProfilesModule {
|
||||
};
|
||||
exports.ProfilesModule = ProfilesModule;
|
||||
exports.ProfilesModule = ProfilesModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
controllers: [profiles_controller_1.ProfilesController],
|
||||
providers: [profiles_service_1.ProfilesService],
|
||||
exports: [profiles_service_1.ProfilesService],
|
||||
})
|
||||
], ProfilesModule);
|
||||
//# sourceMappingURL=profiles.module.js.map
|
||||
1
dist/profiles/profiles.module.js.map
vendored
Normal file
1
dist/profiles/profiles.module.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"profiles.module.js","sourceRoot":"","sources":["../../src/profiles/profiles.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAuC;AACvC,+DAA0D;AAC1D,yDAAoD;AAO7C,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAL1B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,wCAAkB,CAAC;QACjC,SAAS,EAAE,CAAC,kCAAe,CAAC;QAC5B,OAAO,EAAE,CAAC,kCAAe,CAAC;KAC3B,CAAC;GACW,cAAc,CAAG"}
|
||||
40
dist/profiles/profiles.service.d.ts
vendored
Normal file
40
dist/profiles/profiles.service.d.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { OnModuleInit } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateProfileDto } from '../shared/dto/profile.dto';
|
||||
export declare class ProfilesService implements OnModuleInit {
|
||||
private readonly prisma;
|
||||
constructor(prisma: PrismaService);
|
||||
onModuleInit(): Promise<void>;
|
||||
findAllActive(): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
}[]>;
|
||||
findActiveById(profileId: string): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
isActive: boolean;
|
||||
} | null>;
|
||||
create(dto: CreateProfileDto): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
isActive: boolean;
|
||||
}>;
|
||||
deactivate(profileId: string): Promise<{
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
isActive: boolean;
|
||||
} | null>;
|
||||
private ensureDefaultProfile;
|
||||
}
|
||||
126
dist/profiles/profiles.service.js
vendored
Normal file
126
dist/profiles/profiles.service.js
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
"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);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ProfilesService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../prisma/prisma.service");
|
||||
let ProfilesService = class ProfilesService {
|
||||
prisma;
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async onModuleInit() {
|
||||
await this.ensureDefaultProfile();
|
||||
}
|
||||
async findAllActive() {
|
||||
return this.prisma.profile.findMany({
|
||||
where: { isActive: true },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
async findActiveById(profileId) {
|
||||
if (!profileId)
|
||||
return null;
|
||||
return this.prisma.profile.findFirst({
|
||||
where: {
|
||||
id: profileId,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
async create(dto) {
|
||||
const firstName = dto.firstName.trim();
|
||||
const lastName = dto.lastName.trim();
|
||||
if (!firstName || !lastName) {
|
||||
throw new common_1.BadRequestException('Le prénom et le nom sont obligatoires.');
|
||||
}
|
||||
return this.prisma.profile.create({
|
||||
data: {
|
||||
firstName,
|
||||
lastName,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
async deactivate(profileId) {
|
||||
const existing = await this.prisma.profile.findUnique({ where: { id: profileId } });
|
||||
if (!existing) {
|
||||
throw new common_1.NotFoundException('Profil introuvable');
|
||||
}
|
||||
if (!existing.isActive) {
|
||||
return this.prisma.profile.findUnique({
|
||||
where: { id: profileId },
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
return this.prisma.profile.update({
|
||||
where: { id: profileId },
|
||||
data: { isActive: false },
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
async ensureDefaultProfile() {
|
||||
const count = await this.prisma.profile.count({ where: { isActive: true } });
|
||||
if (count > 0)
|
||||
return;
|
||||
const firstName = process.env.DEFAULT_PROFILE_FIRST_NAME?.trim() || 'Admin';
|
||||
const lastName = process.env.DEFAULT_PROFILE_LAST_NAME?.trim() || 'Général';
|
||||
await this.prisma.profile.create({
|
||||
data: {
|
||||
firstName,
|
||||
lastName,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
exports.ProfilesService = ProfilesService;
|
||||
exports.ProfilesService = ProfilesService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], ProfilesService);
|
||||
//# sourceMappingURL=profiles.service.js.map
|
||||
1
dist/profiles/profiles.service.js.map
vendored
Normal file
1
dist/profiles/profiles.service.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"profiles.service.js","sourceRoot":"","sources":["../../src/profiles/profiles.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiG;AACjG,6DAAwD;AAIjD,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAA;IACnC,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,CAAC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