nestcraftx 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/setup.js +7 -2
- package/unutils.txt +401 -143
- package/utils/configs/configureDocker.js +1 -1
- package/utils/configs/setupCleanArchitecture.js +204 -242
- package/utils/setups/orms/typeOrmSetup.js +1 -1
- package/utils/setups/setupAuth.js +211 -83
- package/utils/setups/setupDatabase.js +2 -2
- package/utils/setups/setupLogger.js +53 -0
- package/utils/setups/setupMongoose.js +45 -0
- package/utils/setups/setupPrisma.js +5 -1
- package/utils/setups/setupSwagger.js +6 -5
- package/utils/userInput.js +101 -225
- package/utils/utils.js +204 -43
|
@@ -13,6 +13,8 @@ const {
|
|
|
13
13
|
generateDto,
|
|
14
14
|
generateMiddlewares,
|
|
15
15
|
generateRepository,
|
|
16
|
+
generateController,
|
|
17
|
+
generateMongooseSchemaFileContent,
|
|
16
18
|
} = require("../utils");
|
|
17
19
|
|
|
18
20
|
async function setupCleanArchitecture(inputs) {
|
|
@@ -21,6 +23,7 @@ async function setupCleanArchitecture(inputs) {
|
|
|
21
23
|
|
|
22
24
|
const entitiesData = inputs.entitiesData;
|
|
23
25
|
const dbConfig = inputs.dbConfig;
|
|
26
|
+
const useSwagger = inputs.useSwagger;
|
|
24
27
|
|
|
25
28
|
const srcPath = "src";
|
|
26
29
|
const baseFolders = [
|
|
@@ -81,6 +84,16 @@ export class AppModule {}`,
|
|
|
81
84
|
await createDirectory(`${entityPath}/${folder}`);
|
|
82
85
|
}
|
|
83
86
|
|
|
87
|
+
if (dbConfig.orm === "mongoose") {
|
|
88
|
+
const mongooseSchemaContent = await generateMongooseSchemaFileContent(
|
|
89
|
+
entity
|
|
90
|
+
);
|
|
91
|
+
await createFile({
|
|
92
|
+
path: `src/${entity.name}/domain/entities/${entity.name}.schema.ts`,
|
|
93
|
+
contente: mongooseSchemaContent,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
84
97
|
// 📌 1. Entité
|
|
85
98
|
const entityContent = await generateEntityFileContent(entity);
|
|
86
99
|
await createFile({
|
|
@@ -105,136 +118,168 @@ export interface I${entityNameCapitalized}Repository {
|
|
|
105
118
|
|
|
106
119
|
// 📌 3. Repository Implémentation
|
|
107
120
|
await generateRepository(entity.name, dbConfig.orm);
|
|
108
|
-
/* await createFile({
|
|
109
|
-
path: `${entityPath}/infrastructure/repositories/${entityNameLower}.repository.ts`,
|
|
110
|
-
contente: repositoryContent,
|
|
111
|
-
}); */
|
|
112
121
|
|
|
113
122
|
// 📌 4. Use Cases
|
|
114
123
|
const useCases = ["Create", "GetById", "GetAll", "Update", "Delete"];
|
|
115
124
|
useCases.forEach(async (useCase) => {
|
|
116
125
|
let content = "";
|
|
126
|
+
const entityName = capitalize(entity.name);
|
|
127
|
+
const entityNameLower = decapitalize(entity.name);
|
|
117
128
|
|
|
118
129
|
switch (useCase) {
|
|
119
130
|
case "Create":
|
|
120
131
|
content = `/**
|
|
121
|
-
* Use Case pour créer un ${
|
|
132
|
+
* Use Case pour créer un ${entityName}.
|
|
122
133
|
*/
|
|
123
|
-
import { Inject } from '@nestjs/common';
|
|
124
|
-
import { Create${
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
134
|
+
import { Inject, Logger } from '@nestjs/common';
|
|
135
|
+
import { Create${entityName}Dto } from 'src/${entity.name}/application/dtos/${entity.name}.dto';
|
|
136
|
+
import { I${entityName}Repository } from 'src/${entity.name}/application/interfaces/${entity.name}.repository.interface';
|
|
137
|
+
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
138
|
+
|
|
139
|
+
export class Create${entityName}UseCase {
|
|
140
|
+
private readonly logger = new Logger(Create${entityName}UseCase.name);
|
|
141
|
+
|
|
132
142
|
constructor(
|
|
133
|
-
@Inject("I${
|
|
134
|
-
private readonly ${
|
|
135
|
-
entity.name
|
|
136
|
-
)}Repository,
|
|
143
|
+
@Inject("I${entityName}Repository")
|
|
144
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
137
145
|
) {}
|
|
138
146
|
|
|
139
|
-
execute(data: Create${
|
|
140
|
-
|
|
147
|
+
async execute(data: Create${entityName}Dto): Promise<${entityName}Entity> {
|
|
148
|
+
this.logger.log('Début création ${entityName}');
|
|
149
|
+
try {
|
|
150
|
+
const result = await this.${entityNameLower}Repository.create(data);
|
|
151
|
+
this.logger.log('Création réussie');
|
|
152
|
+
return result;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
this.logger.error('Erreur lors de la création', error.stack);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
141
157
|
}
|
|
142
|
-
}
|
|
158
|
+
}
|
|
159
|
+
`;
|
|
143
160
|
break;
|
|
144
161
|
|
|
145
162
|
case "GetById":
|
|
146
163
|
content = `/**
|
|
147
|
-
* Use Case pour récupérer un ${
|
|
164
|
+
* Use Case pour récupérer un ${entityName} par son ID.
|
|
148
165
|
*/
|
|
149
|
-
import { Inject } from '@nestjs/common';
|
|
150
|
-
import { I${
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
import { Inject, Logger } from '@nestjs/common';
|
|
167
|
+
import { I${entityName}Repository } from 'src/${entity.name}/application/interfaces/${entity.name}.repository.interface';
|
|
168
|
+
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
169
|
+
|
|
170
|
+
export class GetById${entityName}UseCase {
|
|
171
|
+
private readonly logger = new Logger(GetById${entityName}UseCase.name);
|
|
153
172
|
|
|
154
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
155
173
|
constructor(
|
|
156
|
-
@Inject("I${
|
|
157
|
-
private readonly ${
|
|
158
|
-
entity.name
|
|
159
|
-
)}Repository,
|
|
174
|
+
@Inject("I${entityName}Repository")
|
|
175
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
160
176
|
) {}
|
|
161
177
|
|
|
162
|
-
execute(id: string) {
|
|
163
|
-
|
|
178
|
+
async execute(id: string): Promise<${entityName}Entity | null> {
|
|
179
|
+
this.logger.log(\`Recherche de ${entityName} par id: \${id}\`);
|
|
180
|
+
try {
|
|
181
|
+
const result = await this.${entityNameLower}Repository.findById(id);
|
|
182
|
+
this.logger.log('Recherche réussie');
|
|
183
|
+
return result;
|
|
184
|
+
} catch (error) {
|
|
185
|
+
this.logger.error('Erreur lors de la recherche', error.stack);
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
164
188
|
}
|
|
165
|
-
}
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
166
191
|
break;
|
|
167
192
|
|
|
168
193
|
case "GetAll":
|
|
169
194
|
content = `/**
|
|
170
|
-
* Use Case pour récupérer tous les ${
|
|
195
|
+
* Use Case pour récupérer tous les ${entityName}s.
|
|
171
196
|
*/
|
|
172
|
-
import { Inject } from '@nestjs/common';
|
|
173
|
-
import { I${
|
|
174
|
-
|
|
175
|
-
|
|
197
|
+
import { Inject, Logger } from '@nestjs/common';
|
|
198
|
+
import { I${entityName}Repository } from 'src/${entity.name}/application/interfaces/${entity.name}.repository.interface';
|
|
199
|
+
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
200
|
+
|
|
201
|
+
export class GetAll${entityName}UseCase {
|
|
202
|
+
private readonly logger = new Logger(GetAll${entityName}UseCase.name);
|
|
176
203
|
|
|
177
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
178
204
|
constructor(
|
|
179
|
-
@Inject("I${
|
|
180
|
-
private readonly ${
|
|
181
|
-
entity.name
|
|
182
|
-
)}Repository,
|
|
205
|
+
@Inject("I${entityName}Repository")
|
|
206
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
183
207
|
) {}
|
|
184
208
|
|
|
185
|
-
execute() {
|
|
186
|
-
|
|
209
|
+
async execute(): Promise<${entityName}Entity[]> {
|
|
210
|
+
this.logger.log('Récupération de tous les ${entityName}s');
|
|
211
|
+
try {
|
|
212
|
+
const result = await this.${entityNameLower}Repository.findAll();
|
|
213
|
+
this.logger.log('Récupération réussie');
|
|
214
|
+
return result;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
this.logger.error('Erreur lors de la récupération', error.stack);
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
187
219
|
}
|
|
188
|
-
}
|
|
220
|
+
}
|
|
221
|
+
`;
|
|
189
222
|
break;
|
|
190
223
|
|
|
191
224
|
case "Update":
|
|
192
225
|
content = `/**
|
|
193
|
-
* Use Case pour mettre à jour un ${
|
|
226
|
+
* Use Case pour mettre à jour un ${entityName} existant.
|
|
194
227
|
*/
|
|
195
|
-
import { Inject } from '@nestjs/common';
|
|
196
|
-
import { Update${
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
228
|
+
import { Inject, Logger } from '@nestjs/common';
|
|
229
|
+
import { Update${entityName}Dto } from 'src/${entity.name}/application/dtos/${entity.name}.dto';
|
|
230
|
+
import { I${entityName}Repository } from 'src/${entity.name}/application/interfaces/${entity.name}.repository.interface';
|
|
231
|
+
import { ${entityName}Entity } from 'src/${entity.name}/domain/entities/${entityNameLower}.entity';
|
|
232
|
+
|
|
233
|
+
export class Update${entityName}UseCase {
|
|
234
|
+
private readonly logger = new Logger(Update${entityName}UseCase.name);
|
|
235
|
+
|
|
204
236
|
constructor(
|
|
205
|
-
@Inject("I${
|
|
206
|
-
private readonly ${
|
|
207
|
-
entity.name
|
|
208
|
-
)}Repository,
|
|
237
|
+
@Inject("I${entityName}Repository")
|
|
238
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
209
239
|
) {}
|
|
210
240
|
|
|
211
|
-
execute(id: string, data: Update${
|
|
212
|
-
|
|
241
|
+
async execute(id: string, data: Update${entityName}Dto): Promise<${entityName}Entity | null> {
|
|
242
|
+
this.logger.log(\`Mise à jour de ${entityName} id: \${id}\`);
|
|
243
|
+
try {
|
|
244
|
+
const result = await this.${entityNameLower}Repository.update(id, data);
|
|
245
|
+
this.logger.log('Mise à jour réussie');
|
|
246
|
+
return result;
|
|
247
|
+
} catch (error) {
|
|
248
|
+
this.logger.error('Erreur lors de la mise à jour', error.stack);
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
213
251
|
}
|
|
214
|
-
}
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
215
254
|
break;
|
|
216
255
|
|
|
217
256
|
case "Delete":
|
|
218
257
|
content = `/**
|
|
219
|
-
* Use Case pour supprimer un ${
|
|
258
|
+
* Use Case pour supprimer un ${entityName}.
|
|
220
259
|
*/
|
|
221
|
-
import { Inject } from '@nestjs/common';
|
|
222
|
-
import { I${
|
|
223
|
-
|
|
224
|
-
|
|
260
|
+
import { Inject, Logger } from '@nestjs/common';
|
|
261
|
+
import { I${entityName}Repository } from 'src/${entity.name}/application/interfaces/${entity.name}.repository.interface';
|
|
262
|
+
|
|
263
|
+
export class Delete${entityName}UseCase {
|
|
264
|
+
private readonly logger = new Logger(Delete${entityName}UseCase.name);
|
|
225
265
|
|
|
226
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
227
266
|
constructor(
|
|
228
|
-
@Inject("I${
|
|
229
|
-
private readonly ${
|
|
230
|
-
entity.name
|
|
231
|
-
)}Repository,
|
|
267
|
+
@Inject("I${entityName}Repository")
|
|
268
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
232
269
|
) {}
|
|
233
270
|
|
|
234
|
-
execute(id: string) {
|
|
235
|
-
|
|
271
|
+
async execute(id: string): Promise<void> {
|
|
272
|
+
this.logger.log(\`Suppression de ${entityName} id: \${id}\`);
|
|
273
|
+
try {
|
|
274
|
+
await this.${entityNameLower}Repository.delete(id);
|
|
275
|
+
this.logger.log('Suppression réussie');
|
|
276
|
+
} catch (error) {
|
|
277
|
+
this.logger.error('Erreur lors de la suppression', error.stack);
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
236
280
|
}
|
|
237
|
-
}
|
|
281
|
+
}
|
|
282
|
+
`;
|
|
238
283
|
break;
|
|
239
284
|
}
|
|
240
285
|
|
|
@@ -247,7 +292,7 @@ export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
|
247
292
|
});
|
|
248
293
|
|
|
249
294
|
// 📌 5. DTOs
|
|
250
|
-
const DtoFileContent = await generateDto(entity);
|
|
295
|
+
const DtoFileContent = await generateDto(entity, useSwagger);
|
|
251
296
|
await createFile({
|
|
252
297
|
path: `${entityPath}/application/dtos/${entity.name}.dto.ts`,
|
|
253
298
|
contente: DtoFileContent,
|
|
@@ -283,7 +328,7 @@ export enum Role {
|
|
|
283
328
|
// 📌 7. Mapper
|
|
284
329
|
const mapperFileContent = await generateMapper(entity);
|
|
285
330
|
await createFile({
|
|
286
|
-
path: `${entityPath}/domain/mappers/${
|
|
331
|
+
path: `${entityPath}/domain/mappers/${entityNameLower}.mapper.ts`,
|
|
287
332
|
contente: mapperFileContent,
|
|
288
333
|
});
|
|
289
334
|
|
|
@@ -291,53 +336,42 @@ export enum Role {
|
|
|
291
336
|
await createFile({
|
|
292
337
|
path: `${entityPath}/infrastructure/services/${entityNameLower}.service.ts`,
|
|
293
338
|
contente: `
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
import {
|
|
298
|
-
import {
|
|
339
|
+
import { Injectable } from '@nestjs/common';
|
|
340
|
+
import { Create${entityNameCapitalized}UseCase } from 'src/${entityNameLower}/application/use-cases/create-${entityNameLower}.use-case';
|
|
341
|
+
import { Update${entityNameCapitalized}UseCase } from 'src/${entityNameLower}/application/use-cases/update-${entityNameLower}.use-case';
|
|
342
|
+
import { GetById${entityNameCapitalized}UseCase } from 'src/${entityNameLower}/application/use-cases/getById-${entityNameLower}.use-case';
|
|
343
|
+
import { GetAll${entityNameCapitalized}UseCase } from 'src/${entityNameLower}/application/use-cases/getAll-${entityNameLower}.use-case';
|
|
344
|
+
import { Delete${entityNameCapitalized}UseCase } from 'src/${entityNameLower}/application/use-cases/delete-${entityNameLower}.use-case';
|
|
345
|
+
import { Create${entityNameCapitalized}Dto, Update${entityNameCapitalized}Dto } from 'src/${entityNameLower}/application/dtos/${entityNameLower}.dto';
|
|
346
|
+
import { ${entityNameCapitalized}Entity } from 'src/${entityNameLower}/domain/entities/${entityNameLower}.entity';
|
|
299
347
|
|
|
348
|
+
@Injectable()
|
|
300
349
|
export class ${entityNameCapitalized}Service {
|
|
301
350
|
constructor(
|
|
302
|
-
|
|
303
|
-
private readonly
|
|
351
|
+
private readonly createUseCase: Create${entityNameCapitalized}UseCase,
|
|
352
|
+
private readonly updateUseCase: Update${entityNameCapitalized}UseCase,
|
|
353
|
+
private readonly getByIdUseCase: GetById${entityNameCapitalized}UseCase,
|
|
354
|
+
private readonly getAllUseCase: GetAll${entityNameCapitalized}UseCase,
|
|
355
|
+
private readonly deleteUseCase: Delete${entityNameCapitalized}UseCase,
|
|
304
356
|
) {}
|
|
305
357
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (!data || !data.id) {
|
|
309
|
-
throw new Error('Données invalides, ID requis');
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const entityFromDb = await this.repository.findById(data.id);
|
|
313
|
-
|
|
314
|
-
if (!entityFromDb) {
|
|
315
|
-
throw new Error('Entité non trouvée avec cet ID');
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const processedData = {
|
|
319
|
-
...entityFromDb,
|
|
320
|
-
updatedAt: new Date(),
|
|
321
|
-
processedBy: 'System',
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
return processedData;
|
|
358
|
+
async create(dto: Create${entityNameCapitalized}Dto): Promise<${entityNameCapitalized}Entity> {
|
|
359
|
+
return await this.createUseCase.execute(dto);
|
|
325
360
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
async create(data: any) {
|
|
329
|
-
// Logique pour créer une nouvelle entité
|
|
361
|
+
async update(id: string, dto: Update${entityNameCapitalized}Dto): Promise<${entityNameCapitalized}Entity | null> {
|
|
362
|
+
return await this.updateUseCase.execute(id, dto);
|
|
330
363
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
// Logique pour mettre à jour une entité existante
|
|
364
|
+
async getById(id: string): Promise<${entityNameCapitalized}Entity | null> {
|
|
365
|
+
return await this.getByIdUseCase.execute(id);
|
|
334
366
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
367
|
+
async getAll(): Promise<${entityNameCapitalized}Entity[]> {
|
|
368
|
+
return await this.getAllUseCase.execute();
|
|
369
|
+
}
|
|
370
|
+
async delete(id: string): Promise<void> {
|
|
371
|
+
return await this.deleteUseCase.execute(id);
|
|
338
372
|
}
|
|
339
373
|
}
|
|
340
|
-
|
|
374
|
+
`.trim(),
|
|
341
375
|
});
|
|
342
376
|
|
|
343
377
|
// 📌 9. Adapter
|
|
@@ -372,99 +406,56 @@ export class ${entityNameCapitalized}Adapter {
|
|
|
372
406
|
});
|
|
373
407
|
|
|
374
408
|
// 📌 10. Controller
|
|
409
|
+
const controllerContente = await generateController(
|
|
410
|
+
entity.name,
|
|
411
|
+
entityPath,
|
|
412
|
+
useSwagger
|
|
413
|
+
);
|
|
375
414
|
await createFile({
|
|
376
415
|
path: `${entityPath}/presentation/controllers/${entityNameLower}.controller.ts`,
|
|
377
|
-
contente:
|
|
378
|
-
/**
|
|
379
|
-
* ${entityNameCapitalized}Controller gère les endpoints de l'API pour l'entité ${entityNameCapitalized}.
|
|
380
|
-
* Il utilise les cas d'utilisation (Use Cases) pour orchestrer les différentes actions métiers liées à l'entité.
|
|
381
|
-
* Ce contrôleur est responsable des actions HTTP telles que la création, la mise à jour, la récupération, et la suppression de ${entityNameCapitalized}.
|
|
382
|
-
*/
|
|
383
|
-
|
|
384
|
-
import { Controller, Get, Post, Body, Param, Put, Delete, Injectable } from "@nestjs/common";
|
|
385
|
-
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
386
|
-
// Importation des cas d'utilisation (Use Cases) spécifiques à ${entityNameCapitalized}
|
|
387
|
-
import { Create${entityNameCapitalized}UseCase } from "${entityPath}/application/use-cases/create-${entityNameLower}.use-case";
|
|
388
|
-
import { Update${entityNameCapitalized}UseCase } from "${entityPath}/application/use-cases/update-${entityNameLower}.use-case";
|
|
389
|
-
import { GetById${entityNameCapitalized}UseCase } from "${entityPath}/application/use-cases/getById-${entityNameLower}.use-case";
|
|
390
|
-
import { GetAll${entityNameCapitalized}UseCase } from "${entityPath}/application/use-cases/getAll-${entityNameLower}.use-case";
|
|
391
|
-
import { Delete${entityNameCapitalized}UseCase } from "${entityPath}/application/use-cases/delete-${entityNameLower}.use-case";
|
|
392
|
-
// Importation des DTOs pour la validation et la transformation des données entrantes
|
|
393
|
-
import { Create${entityNameCapitalized}Dto, Update${entityNameCapitalized}Dto } from 'src/${entityNameLower}/application/dtos/${entityNameLower}.dto';
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Le contrôleur est annoté avec @ApiTags pour la documentation Swagger.
|
|
397
|
-
* Il regroupe les opérations HTTP relatives à l'entité ${entityNameCapitalized}.
|
|
398
|
-
*/
|
|
399
|
-
@Injectable()
|
|
400
|
-
@ApiTags('${entityNameCapitalized}')
|
|
401
|
-
@Controller('${entityNameLower}')
|
|
402
|
-
export class ${entityNameCapitalized}Controller {
|
|
403
|
-
constructor(
|
|
404
|
-
private readonly createUseCase: Create${entityNameCapitalized}UseCase,
|
|
405
|
-
private readonly updateUseCase: Update${entityNameCapitalized}UseCase,
|
|
406
|
-
private readonly getByIdUseCase: GetById${entityNameCapitalized}UseCase,
|
|
407
|
-
private readonly getAllUseCase: GetAll${entityNameCapitalized}UseCase,
|
|
408
|
-
private readonly deleteUseCase: Delete${entityNameCapitalized}UseCase,
|
|
409
|
-
) {}
|
|
410
|
-
|
|
411
|
-
// 📌 Créer un ${entityNameLower}
|
|
412
|
-
@Post()
|
|
413
|
-
@ApiOperation({ summary: 'Create a new ${entityNameLower}' })
|
|
414
|
-
async create${entityNameCapitalized}(
|
|
415
|
-
@Body() create${entityNameCapitalized}Dto: Create${entityNameCapitalized}Dto,
|
|
416
|
-
) {
|
|
417
|
-
return this.createUseCase.execute(create${entityNameCapitalized}Dto);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// 📌 Mettre à jour un ${entityNameLower}
|
|
421
|
-
@Put(':id')
|
|
422
|
-
@ApiOperation({ summary: 'Update a ${entityNameLower}' })
|
|
423
|
-
async update${entityNameCapitalized}(
|
|
424
|
-
@Param('id') id: string,
|
|
425
|
-
@Body() update${entityNameCapitalized}Dto: Update${entityNameCapitalized}Dto,
|
|
426
|
-
) {
|
|
427
|
-
return this.updateUseCase.execute(id, update${entityNameCapitalized}Dto);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// 📌 Récupérer un ${entityNameLower} par ID
|
|
431
|
-
@Get(':id')
|
|
432
|
-
@ApiOperation({ summary: 'Get a ${entityNameLower} by ID' })
|
|
433
|
-
async getById${entityNameCapitalized}(@Param('id') id: string) {
|
|
434
|
-
return this.getByIdUseCase.execute(id);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// 📌 Récupérer tous les ${entityNameLower}s
|
|
438
|
-
@Get()
|
|
439
|
-
@ApiOperation({ summary: 'Get all ${entityNameLower}s' })
|
|
440
|
-
async getAll${entityNameCapitalized}() {
|
|
441
|
-
return this.getAllUseCase.execute();
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// 📌 Supprimer un ${entityNameLower}
|
|
445
|
-
@Delete(':id')
|
|
446
|
-
@ApiOperation({ summary: 'Delete a ${entityNameLower} by ID' })
|
|
447
|
-
async delete${entityNameCapitalized}(@Param('id') id: string) {
|
|
448
|
-
return this.deleteUseCase.execute(id);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
`,
|
|
416
|
+
contente: controllerContente,
|
|
452
417
|
});
|
|
453
418
|
|
|
454
419
|
// 📌 11. Module
|
|
455
|
-
let
|
|
456
|
-
let
|
|
457
|
-
let
|
|
458
|
-
TypeOrmModule.forFeature([${entityNameCapitalized}]), // Injection de l'entité
|
|
459
|
-
],`;
|
|
420
|
+
let importsBlock = [];
|
|
421
|
+
let providersBlock = [];
|
|
422
|
+
let extraImports = "";
|
|
460
423
|
|
|
461
424
|
if (dbConfig.orm === "prisma") {
|
|
462
|
-
|
|
463
|
-
|
|
425
|
+
extraImports = `import { PrismaService } from 'src/prisma/prisma.service';`;
|
|
426
|
+
providersBlock.push("PrismaService");
|
|
464
427
|
} else if (dbConfig.orm === "typeorm") {
|
|
465
|
-
|
|
428
|
+
extraImports = `import { ${entityNameCapitalized} } from 'src/entities/${entityNameCapitalized}.entity';\nimport { TypeOrmModule } from '@nestjs/typeorm';`;
|
|
429
|
+
importsBlock.push(
|
|
430
|
+
`TypeOrmModule.forFeature([${entityNameCapitalized}])`
|
|
431
|
+
);
|
|
432
|
+
} else if (dbConfig.orm === "mongoose") {
|
|
433
|
+
extraImports = `import { MongooseModule } from '@nestjs/mongoose';
|
|
434
|
+
import { ${entityNameCapitalized}, ${entityNameCapitalized}Schema } from '${entityPath}/domain/entities/${entityNameLower}.schema';`;
|
|
435
|
+
importsBlock.push(
|
|
436
|
+
`MongooseModule.forFeature([{ name: ${entityNameCapitalized}.name, schema: ${entityNameCapitalized}Schema }])`
|
|
437
|
+
);
|
|
466
438
|
}
|
|
467
439
|
|
|
440
|
+
// Ajoute l'import du service
|
|
441
|
+
extraImports += `\nimport { ${entityNameCapitalized}Service } from '${entityPath}/infrastructure/services/${entityNameLower}.service';`;
|
|
442
|
+
|
|
443
|
+
// Always necessary providers
|
|
444
|
+
providersBlock.push(
|
|
445
|
+
`{
|
|
446
|
+
provide: 'I${entityNameCapitalized}Repository',
|
|
447
|
+
useClass: ${entityNameCapitalized}Repository,
|
|
448
|
+
}`,
|
|
449
|
+
`${entityNameCapitalized}Service`,
|
|
450
|
+
`${entityNameCapitalized}Repository`,
|
|
451
|
+
`Create${entityNameCapitalized}UseCase`,
|
|
452
|
+
`Update${entityNameCapitalized}UseCase`,
|
|
453
|
+
`GetById${entityNameCapitalized}UseCase`,
|
|
454
|
+
`GetAll${entityNameCapitalized}UseCase`,
|
|
455
|
+
`Delete${entityNameCapitalized}UseCase`,
|
|
456
|
+
`${entityNameCapitalized}Mapper`
|
|
457
|
+
);
|
|
458
|
+
|
|
468
459
|
await createFile({
|
|
469
460
|
path: `${entityPath}/${entityNameLower}.module.ts`,
|
|
470
461
|
contente: `
|
|
@@ -472,12 +463,13 @@ export class ${entityNameCapitalized}Controller {
|
|
|
472
463
|
* ${entityNameCapitalized}Module est le module principal qui gère l'entité ${entityNameCapitalized}.
|
|
473
464
|
* Il regroupe tous les composants nécessaires pour traiter cette entité :
|
|
474
465
|
* - Contrôleur
|
|
475
|
-
* -
|
|
466
|
+
* - Repository
|
|
476
467
|
* - Use Cases
|
|
477
468
|
* - Mapper
|
|
469
|
+
* - Service
|
|
478
470
|
*/
|
|
479
471
|
import { Module } from '@nestjs/common';
|
|
480
|
-
|
|
472
|
+
${extraImports}
|
|
481
473
|
import { ${entityNameCapitalized}Controller } from '${entityPath}/presentation/controllers/${entityNameLower}.controller';
|
|
482
474
|
import { ${entityNameCapitalized}Repository } from '${entityPath}/infrastructure/repositories/${entityNameLower}.repository';
|
|
483
475
|
import { Create${entityNameCapitalized}UseCase } from '${entityPath}/application/use-cases/create-${entityNameLower}.use-case';
|
|
@@ -486,51 +478,21 @@ import { GetById${entityNameCapitalized}UseCase } from '${entityPath}/applicatio
|
|
|
486
478
|
import { GetAll${entityNameCapitalized}UseCase } from '${entityPath}/application/use-cases/getAll-${entityNameLower}.use-case';
|
|
487
479
|
import { Delete${entityNameCapitalized}UseCase } from '${entityPath}/application/use-cases/delete-${entityNameLower}.use-case';
|
|
488
480
|
import { ${entityNameCapitalized}Mapper } from '${entityPath}/domain/mappers/${entityNameLower}.mapper';
|
|
489
|
-
${Import}
|
|
490
481
|
|
|
491
482
|
@Module({
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
*/
|
|
499
|
-
controllers: [${entityNameCapitalized}Controller],
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Liste des providers nécessaires à la gestion de ${entityNameCapitalized}.
|
|
503
|
-
* Cela inclut :
|
|
504
|
-
* - Repository : Fournisseur pour accéder aux données de ${entityNameCapitalized}.
|
|
505
|
-
* - Use Cases : Logique métier pour la gestion de ${entityNameCapitalized}.
|
|
506
|
-
* - Mapper : Permet la transformation entre les DTOs et les entités.
|
|
507
|
-
*/
|
|
483
|
+
imports: [
|
|
484
|
+
${importsBlock.join(",\n ")}
|
|
485
|
+
],
|
|
486
|
+
controllers: [
|
|
487
|
+
${entityNameCapitalized}Controller
|
|
488
|
+
],
|
|
508
489
|
providers: [
|
|
509
|
-
${
|
|
510
|
-
|
|
511
|
-
// Repository : Permet d'interagir avec la base de données
|
|
512
|
-
{
|
|
513
|
-
provide: 'I${entityNameCapitalized}Repository', // Interface du repository
|
|
514
|
-
useClass: ${entityNameCapitalized}Repository, // Classe qui implémente l'interface
|
|
515
|
-
},
|
|
516
|
-
${entityNameCapitalized}Repository, // Fournisseur pour l'accès aux données
|
|
517
|
-
|
|
518
|
-
// Use Cases : Logique métier pour la gestion de ${entityNameCapitalized}
|
|
519
|
-
Create${entityNameCapitalized}UseCase, // Use Case pour créer un ${entityNameLower}
|
|
520
|
-
Update${entityNameCapitalized}UseCase, // Use Case pour mettre à jour un ${entityNameLower}
|
|
521
|
-
GetById${entityNameCapitalized}UseCase, // Use Case pour récupérer un ${entityNameLower} par son ID
|
|
522
|
-
GetAll${entityNameCapitalized}UseCase, // Use Case pour récupérer tous les ${entityNameLower}s
|
|
523
|
-
Delete${entityNameCapitalized}UseCase, // Use Case pour supprimer un ${entityNameLower}
|
|
524
|
-
|
|
525
|
-
// Mapper : Convertit entre les entités et les DTOs
|
|
526
|
-
${entityNameCapitalized}Mapper, // Mapper pour la transformation des données
|
|
490
|
+
${providersBlock.join(",\n ")}
|
|
527
491
|
],
|
|
492
|
+
exports: [
|
|
493
|
+
${entityNameCapitalized}Service
|
|
494
|
+
]
|
|
528
495
|
})
|
|
529
|
-
/**
|
|
530
|
-
* Le module ${entityNameCapitalized} est une unité logique regroupant toutes les dépendances nécessaires
|
|
531
|
-
* pour le bon fonctionnement de l'entité ${entityNameCapitalized}.
|
|
532
|
-
* Il gère l'injection des services, les actions métier, ainsi que la transformation des données.
|
|
533
|
-
*/
|
|
534
496
|
export class ${entityNameCapitalized}Module {}
|
|
535
497
|
`.trim(),
|
|
536
498
|
});
|
|
@@ -562,7 +524,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';`,
|
|
|
562
524
|
},`,
|
|
563
525
|
});
|
|
564
526
|
|
|
565
|
-
logSuccess(
|
|
527
|
+
logSuccess(`structure generé avec succes !`);
|
|
566
528
|
} catch (error) {
|
|
567
529
|
logError(`process currency have error: ${error}`);
|
|
568
530
|
}
|
|
@@ -39,7 +39,7 @@ DB_DATABASE=${dbConfig.POSTGRES_DB}
|
|
|
39
39
|
TypeOrmModule.forRoot({
|
|
40
40
|
type: 'postgres',
|
|
41
41
|
host: process.env.DB_HOST,
|
|
42
|
-
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT, 10) :
|
|
42
|
+
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT, 10) : 5432,
|
|
43
43
|
username: process.env.DB_USERNAME,
|
|
44
44
|
password: process.env.DB_PASSWORD,
|
|
45
45
|
database: process.env.DB_DATABASE,
|