nestcraftx 0.1.7 → 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/unutils.txt +397 -216
- package/utils/configs/configureDocker.js +1 -1
- package/utils/configs/setupCleanArchitecture.js +166 -118
- package/utils/setups/orms/typeOrmSetup.js +1 -1
- package/utils/setups/setupAuth.js +36 -25
- package/utils/setups/setupDatabase.js +2 -2
- package/utils/setups/setupMongoose.js +45 -0
- package/utils/setups/setupPrisma.js +5 -1
- package/utils/userInput.js +101 -225
- package/utils/utils.js +40 -149
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
generateMiddlewares,
|
|
15
15
|
generateRepository,
|
|
16
16
|
generateController,
|
|
17
|
+
generateMongooseSchemaFileContent,
|
|
17
18
|
} = require("../utils");
|
|
18
19
|
|
|
19
20
|
async function setupCleanArchitecture(inputs) {
|
|
@@ -83,6 +84,16 @@ export class AppModule {}`,
|
|
|
83
84
|
await createDirectory(`${entityPath}/${folder}`);
|
|
84
85
|
}
|
|
85
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
|
+
|
|
86
97
|
// 📌 1. Entité
|
|
87
98
|
const entityContent = await generateEntityFileContent(entity);
|
|
88
99
|
await createFile({
|
|
@@ -107,136 +118,168 @@ export interface I${entityNameCapitalized}Repository {
|
|
|
107
118
|
|
|
108
119
|
// 📌 3. Repository Implémentation
|
|
109
120
|
await generateRepository(entity.name, dbConfig.orm);
|
|
110
|
-
/* await createFile({
|
|
111
|
-
path: `${entityPath}/infrastructure/repositories/${entityNameLower}.repository.ts`,
|
|
112
|
-
contente: repositoryContent,
|
|
113
|
-
}); */
|
|
114
121
|
|
|
115
122
|
// 📌 4. Use Cases
|
|
116
123
|
const useCases = ["Create", "GetById", "GetAll", "Update", "Delete"];
|
|
117
124
|
useCases.forEach(async (useCase) => {
|
|
118
125
|
let content = "";
|
|
126
|
+
const entityName = capitalize(entity.name);
|
|
127
|
+
const entityNameLower = decapitalize(entity.name);
|
|
119
128
|
|
|
120
129
|
switch (useCase) {
|
|
121
130
|
case "Create":
|
|
122
131
|
content = `/**
|
|
123
|
-
* Use Case pour créer un ${
|
|
132
|
+
* Use Case pour créer un ${entityName}.
|
|
124
133
|
*/
|
|
125
|
-
import { Inject } from '@nestjs/common';
|
|
126
|
-
import { Create${
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
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
|
+
|
|
134
142
|
constructor(
|
|
135
|
-
@Inject("I${
|
|
136
|
-
private readonly ${
|
|
137
|
-
entity.name
|
|
138
|
-
)}Repository,
|
|
143
|
+
@Inject("I${entityName}Repository")
|
|
144
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
139
145
|
) {}
|
|
140
146
|
|
|
141
|
-
execute(data: Create${
|
|
142
|
-
|
|
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
|
+
}
|
|
143
157
|
}
|
|
144
|
-
}
|
|
158
|
+
}
|
|
159
|
+
`;
|
|
145
160
|
break;
|
|
146
161
|
|
|
147
162
|
case "GetById":
|
|
148
163
|
content = `/**
|
|
149
|
-
* Use Case pour récupérer un ${
|
|
164
|
+
* Use Case pour récupérer un ${entityName} par son ID.
|
|
150
165
|
*/
|
|
151
|
-
import { Inject } from '@nestjs/common';
|
|
152
|
-
import { I${
|
|
153
|
-
|
|
154
|
-
|
|
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);
|
|
155
172
|
|
|
156
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
157
173
|
constructor(
|
|
158
|
-
@Inject("I${
|
|
159
|
-
private readonly ${
|
|
160
|
-
entity.name
|
|
161
|
-
)}Repository,
|
|
174
|
+
@Inject("I${entityName}Repository")
|
|
175
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
162
176
|
) {}
|
|
163
177
|
|
|
164
|
-
execute(id: string) {
|
|
165
|
-
|
|
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
|
+
}
|
|
166
188
|
}
|
|
167
|
-
}
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
168
191
|
break;
|
|
169
192
|
|
|
170
193
|
case "GetAll":
|
|
171
194
|
content = `/**
|
|
172
|
-
* Use Case pour récupérer tous les ${
|
|
195
|
+
* Use Case pour récupérer tous les ${entityName}s.
|
|
173
196
|
*/
|
|
174
|
-
import { Inject } from '@nestjs/common';
|
|
175
|
-
import { I${
|
|
176
|
-
|
|
177
|
-
|
|
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);
|
|
178
203
|
|
|
179
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
180
204
|
constructor(
|
|
181
|
-
@Inject("I${
|
|
182
|
-
private readonly ${
|
|
183
|
-
entity.name
|
|
184
|
-
)}Repository,
|
|
205
|
+
@Inject("I${entityName}Repository")
|
|
206
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
185
207
|
) {}
|
|
186
208
|
|
|
187
|
-
execute() {
|
|
188
|
-
|
|
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
|
+
}
|
|
189
219
|
}
|
|
190
|
-
}
|
|
220
|
+
}
|
|
221
|
+
`;
|
|
191
222
|
break;
|
|
192
223
|
|
|
193
224
|
case "Update":
|
|
194
225
|
content = `/**
|
|
195
|
-
* Use Case pour mettre à jour un ${
|
|
226
|
+
* Use Case pour mettre à jour un ${entityName} existant.
|
|
196
227
|
*/
|
|
197
|
-
import { Inject } from '@nestjs/common';
|
|
198
|
-
import { Update${
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
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
|
+
|
|
206
236
|
constructor(
|
|
207
|
-
@Inject("I${
|
|
208
|
-
private readonly ${
|
|
209
|
-
entity.name
|
|
210
|
-
)}Repository,
|
|
237
|
+
@Inject("I${entityName}Repository")
|
|
238
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
211
239
|
) {}
|
|
212
240
|
|
|
213
|
-
execute(id: string, data: Update${
|
|
214
|
-
|
|
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
|
+
}
|
|
215
251
|
}
|
|
216
|
-
}
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
217
254
|
break;
|
|
218
255
|
|
|
219
256
|
case "Delete":
|
|
220
257
|
content = `/**
|
|
221
|
-
* Use Case pour supprimer un ${
|
|
258
|
+
* Use Case pour supprimer un ${entityName}.
|
|
222
259
|
*/
|
|
223
|
-
import { Inject } from '@nestjs/common';
|
|
224
|
-
import { I${
|
|
225
|
-
|
|
226
|
-
|
|
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);
|
|
227
265
|
|
|
228
|
-
export class ${useCase}${capitalize(entity.name)}UseCase {
|
|
229
266
|
constructor(
|
|
230
|
-
@Inject("I${
|
|
231
|
-
private readonly ${
|
|
232
|
-
entity.name
|
|
233
|
-
)}Repository,
|
|
267
|
+
@Inject("I${entityName}Repository")
|
|
268
|
+
private readonly ${entityNameLower}Repository: I${entityName}Repository,
|
|
234
269
|
) {}
|
|
235
270
|
|
|
236
|
-
execute(id: string) {
|
|
237
|
-
|
|
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
|
+
}
|
|
238
280
|
}
|
|
239
|
-
}
|
|
281
|
+
}
|
|
282
|
+
`;
|
|
240
283
|
break;
|
|
241
284
|
}
|
|
242
285
|
|
|
@@ -285,7 +328,7 @@ export enum Role {
|
|
|
285
328
|
// 📌 7. Mapper
|
|
286
329
|
const mapperFileContent = await generateMapper(entity);
|
|
287
330
|
await createFile({
|
|
288
|
-
path: `${entityPath}/domain/mappers/${
|
|
331
|
+
path: `${entityPath}/domain/mappers/${entityNameLower}.mapper.ts`,
|
|
289
332
|
contente: mapperFileContent,
|
|
290
333
|
});
|
|
291
334
|
|
|
@@ -293,53 +336,42 @@ export enum Role {
|
|
|
293
336
|
await createFile({
|
|
294
337
|
path: `${entityPath}/infrastructure/services/${entityNameLower}.service.ts`,
|
|
295
338
|
contente: `
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
import {
|
|
300
|
-
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';
|
|
301
347
|
|
|
348
|
+
@Injectable()
|
|
302
349
|
export class ${entityNameCapitalized}Service {
|
|
303
350
|
constructor(
|
|
304
|
-
|
|
305
|
-
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,
|
|
306
356
|
) {}
|
|
307
357
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (!data || !data.id) {
|
|
311
|
-
throw new Error('Données invalides, ID requis');
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const entityFromDb = await this.repository.findById(data.id);
|
|
315
|
-
|
|
316
|
-
if (!entityFromDb) {
|
|
317
|
-
throw new Error('Entité non trouvée avec cet ID');
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const processedData = {
|
|
321
|
-
...entityFromDb,
|
|
322
|
-
updatedAt: new Date(),
|
|
323
|
-
processedBy: 'System',
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
return processedData;
|
|
358
|
+
async create(dto: Create${entityNameCapitalized}Dto): Promise<${entityNameCapitalized}Entity> {
|
|
359
|
+
return await this.createUseCase.execute(dto);
|
|
327
360
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
async create(data: any) {
|
|
331
|
-
// 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);
|
|
332
363
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
// Logique pour mettre à jour une entité existante
|
|
364
|
+
async getById(id: string): Promise<${entityNameCapitalized}Entity | null> {
|
|
365
|
+
return await this.getByIdUseCase.execute(id);
|
|
336
366
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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);
|
|
340
372
|
}
|
|
341
373
|
}
|
|
342
|
-
|
|
374
|
+
`.trim(),
|
|
343
375
|
});
|
|
344
376
|
|
|
345
377
|
// 📌 9. Adapter
|
|
@@ -397,14 +429,24 @@ export class ${entityNameCapitalized}Adapter {
|
|
|
397
429
|
importsBlock.push(
|
|
398
430
|
`TypeOrmModule.forFeature([${entityNameCapitalized}])`
|
|
399
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
|
+
);
|
|
400
438
|
}
|
|
401
439
|
|
|
440
|
+
// Ajoute l'import du service
|
|
441
|
+
extraImports += `\nimport { ${entityNameCapitalized}Service } from '${entityPath}/infrastructure/services/${entityNameLower}.service';`;
|
|
442
|
+
|
|
402
443
|
// Always necessary providers
|
|
403
444
|
providersBlock.push(
|
|
404
445
|
`{
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
446
|
+
provide: 'I${entityNameCapitalized}Repository',
|
|
447
|
+
useClass: ${entityNameCapitalized}Repository,
|
|
448
|
+
}`,
|
|
449
|
+
`${entityNameCapitalized}Service`,
|
|
408
450
|
`${entityNameCapitalized}Repository`,
|
|
409
451
|
`Create${entityNameCapitalized}UseCase`,
|
|
410
452
|
`Update${entityNameCapitalized}UseCase`,
|
|
@@ -424,6 +466,7 @@ export class ${entityNameCapitalized}Adapter {
|
|
|
424
466
|
* - Repository
|
|
425
467
|
* - Use Cases
|
|
426
468
|
* - Mapper
|
|
469
|
+
* - Service
|
|
427
470
|
*/
|
|
428
471
|
import { Module } from '@nestjs/common';
|
|
429
472
|
${extraImports}
|
|
@@ -446,6 +489,9 @@ import { ${entityNameCapitalized}Mapper } from '${entityPath}/domain/mappers/${e
|
|
|
446
489
|
providers: [
|
|
447
490
|
${providersBlock.join(",\n ")}
|
|
448
491
|
],
|
|
492
|
+
exports: [
|
|
493
|
+
${entityNameCapitalized}Service
|
|
494
|
+
]
|
|
449
495
|
})
|
|
450
496
|
export class ${entityNameCapitalized}Module {}
|
|
451
497
|
`.trim(),
|
|
@@ -477,6 +523,8 @@ import { APP_INTERCEPTOR } from '@nestjs/core';`,
|
|
|
477
523
|
useClass: ResponseInterceptor,
|
|
478
524
|
},`,
|
|
479
525
|
});
|
|
526
|
+
|
|
527
|
+
logSuccess(`structure generé avec succes !`);
|
|
480
528
|
} catch (error) {
|
|
481
529
|
logError(`process currency have error: ${error}`);
|
|
482
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,
|
|
@@ -34,53 +34,64 @@ async function setupAuth(inputs) {
|
|
|
34
34
|
await createDirectory(path);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
import { User } from 'src/entities/
|
|
49
|
-
|
|
37
|
+
let ormImports = "";
|
|
38
|
+
let ormModuleImport = "";
|
|
39
|
+
let prismaProvider = ""; // Pour n'ajouter PrismaService que si besoin
|
|
40
|
+
|
|
41
|
+
if (dbConfig.orm === "typeorm") {
|
|
42
|
+
ormImports = `import { TypeOrmModule } from '@nestjs/typeorm';
|
|
43
|
+
import { User } from 'src/entities/User.entity';`;
|
|
44
|
+
ormModuleImport = `TypeOrmModule.forFeature([User]),`;
|
|
45
|
+
prismaProvider = "PrismaService,";
|
|
46
|
+
} else if (dbConfig.orm === "mongoose") {
|
|
47
|
+
ormImports = `import { MongooseModule } from '@nestjs/mongoose';
|
|
48
|
+
import { User, UserSchema } from 'src/user/domain/entities/user.schema';`;
|
|
49
|
+
ormModuleImport = `MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),`;
|
|
50
|
+
prismaProvider = ""; // Ne pas ajouter PrismaService
|
|
51
|
+
} else if (dbConfig.orm === "prisma") {
|
|
52
|
+
ormImports = "";
|
|
53
|
+
ormModuleImport = "";
|
|
54
|
+
prismaProvider = "PrismaService,";
|
|
55
|
+
}
|
|
50
56
|
|
|
51
57
|
await createFile({
|
|
52
58
|
path: `${authPath}/auth.module.ts`,
|
|
53
|
-
contente: `
|
|
59
|
+
contente: `
|
|
60
|
+
import { Module } from '@nestjs/common';
|
|
54
61
|
import { JwtModule } from '@nestjs/jwt';
|
|
55
62
|
import { PassportModule } from '@nestjs/passport';
|
|
56
63
|
import { UserMapper } from 'src/user/domain/mappers/user.mapper';
|
|
57
|
-
${
|
|
64
|
+
${ormImports}
|
|
58
65
|
import { AuthService } from '${authPaths.authServicesPath}/auth.service';
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
${
|
|
67
|
+
dbConfig.orm === "prisma"
|
|
68
|
+
? "import { PrismaService } from 'src/prisma/prisma.service';"
|
|
69
|
+
: ""
|
|
70
|
+
}
|
|
71
|
+
import { AuthController } from '${
|
|
72
|
+
authPaths.authControllersPath
|
|
73
|
+
}/auth.controller';
|
|
61
74
|
import { JwtStrategy } from '${authPaths.authStrategyPath}/jwt.strategy';
|
|
62
75
|
import { AuthGuard } from '${authPaths.authGuardsPath}/auth.guard';
|
|
63
76
|
import { UserRepository } from 'src/user/infrastructure/repositories/user.repository';
|
|
64
77
|
|
|
65
78
|
@Module({
|
|
66
79
|
imports: [
|
|
67
|
-
${
|
|
80
|
+
${ormModuleImport}
|
|
81
|
+
PassportModule,
|
|
82
|
+
JwtModule.register({ secret: 'your-secret-key', signOptions: { expiresIn: '1h' } }),
|
|
68
83
|
],
|
|
69
84
|
controllers: [AuthController],
|
|
70
85
|
providers: [
|
|
71
|
-
|
|
72
|
-
UserMapper,
|
|
73
|
-
{
|
|
74
|
-
provide: 'IUserRepository',
|
|
75
|
-
useClass: UserRepository,
|
|
76
|
-
},
|
|
86
|
+
${prismaProvider}
|
|
77
87
|
AuthService,
|
|
78
88
|
JwtStrategy,
|
|
79
89
|
AuthGuard
|
|
80
90
|
],
|
|
81
91
|
exports: [AuthService],
|
|
82
92
|
})
|
|
83
|
-
export class AuthModule {}
|
|
93
|
+
export class AuthModule {}
|
|
94
|
+
`.trim(),
|
|
84
95
|
});
|
|
85
96
|
|
|
86
97
|
// 📌 Auth Service
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { logInfo } = require("../loggers/logInfo");
|
|
2
2
|
const { runCommand } = require("../shell");
|
|
3
3
|
const { setupTypeORM } = require("./orms/typeOrmSetup");
|
|
4
|
+
const { setupMongoose } = require("./setupMongoose");
|
|
4
5
|
const { setupPrisma } = require("./setupPrisma");
|
|
5
6
|
|
|
6
7
|
async function setupDatabase(inputs) {
|
|
@@ -36,8 +37,7 @@ async function setupDatabase(inputs) {
|
|
|
36
37
|
}
|
|
37
38
|
async function setupMongoDB(inputs) {
|
|
38
39
|
logInfo("Configuration de MongoDB...");
|
|
39
|
-
|
|
40
|
-
// await setupMongoDBConfig(inputs);
|
|
40
|
+
await setupMongoose(inputs);
|
|
41
41
|
}
|
|
42
42
|
async function setupSQLite(inputs) {
|
|
43
43
|
logInfo("Configuration de SQLite...");
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { createFile, updateFile } = require("../userInput");
|
|
4
|
+
const { logSuccess } = require("../loggers/logSuccess");
|
|
5
|
+
const { logInfo } = require("../loggers/logInfo");
|
|
6
|
+
|
|
7
|
+
async function setupMongoose(inputs) {
|
|
8
|
+
logInfo("📦 Installation de Mongoose et @nestjs/mongoose...");
|
|
9
|
+
execSync("npm install @nestjs/mongoose mongoose", { stdio: "inherit" });
|
|
10
|
+
|
|
11
|
+
// Génération du fichier .env
|
|
12
|
+
const envContent = `
|
|
13
|
+
MONGO_URI=${inputs.dbConfig.MONGO_URI}
|
|
14
|
+
MONGO_DB=${inputs.dbConfig.MONGO_DB}
|
|
15
|
+
`.trim();
|
|
16
|
+
await createFile({ path: ".env", contente: envContent });
|
|
17
|
+
|
|
18
|
+
// Ajout de l'import et de la configuration Mongoose dans app.module.ts
|
|
19
|
+
const appModulePath = path.join("src", "app.module.ts");
|
|
20
|
+
const mongooseImport = `import { MongooseModule } from '@nestjs/mongoose';`;
|
|
21
|
+
|
|
22
|
+
// Ajoute l'import si absent
|
|
23
|
+
await updateFile({
|
|
24
|
+
path: appModulePath,
|
|
25
|
+
pattern: /import {[\s\S]*?} from '@nestjs\/config';/,
|
|
26
|
+
replacement: (match) => `${match}\n${mongooseImport}`,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Ajoute la configuration MongooseModule dans les imports
|
|
30
|
+
const importsPattern =
|
|
31
|
+
/imports:\s*\[[\s\S]*?ConfigModule\.forRoot\([\s\S]*?\),/;
|
|
32
|
+
await updateFile({
|
|
33
|
+
path: appModulePath,
|
|
34
|
+
pattern: importsPattern,
|
|
35
|
+
replacement: (match) =>
|
|
36
|
+
`${match}
|
|
37
|
+
MongooseModule.forRoot(process.env.MONGO_URI, {
|
|
38
|
+
dbName: process.env.MONGO_DB,
|
|
39
|
+
}),`,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
logSuccess("Mongoose configuré et injecté dans app.module.ts !");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = { setupMongoose };
|
|
@@ -210,8 +210,12 @@ function mapTypeToPrisma(type) {
|
|
|
210
210
|
switch (type.toLowerCase()) {
|
|
211
211
|
case "string":
|
|
212
212
|
return "String";
|
|
213
|
+
case "int":
|
|
214
|
+
return "Int";
|
|
215
|
+
case "float":
|
|
216
|
+
return "Float";
|
|
213
217
|
case "number":
|
|
214
|
-
return "Float"; //
|
|
218
|
+
return "Float"; // ou "Int" selon le besoin
|
|
215
219
|
case "boolean":
|
|
216
220
|
return "Boolean";
|
|
217
221
|
case "date":
|