@mikemajesty/microservice-crud 6.1.3 → 6.1.5
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/src/cli.js +52 -66
- package/src/scafold/core/.gitkeep +0 -0
- package/src/templates/{mongo/core → core}/entity/entity.js +1 -1
- package/src/templates/{mongo/core → core}/repository/repository.js +1 -1
- package/src/templates/{postgres/core → core}/use-cases/__tests__/create.spec.js +1 -1
- package/src/templates/{postgres/core → core}/use-cases/__tests__/delete.spec.js +1 -1
- package/src/templates/{postgres/core → core}/use-cases/__tests__/get-by-id.spec.js +1 -1
- package/src/templates/{postgres/core → core}/use-cases/__tests__/list.spec.js +1 -1
- package/src/templates/{postgres/core → core}/use-cases/__tests__/update.spec.js +1 -1
- package/src/templates/{postgres/core → core}/use-cases/create.js +4 -4
- package/src/templates/{postgres/core → core}/use-cases/delete.js +4 -4
- package/src/templates/{postgres/core → core}/use-cases/get-by-id.js +4 -4
- package/src/templates/{postgres/core → core}/use-cases/list.js +4 -4
- package/src/templates/{postgres/core → core}/use-cases/update.js +4 -4
- package/src/templates/mongo/modules/repository.js +2 -1
- package/src/templates/postgres/modules/repository.js +2 -2
- package/src/templates/mongo/core/use-cases/__tests__/create.spec.js +0 -70
- package/src/templates/mongo/core/use-cases/__tests__/delete.spec.js +0 -77
- package/src/templates/mongo/core/use-cases/__tests__/get-by-id.spec.js +0 -74
- package/src/templates/mongo/core/use-cases/__tests__/list.spec.js +0 -87
- package/src/templates/mongo/core/use-cases/__tests__/update.spec.js +0 -76
- package/src/templates/mongo/core/use-cases/create.js +0 -41
- package/src/templates/mongo/core/use-cases/delete.js +0 -43
- package/src/templates/mongo/core/use-cases/get-by-id.js +0 -38
- package/src/templates/mongo/core/use-cases/list.js +0 -39
- package/src/templates/mongo/core/use-cases/update.js +0 -51
- package/src/templates/postgres/core/entity/entity.js +0 -35
- package/src/templates/postgres/core/repository/repository.js +0 -15
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -17,18 +17,18 @@ const path = require('path');
|
|
|
17
17
|
const cliSelect = require('cli-select');
|
|
18
18
|
const prompt = require('prompt-sync')();
|
|
19
19
|
|
|
20
|
-
const { getCoreUsecaseCreateTest } = require('./templates/
|
|
21
|
-
const { getCoreUsecaseUpdateTest } = require('./templates/
|
|
22
|
-
const { getCoreUsecaseDeleteTest } = require('./templates/
|
|
23
|
-
const { getCoreUsecaseListTest } = require('./templates/
|
|
24
|
-
const { getCoreUsecaseGetByIdTest } = require('./templates/
|
|
25
|
-
const { getCoreUsecaseGetById } = require('./templates/
|
|
26
|
-
const { getCoreUsecaseList } = require('./templates/
|
|
27
|
-
const { getCoreEntity } = require('./templates/
|
|
28
|
-
const { getCoreRepository } = require('./templates/
|
|
29
|
-
const { getCoreUsecaseCreate } = require('./templates/
|
|
30
|
-
const { getCoreUsecaseDelete } = require('./templates/
|
|
31
|
-
const { getCoreUsecaseUpdate } = require('./templates/
|
|
20
|
+
const { getCoreUsecaseCreateTest } = require('./templates/core/use-cases/__tests__/create.spec');
|
|
21
|
+
const { getCoreUsecaseUpdateTest } = require('./templates/core/use-cases/__tests__/update.spec');
|
|
22
|
+
const { getCoreUsecaseDeleteTest } = require('./templates/core/use-cases/__tests__/delete.spec');
|
|
23
|
+
const { getCoreUsecaseListTest } = require('./templates/core/use-cases/__tests__/list.spec');
|
|
24
|
+
const { getCoreUsecaseGetByIdTest } = require('./templates/core/use-cases/__tests__/get-by-id.spec');
|
|
25
|
+
const { getCoreUsecaseGetById } = require('./templates/core/use-cases/get-by-id');
|
|
26
|
+
const { getCoreUsecaseList } = require('./templates/core/use-cases/list');
|
|
27
|
+
const { getCoreEntity } = require('./templates/core/entity/entity');
|
|
28
|
+
const { getCoreRepository } = require('./templates/core/repository/repository');
|
|
29
|
+
const { getCoreUsecaseCreate } = require('./templates/core/use-cases/create');
|
|
30
|
+
const { getCoreUsecaseDelete } = require('./templates/core/use-cases/delete');
|
|
31
|
+
const { getCoreUsecaseUpdate } = require('./templates/core/use-cases/update');
|
|
32
32
|
|
|
33
33
|
const { getModuleAdapter } = require('./templates/postgres/modules/adapter');
|
|
34
34
|
const { getModuleController } = require('./templates/postgres/modules/controller');
|
|
@@ -37,19 +37,6 @@ const { getModuleRepository } = require('./templates/postgres/modules/repository
|
|
|
37
37
|
const { getModuleSchema } = require('./templates/postgres/schemas/schema');
|
|
38
38
|
const { getModuleSwagger } = require('./templates/postgres/modules/swagger');
|
|
39
39
|
|
|
40
|
-
const { getCoreUsecaseCreateTest: getCoreUsecaseCreateMongoTest } = require('./templates/mongo/core/use-cases/__tests__/create.spec');
|
|
41
|
-
const { getCoreUsecaseUpdateTest: getCoreUsecaseUpdateMongoTest } = require('./templates/mongo/core/use-cases/__tests__/update.spec');
|
|
42
|
-
const { getCoreUsecaseDeleteTest: getCoreUsecaseDeleteMongoTest } = require('./templates/mongo/core/use-cases/__tests__/delete.spec');
|
|
43
|
-
const { getCoreUsecaseListTest: getCoreUsecaseListMongoTest } = require('./templates/mongo/core/use-cases/__tests__/list.spec');
|
|
44
|
-
const { getCoreUsecaseGetByIdTest: getCoreUsecaseGetByIdMongoTest } = require('./templates/mongo/core/use-cases/__tests__/get-by-id.spec');
|
|
45
|
-
const { getCoreUsecaseGetById: getCoreUsecaseGetByIdMongo } = require('./templates/mongo/core/use-cases/get-by-id');
|
|
46
|
-
const { getCoreUsecaseList: getCoreUsecaseListMongo } = require('./templates/mongo/core/use-cases/list');
|
|
47
|
-
const { getCoreEntity: getCoreEntityMongo } = require('./templates/mongo/core/entity/entity');
|
|
48
|
-
const { getCoreRepository: getCoreRepositoryMongo } = require('./templates/mongo/core/repository/repository');
|
|
49
|
-
const { getCoreUsecaseCreate: getCoreUsecaseCreateMongo } = require('./templates/mongo/core/use-cases/create');
|
|
50
|
-
const { getCoreUsecaseDelete: getCoreUsecaseDeleteMongo } = require('./templates/mongo/core/use-cases/delete');
|
|
51
|
-
const { getCoreUsecaseUpdate: getCoreUsecaseUpdateMongo } = require('./templates/mongo/core/use-cases/update');
|
|
52
|
-
|
|
53
40
|
const { getModuleAdapter: getModuleAdapterMongo } = require('./templates/mongo/modules/adapter');
|
|
54
41
|
const { getModuleController: getModuleControllerMongo } = require('./templates/mongo/modules/controller');
|
|
55
42
|
const { getModule: getModuleMongo } = require('./templates/mongo/modules/module');
|
|
@@ -139,23 +126,18 @@ const createLib = async (name) => {
|
|
|
139
126
|
}
|
|
140
127
|
}
|
|
141
128
|
|
|
142
|
-
const
|
|
129
|
+
const createCore = async (name) => {
|
|
143
130
|
name = getName(name);
|
|
144
131
|
|
|
145
|
-
const dirRoot = `${__dirname}/scafold/
|
|
132
|
+
const dirRoot = `${__dirname}/scafold/core/${name}`
|
|
146
133
|
|
|
147
134
|
try {
|
|
135
|
+
|
|
148
136
|
if (fs.existsSync(dirRoot)) {
|
|
149
137
|
fs.rmSync(dirRoot, { recursive: true });
|
|
150
138
|
}
|
|
151
139
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
fs.mkdirSync(`${dirRoot}/modules`)
|
|
155
|
-
|
|
156
|
-
fs.mkdirSync(`${dirRoot}/core`)
|
|
157
|
-
|
|
158
|
-
const dirCore = `${dirRoot}/core/${name}`;
|
|
140
|
+
const dirCore = dirRoot;
|
|
159
141
|
fs.mkdirSync(dirCore)
|
|
160
142
|
|
|
161
143
|
const entityPath = `${dirCore}/entity`;
|
|
@@ -183,6 +165,28 @@ const createPostgresCrud = async (name) => {
|
|
|
183
165
|
fs.writeFileSync(`${useCasesPathTest}/${name}-delete.spec.ts`, getCoreUsecaseDeleteTest(name))
|
|
184
166
|
fs.writeFileSync(`${useCasesPathTest}/${name}-list.spec.ts`, getCoreUsecaseListTest(name))
|
|
185
167
|
fs.writeFileSync(`${useCasesPathTest}/${name}-get-by-id.spec.ts`, getCoreUsecaseGetByIdTest(name))
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.log('error', error)
|
|
170
|
+
if (fs.existsSync(dirRoot)) {
|
|
171
|
+
fs.rmSync(dirRoot, { recursive: true });
|
|
172
|
+
}
|
|
173
|
+
return `${name}`
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const createPostgresCrud = async (name) => {
|
|
178
|
+
name = getName(name);
|
|
179
|
+
|
|
180
|
+
const dirRoot = `${__dirname}/scafold/postgres/${name}`
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
if (fs.existsSync(dirRoot)) {
|
|
184
|
+
fs.rmSync(dirRoot, { recursive: true });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fs.mkdirSync(dirRoot)
|
|
188
|
+
|
|
189
|
+
fs.mkdirSync(`${dirRoot}/modules`)
|
|
186
190
|
|
|
187
191
|
const schemasPath = `${__dirname}/scafold/postgres/schemas`;
|
|
188
192
|
if (fs.existsSync(schemasPath)) {
|
|
@@ -199,7 +203,10 @@ const createPostgresCrud = async (name) => {
|
|
|
199
203
|
fs.writeFileSync(`${modulesPath}/repository.ts`, getModuleRepository(name))
|
|
200
204
|
fs.writeFileSync(`${modulesPath}/swagger.ts`, getModuleSwagger(name))
|
|
201
205
|
|
|
206
|
+
await createCore(name)
|
|
207
|
+
|
|
202
208
|
return `${name}`
|
|
209
|
+
|
|
203
210
|
} catch (error) {
|
|
204
211
|
console.log('error', error)
|
|
205
212
|
if (fs.existsSync(dirRoot)) {
|
|
@@ -225,38 +232,6 @@ const createMongoCrud = async (name) => {
|
|
|
225
232
|
|
|
226
233
|
fs.mkdirSync(`${dirRoot}/modules`)
|
|
227
234
|
|
|
228
|
-
fs.mkdirSync(`${dirRoot}/core`)
|
|
229
|
-
|
|
230
|
-
const dirCore = `${dirRoot}/core/${name}`;
|
|
231
|
-
fs.mkdirSync(dirCore)
|
|
232
|
-
|
|
233
|
-
const entityPath = `${dirCore}/entity`;
|
|
234
|
-
const repositoryPath = `${dirCore}/repository`;
|
|
235
|
-
const useCasesPath = `${dirCore}/use-cases`;
|
|
236
|
-
|
|
237
|
-
fs.mkdirSync(entityPath)
|
|
238
|
-
fs.mkdirSync(repositoryPath)
|
|
239
|
-
fs.mkdirSync(useCasesPath)
|
|
240
|
-
|
|
241
|
-
fs.writeFileSync(`${entityPath}/${name}.ts`, getCoreEntityMongo(name))
|
|
242
|
-
fs.writeFileSync(`${repositoryPath}/${name}.ts`, getCoreRepositoryMongo(name))
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
fs.writeFileSync(`${useCasesPath}/${name}-create.ts`, getCoreUsecaseCreateMongo(name))
|
|
246
|
-
fs.writeFileSync(`${useCasesPath}/${name}-delete.ts`, getCoreUsecaseDeleteMongo(name))
|
|
247
|
-
fs.writeFileSync(`${useCasesPath}/${name}-get-by-id.ts`, getCoreUsecaseGetByIdMongo(name))
|
|
248
|
-
fs.writeFileSync(`${useCasesPath}/${name}-list.ts`, getCoreUsecaseListMongo(name))
|
|
249
|
-
fs.writeFileSync(`${useCasesPath}/${name}-update.ts`, getCoreUsecaseUpdateMongo(name))
|
|
250
|
-
|
|
251
|
-
const useCasesPathTest = `${useCasesPath}/__tests__`
|
|
252
|
-
fs.mkdirSync(useCasesPathTest)
|
|
253
|
-
|
|
254
|
-
fs.writeFileSync(`${useCasesPathTest}/${name}-create.spec.ts`, getCoreUsecaseCreateMongoTest(name))
|
|
255
|
-
fs.writeFileSync(`${useCasesPathTest}/${name}-update.spec.ts`, getCoreUsecaseUpdateMongoTest(name))
|
|
256
|
-
fs.writeFileSync(`${useCasesPathTest}/${name}-delete.spec.ts`, getCoreUsecaseDeleteMongoTest(name))
|
|
257
|
-
fs.writeFileSync(`${useCasesPathTest}/${name}-list.spec.ts`, getCoreUsecaseListMongoTest(name))
|
|
258
|
-
fs.writeFileSync(`${useCasesPathTest}/${name}-get-by-id.spec.ts`, getCoreUsecaseGetByIdMongoTest(name))
|
|
259
|
-
|
|
260
235
|
const schemasPath = `${__dirname}/scafold/mongo/schemas`;
|
|
261
236
|
|
|
262
237
|
if (fs.existsSync(schemasPath)) {
|
|
@@ -275,6 +250,8 @@ const createMongoCrud = async (name) => {
|
|
|
275
250
|
fs.writeFileSync(`${modulesPath}/repository.ts`, getModuleRepositoryMongo(name))
|
|
276
251
|
fs.writeFileSync(`${modulesPath}/swagger.ts`, getModuleSwaggerMongo(name))
|
|
277
252
|
|
|
253
|
+
await createCore(name)
|
|
254
|
+
|
|
278
255
|
return `${name}`
|
|
279
256
|
} catch (error) {
|
|
280
257
|
console.log('error', error)
|
|
@@ -436,6 +413,11 @@ export async function cli(args) {
|
|
|
436
413
|
|
|
437
414
|
const pathSchema = path.resolve(src, '../schemas');
|
|
438
415
|
|
|
416
|
+
const pathDest = `${dest}/src/core/${name}`;
|
|
417
|
+
const pathCore = path.resolve(src, '../../core');
|
|
418
|
+
|
|
419
|
+
fse.copySync(pathCore + `/${name}`, pathDest, { overwrite: true });
|
|
420
|
+
|
|
439
421
|
fse.copySync(pathSchema, destPathSchema, { overwrite: true });
|
|
440
422
|
|
|
441
423
|
if (fs.existsSync(source)) {
|
|
@@ -446,6 +428,10 @@ export async function cli(args) {
|
|
|
446
428
|
fs.rmSync(pathSchema + `/${name}.ts`, { recursive: true });
|
|
447
429
|
}
|
|
448
430
|
|
|
431
|
+
if (fs.existsSync(pathCore + `/${name}`)) {
|
|
432
|
+
fs.rmSync(pathCore + `/${name}`, { recursive: true });
|
|
433
|
+
}
|
|
434
|
+
|
|
449
435
|
}
|
|
450
436
|
}
|
|
451
437
|
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const pluralize = require('pluralize')
|
|
3
|
-
const { dashToPascal, snakeToCamel } = require('
|
|
3
|
+
const { dashToPascal, snakeToCamel } = require('../../../../textUtils')
|
|
4
4
|
|
|
5
5
|
const getCoreUsecaseListTest = (name) => `import { Test } from '@nestjs/testing';
|
|
6
6
|
import { ZodIssue } from 'zod';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("
|
|
1
|
+
const { dashToPascal, snakeToCamel } = require("../../../textUtils")
|
|
2
2
|
|
|
3
3
|
const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
|
|
4
4
|
|
|
@@ -15,9 +15,6 @@ export const ${dashToPascal(name)}CreateSchema = ${dashToPascal(name)}EntitySche
|
|
|
15
15
|
name: true
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
export type ${dashToPascal(name)}CreateInput = z.infer<typeof ${dashToPascal(name)}CreateSchema>;
|
|
19
|
-
export type ${dashToPascal(name)}CreateOutput = CreatedModel;
|
|
20
|
-
|
|
21
18
|
export class ${dashToPascal(name)}CreateUsecase implements IUsecase {
|
|
22
19
|
constructor(
|
|
23
20
|
private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository,
|
|
@@ -35,6 +32,9 @@ export class ${dashToPascal(name)}CreateUsecase implements IUsecase {
|
|
|
35
32
|
return ${snakeToCamel(name)};
|
|
36
33
|
}
|
|
37
34
|
}
|
|
35
|
+
|
|
36
|
+
export type ${dashToPascal(name)}CreateInput = z.infer<typeof ${dashToPascal(name)}CreateSchema>;
|
|
37
|
+
export type ${dashToPascal(name)}CreateOutput = CreatedModel;
|
|
38
38
|
`
|
|
39
39
|
|
|
40
40
|
module.exports = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("
|
|
1
|
+
const { dashToPascal, snakeToCamel } = require("../../../textUtils")
|
|
2
2
|
|
|
3
3
|
const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
|
|
4
4
|
|
|
@@ -13,9 +13,6 @@ export const ${dashToPascal(name)}DeleteSchema = ${dashToPascal(name)}EntitySche
|
|
|
13
13
|
id: true
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
export type ${dashToPascal(name)}DeleteInput = z.infer<typeof ${dashToPascal(name)}DeleteSchema>;
|
|
17
|
-
export type ${dashToPascal(name)}DeleteOutput = ${dashToPascal(name)}Entity;
|
|
18
|
-
|
|
19
16
|
export class ${dashToPascal(name)}DeleteUsecase implements IUsecase {
|
|
20
17
|
constructor(private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) {}
|
|
21
18
|
|
|
@@ -36,6 +33,9 @@ export class ${dashToPascal(name)}DeleteUsecase implements IUsecase {
|
|
|
36
33
|
return ${snakeToCamel(name)};
|
|
37
34
|
}
|
|
38
35
|
}
|
|
36
|
+
|
|
37
|
+
export type ${dashToPascal(name)}DeleteInput = z.infer<typeof ${dashToPascal(name)}DeleteSchema>;
|
|
38
|
+
export type ${dashToPascal(name)}DeleteOutput = ${dashToPascal(name)}Entity;
|
|
39
39
|
`
|
|
40
40
|
|
|
41
41
|
module.exports = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("
|
|
1
|
+
const { dashToPascal, snakeToCamel } = require("../../../textUtils")
|
|
2
2
|
|
|
3
3
|
const getCoreUsecaseGetById = (name) => `import { z } from 'zod';
|
|
4
4
|
|
|
@@ -14,9 +14,6 @@ export const ${dashToPascal(name)}GetByIdSchema = ${dashToPascal(name)}EntitySch
|
|
|
14
14
|
id: true
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
export type ${dashToPascal(name)}GetByIdInput = z.infer<typeof ${dashToPascal(name)}GetByIdSchema>;
|
|
18
|
-
export type ${dashToPascal(name)}GetByIdOutput = ${dashToPascal(name)}Entity;
|
|
19
|
-
|
|
20
17
|
export class ${dashToPascal(name)}GetByIdUsecase implements IUsecase {
|
|
21
18
|
constructor(private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) {}
|
|
22
19
|
|
|
@@ -31,6 +28,9 @@ export class ${dashToPascal(name)}GetByIdUsecase implements IUsecase {
|
|
|
31
28
|
return new ${dashToPascal(name)}Entity(${snakeToCamel(name)});
|
|
32
29
|
}
|
|
33
30
|
}
|
|
31
|
+
|
|
32
|
+
export type ${dashToPascal(name)}GetByIdInput = z.infer<typeof ${dashToPascal(name)}GetByIdSchema>;
|
|
33
|
+
export type ${dashToPascal(name)}GetByIdOutput = ${dashToPascal(name)}Entity;
|
|
34
34
|
`
|
|
35
35
|
|
|
36
36
|
module.exports = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("
|
|
1
|
+
const { dashToPascal, snakeToCamel } = require("../../../textUtils")
|
|
2
2
|
|
|
3
3
|
const getCoreUsecaseList = (name) => `import { z } from 'zod';
|
|
4
4
|
|
|
@@ -13,9 +13,6 @@ import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
|
13
13
|
|
|
14
14
|
export const ${dashToPascal(name)}ListSchema = z.intersection(PaginationSchema, SortSchema.merge(SearchSchema));
|
|
15
15
|
|
|
16
|
-
export type ${dashToPascal(name)}ListInput = PaginationInput<${dashToPascal(name)}Entity>;
|
|
17
|
-
export type ${dashToPascal(name)}ListOutput = PaginationOutput<${dashToPascal(name)}Entity>;
|
|
18
|
-
|
|
19
16
|
export class ${dashToPascal(name)}ListUsecase implements IUsecase {
|
|
20
17
|
constructor(private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) {}
|
|
21
18
|
|
|
@@ -24,6 +21,9 @@ export class ${dashToPascal(name)}ListUsecase implements IUsecase {
|
|
|
24
21
|
return await this.${snakeToCamel(name)}Repository.paginate(input);
|
|
25
22
|
}
|
|
26
23
|
}
|
|
24
|
+
|
|
25
|
+
export type ${dashToPascal(name)}ListInput = PaginationInput<${dashToPascal(name)}Entity>;
|
|
26
|
+
export type ${dashToPascal(name)}ListOutput = PaginationOutput<${dashToPascal(name)}Entity>;
|
|
27
27
|
`
|
|
28
28
|
|
|
29
29
|
module.exports = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("
|
|
1
|
+
const { dashToPascal, snakeToCamel } = require("../../../textUtils")
|
|
2
2
|
|
|
3
3
|
const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
|
|
4
4
|
|
|
@@ -14,9 +14,6 @@ export const ${dashToPascal(name)}UpdateSchema = ${dashToPascal(name)}EntitySche
|
|
|
14
14
|
id: true
|
|
15
15
|
}).merge(${dashToPascal(name)}EntitySchema.omit({ id: true }).partial());
|
|
16
16
|
|
|
17
|
-
export type ${dashToPascal(name)}UpdateInput = z.infer<typeof ${dashToPascal(name)}UpdateSchema>;
|
|
18
|
-
export type ${dashToPascal(name)}UpdateOutput = ${dashToPascal(name)}Entity;
|
|
19
|
-
|
|
20
17
|
export class ${dashToPascal(name)}UpdateUsecase implements IUsecase {
|
|
21
18
|
constructor(
|
|
22
19
|
private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository,
|
|
@@ -44,6 +41,9 @@ export class ${dashToPascal(name)}UpdateUsecase implements IUsecase {
|
|
|
44
41
|
return new ${dashToPascal(name)}Entity(updated as ${dashToPascal(name)}Entity);
|
|
45
42
|
}
|
|
46
43
|
}
|
|
44
|
+
|
|
45
|
+
export type ${dashToPascal(name)}UpdateInput = z.infer<typeof ${dashToPascal(name)}UpdateSchema>;
|
|
46
|
+
export type ${dashToPascal(name)}UpdateOutput = ${dashToPascal(name)}Entity;
|
|
47
47
|
`
|
|
48
48
|
|
|
49
49
|
module.exports = {
|
|
@@ -4,6 +4,7 @@ const { dashToPascal, snakeToCamel } = require('../../../textUtils')
|
|
|
4
4
|
const getModuleRepository = (name) => `import { Injectable } from '@nestjs/common';
|
|
5
5
|
import { InjectModel } from '@nestjs/mongoose';
|
|
6
6
|
import { FilterQuery, PaginateModel } from 'mongoose';
|
|
7
|
+
import { ${dashToPascal(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
7
8
|
|
|
8
9
|
import { I${dashToPascal(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
9
10
|
import { ${dashToPascal(name)}ListInput, ${dashToPascal(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
@@ -28,7 +29,7 @@ export class ${dashToPascal(name)}Repository extends MongoRepository<${dashToPas
|
|
|
28
29
|
sort: sort as object
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
return { docs: ${pluralize(snakeToCamel(name))}.docs.map((u) => u.toObject({ virtuals: true })), limit, page, total: ${snakeToCamel(name)}s.totalDocs };
|
|
32
|
+
return { docs: ${pluralize(snakeToCamel(name))}.docs.map((u) => new ${dashToPascal(name)}Entity(u.toObject({ virtuals: true }))), limit, page, total: ${snakeToCamel(name)}s.totalDocs };
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
`
|
|
@@ -12,8 +12,6 @@ import { ConvertTypeOrmFilter, SearchTypeEnum, ValidateDatabaseSortAllowed } fro
|
|
|
12
12
|
import { IEntity } from '@/utils/entity';
|
|
13
13
|
import { PaginationUtils } from '@/utils/pagination';
|
|
14
14
|
|
|
15
|
-
type Model = ${dashToPascal(name)}Schema & ${dashToPascal(name)}Entity;
|
|
16
|
-
|
|
17
15
|
@Injectable()
|
|
18
16
|
export class ${dashToPascal(name)}Repository extends TypeORMRepository<Model> implements I${dashToPascal(name)}Repository {
|
|
19
17
|
constructor(readonly repository: Repository<Model>) {
|
|
@@ -35,6 +33,8 @@ export class ${dashToPascal(name)}Repository extends TypeORMRepository<Model> im
|
|
|
35
33
|
return { docs, total, page: input.page, limit: input.limit };
|
|
36
34
|
}
|
|
37
35
|
}
|
|
36
|
+
|
|
37
|
+
type Model = ${dashToPascal(name)}Schema & ${dashToPascal(name)}Entity;
|
|
38
38
|
`
|
|
39
39
|
|
|
40
40
|
module.exports = {
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreUsecaseCreateTest = (name) => `import { Test } from '@nestjs/testing';
|
|
4
|
-
import { ZodIssue } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { ILoggerAdapter } from '@/infra/logger';
|
|
7
|
-
import { I${dashToPascal(name)}CreateAdapter } from '@/modules/${name}/adapter';
|
|
8
|
-
import { TestUtils } from '@/utils/tests';
|
|
9
|
-
|
|
10
|
-
import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
|
|
11
|
-
import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
|
|
12
|
-
import { ${dashToPascal(name)}CreateInput, ${dashToPascal(name)}CreateOutput, ${dashToPascal(name)}CreateUsecase } from '../${name}-create';
|
|
13
|
-
|
|
14
|
-
describe(${dashToPascal(name)}CreateUsecase.name, () => {
|
|
15
|
-
let usecase: I${dashToPascal(name)}CreateAdapter;
|
|
16
|
-
let repository: I${dashToPascal(name)}Repository;
|
|
17
|
-
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
const app = await Test.createTestingModule({
|
|
20
|
-
providers: [
|
|
21
|
-
{
|
|
22
|
-
provide: I${dashToPascal(name)}Repository,
|
|
23
|
-
useValue: {}
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
provide: ILoggerAdapter,
|
|
27
|
-
useValue: {
|
|
28
|
-
info: jest.fn()
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
provide: I${dashToPascal(name)}CreateAdapter,
|
|
33
|
-
useFactory: (${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository, logger: ILoggerAdapter) => {
|
|
34
|
-
return new ${dashToPascal(name)}CreateUsecase(${snakeToCamel(name)}Repository, logger);
|
|
35
|
-
},
|
|
36
|
-
inject: [I${dashToPascal(name)}Repository, ILoggerAdapter]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}).compile();
|
|
40
|
-
|
|
41
|
-
usecase = app.get(I${dashToPascal(name)}CreateAdapter);
|
|
42
|
-
repository = app.get(I${dashToPascal(name)}Repository);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('when no input is specified, should expect an error', async () => {
|
|
46
|
-
await TestUtils.expectZodError(
|
|
47
|
-
() => usecase.execute({} as ${dashToPascal(name)}CreateInput),
|
|
48
|
-
(issues: ZodIssue[]) => {
|
|
49
|
-
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('name') }]);
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const input: ${dashToPascal(name)}CreateInput = {
|
|
55
|
-
name: 'name'
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
test('when ${snakeToCamel(name)} created successfully, should expect a ${snakeToCamel(name)}', async () => {
|
|
59
|
-
const output: ${dashToPascal(name)}CreateOutput = { created: true, id: TestUtils.getMockUUID() };
|
|
60
|
-
repository.findOne = jest.fn().mockResolvedValue(null);
|
|
61
|
-
repository.create = jest.fn().mockResolvedValue(output);
|
|
62
|
-
|
|
63
|
-
await expect(usecase.execute(input)).resolves.toEqual(output);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
`
|
|
67
|
-
|
|
68
|
-
module.exports = {
|
|
69
|
-
getCoreUsecaseCreateTest
|
|
70
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../../textUtils")
|
|
2
|
-
const getCoreUsecaseDeleteTest = (name) => `import { Test } from '@nestjs/testing';
|
|
3
|
-
import { ZodIssue } from 'zod';
|
|
4
|
-
|
|
5
|
-
import { I${dashToPascal(name)}DeleteAdapter } from '@/modules/${name}/adapter';
|
|
6
|
-
import { ApiNotFoundException } from '@/utils/exception';
|
|
7
|
-
import { TestUtils } from '@/utils/tests';
|
|
8
|
-
|
|
9
|
-
import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
|
|
10
|
-
import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
|
|
11
|
-
import { ${dashToPascal(name)}DeleteInput, ${dashToPascal(name)}DeleteUsecase } from '../${name}-delete';
|
|
12
|
-
|
|
13
|
-
describe(${dashToPascal(name)}DeleteUsecase.name, () => {
|
|
14
|
-
let usecase: I${dashToPascal(name)}DeleteAdapter;
|
|
15
|
-
let repository: I${dashToPascal(name)}Repository;
|
|
16
|
-
|
|
17
|
-
beforeEach(async () => {
|
|
18
|
-
const app = await Test.createTestingModule({
|
|
19
|
-
imports: [],
|
|
20
|
-
providers: [
|
|
21
|
-
{
|
|
22
|
-
provide: I${dashToPascal(name)}Repository,
|
|
23
|
-
useValue: {}
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
provide: I${dashToPascal(name)}DeleteAdapter,
|
|
27
|
-
useFactory: (${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) => {
|
|
28
|
-
return new ${dashToPascal(name)}DeleteUsecase(${snakeToCamel(name)}Repository);
|
|
29
|
-
},
|
|
30
|
-
inject: [I${dashToPascal(name)}Repository]
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}).compile();
|
|
34
|
-
|
|
35
|
-
usecase = app.get(I${dashToPascal(name)}DeleteAdapter);
|
|
36
|
-
repository = app.get(I${dashToPascal(name)}Repository);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('when no input is specified, should expect an error', async () => {
|
|
40
|
-
await TestUtils.expectZodError(
|
|
41
|
-
() => usecase.execute({} as ${dashToPascal(name)}DeleteInput),
|
|
42
|
-
(issues: ZodIssue[]) => {
|
|
43
|
-
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const input: ${dashToPascal(name)}DeleteInput = {
|
|
49
|
-
id: TestUtils.getMockUUID()
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
test('when ${snakeToCamel(name)} not found, should expect an error', async () => {
|
|
53
|
-
repository.findById = jest.fn().mockResolvedValue(null);
|
|
54
|
-
|
|
55
|
-
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const ${snakeToCamel(name)} = new ${dashToPascal(name)}Entity({
|
|
59
|
-
id: TestUtils.getMockUUID(),
|
|
60
|
-
name: 'dummy'
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('when ${snakeToCamel(name)} deleted successfully, should expect a ${snakeToCamel(name)}', async () => {
|
|
64
|
-
repository.findById = jest.fn().mockResolvedValue(${snakeToCamel(name)});
|
|
65
|
-
repository.updateOne = jest.fn();
|
|
66
|
-
|
|
67
|
-
await expect(usecase.execute(input)).resolves.toEqual({
|
|
68
|
-
...${snakeToCamel(name)},
|
|
69
|
-
deletedAt: expect.any(Date)
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
`
|
|
74
|
-
|
|
75
|
-
module.exports = {
|
|
76
|
-
getCoreUsecaseDeleteTest
|
|
77
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreUsecaseGetByIdTest = (name) => `import { Test } from '@nestjs/testing';
|
|
4
|
-
import { ZodIssue } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { I${dashToPascal(name)}GetByIdAdapter } from '@/modules/${name}/adapter';
|
|
7
|
-
import { ApiNotFoundException } from '@/utils/exception';
|
|
8
|
-
import { TestUtils } from '@/utils/tests';
|
|
9
|
-
|
|
10
|
-
import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
|
|
11
|
-
import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
|
|
12
|
-
import { ${dashToPascal(name)}GetByIdInput, ${dashToPascal(name)}GetByIdUsecase } from '../${name}-get-by-id';
|
|
13
|
-
|
|
14
|
-
describe(${dashToPascal(name)}GetByIdUsecase.name, () => {
|
|
15
|
-
let usecase: I${dashToPascal(name)}GetByIdAdapter;
|
|
16
|
-
let repository: I${dashToPascal(name)}Repository;
|
|
17
|
-
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
const app = await Test.createTestingModule({
|
|
20
|
-
imports: [],
|
|
21
|
-
providers: [
|
|
22
|
-
{
|
|
23
|
-
provide: I${dashToPascal(name)}Repository,
|
|
24
|
-
useValue: {}
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
provide: I${dashToPascal(name)}GetByIdAdapter,
|
|
28
|
-
useFactory: (${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) => {
|
|
29
|
-
return new ${dashToPascal(name)}GetByIdUsecase(${snakeToCamel(name)}Repository);
|
|
30
|
-
},
|
|
31
|
-
inject: [I${dashToPascal(name)}Repository]
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
}).compile();
|
|
35
|
-
|
|
36
|
-
usecase = app.get(I${dashToPascal(name)}GetByIdAdapter);
|
|
37
|
-
repository = app.get(I${dashToPascal(name)}Repository);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('when no input is specified, should expect an error', async () => {
|
|
41
|
-
await TestUtils.expectZodError(
|
|
42
|
-
() => usecase.execute({} as ${dashToPascal(name)}GetByIdInput),
|
|
43
|
-
(issues: ZodIssue[]) => {
|
|
44
|
-
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const input: ${dashToPascal(name)}GetByIdInput = {
|
|
50
|
-
id: TestUtils.getMockUUID()
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
test('when ${snakeToCamel(name)} not found, should expect an error', async () => {
|
|
54
|
-
repository.findById = jest.fn().mockResolvedValue(null);
|
|
55
|
-
|
|
56
|
-
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const ${snakeToCamel(name)} = new ${dashToPascal(name)}Entity({
|
|
60
|
-
id: '61cc35f3-03d9-4b7f-9c63-59f32b013ef5',
|
|
61
|
-
name: 'dummy'
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('when ${snakeToCamel(name)} found, should expect a ${snakeToCamel(name)}', async () => {
|
|
65
|
-
repository.findById = jest.fn().mockResolvedValue(${snakeToCamel(name)});
|
|
66
|
-
|
|
67
|
-
await expect(usecase.execute(input)).resolves.toEqual(${snakeToCamel(name)});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
`
|
|
71
|
-
|
|
72
|
-
module.exports = {
|
|
73
|
-
getCoreUsecaseGetByIdTest
|
|
74
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const pluralize = require('pluralize')
|
|
3
|
-
const { dashToPascal, snakeToCamel } = require('../../../../../textUtils')
|
|
4
|
-
|
|
5
|
-
const getCoreUsecaseListTest = (name) => `import { Test } from '@nestjs/testing';
|
|
6
|
-
import { ZodIssue } from 'zod';
|
|
7
|
-
|
|
8
|
-
import { I${dashToPascal(name)}ListAdapter } from '@/modules/${name}/adapter';
|
|
9
|
-
import { TestUtils } from '@/utils/tests';
|
|
10
|
-
|
|
11
|
-
import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
|
|
12
|
-
import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
|
|
13
|
-
import { ${dashToPascal(name)}ListInput, ${dashToPascal(name)}ListOutput, ${dashToPascal(name)}ListUsecase } from '../${name}-list';
|
|
14
|
-
|
|
15
|
-
describe(${dashToPascal(name)}ListUsecase.name, () => {
|
|
16
|
-
let usecase: I${dashToPascal(name)}ListAdapter;
|
|
17
|
-
let repository: I${dashToPascal(name)}Repository;
|
|
18
|
-
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
const app = await Test.createTestingModule({
|
|
21
|
-
imports: [],
|
|
22
|
-
providers: [
|
|
23
|
-
{
|
|
24
|
-
provide: I${dashToPascal(name)}Repository,
|
|
25
|
-
useValue: {}
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
provide: I${dashToPascal(name)}ListAdapter,
|
|
29
|
-
useFactory: (${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) => {
|
|
30
|
-
return new ${dashToPascal(name)}ListUsecase(${snakeToCamel(name)}Repository);
|
|
31
|
-
},
|
|
32
|
-
inject: [I${dashToPascal(name)}Repository]
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}).compile();
|
|
36
|
-
|
|
37
|
-
usecase = app.get(I${dashToPascal(name)}ListAdapter);
|
|
38
|
-
repository = app.get(I${dashToPascal(name)}Repository);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('when sort input is specified, should expect an error', async () => {
|
|
42
|
-
await TestUtils.expectZodError(
|
|
43
|
-
() => usecase.execute({} as ${dashToPascal(name)}ListInput),
|
|
44
|
-
(issues: ZodIssue[]) => {
|
|
45
|
-
expect(issues).toEqual([
|
|
46
|
-
{ message: 'Required', path: 'sort' },
|
|
47
|
-
{ message: 'Required', path: 'search' }
|
|
48
|
-
]);
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const input: ${dashToPascal(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } };
|
|
54
|
-
|
|
55
|
-
const ${snakeToCamel(name)} = new ${dashToPascal(name)}Entity({
|
|
56
|
-
id: TestUtils.getMockUUID(),
|
|
57
|
-
name: 'dummy',
|
|
58
|
-
createdAt: new Date(),
|
|
59
|
-
updatedAt: new Date()
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const ${pluralize(snakeToCamel(name))} = [${snakeToCamel(name)}];
|
|
63
|
-
|
|
64
|
-
test('when ${snakeToCamel(name)} are found, should expect an ${snakeToCamel(name)} list', async () => {
|
|
65
|
-
const output: ${dashToPascal(name)}ListOutput = { docs: ${pluralize(snakeToCamel(name))}, page: 1, limit: 1, total: 1 };
|
|
66
|
-
repository.paginate = jest.fn().mockResolvedValue(output);
|
|
67
|
-
|
|
68
|
-
await expect(usecase.execute(input)).resolves.toEqual({
|
|
69
|
-
docs: ${pluralize(snakeToCamel(name))},
|
|
70
|
-
page: 1,
|
|
71
|
-
limit: 1,
|
|
72
|
-
total: 1
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('when ${snakeToCamel(name)} not found, should expect an empty list', async () => {
|
|
77
|
-
const output: ${dashToPascal(name)}ListOutput = { docs: [], page: 1, limit: 1, total: 1 };
|
|
78
|
-
repository.paginate = jest.fn().mockResolvedValue(output);
|
|
79
|
-
|
|
80
|
-
await expect(usecase.execute(input)).resolves.toEqual(output);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
`
|
|
84
|
-
|
|
85
|
-
module.exports = {
|
|
86
|
-
getCoreUsecaseListTest
|
|
87
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreUsecaseUpdateTest = (name) => `import { Test } from '@nestjs/testing';
|
|
4
|
-
import { ZodIssue } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { ILoggerAdapter, LoggerModule } from '@/infra/logger';
|
|
7
|
-
import { I${dashToPascal(name)}UpdateAdapter } from '@/modules/${name}/adapter';
|
|
8
|
-
import { ApiNotFoundException } from '@/utils/exception';
|
|
9
|
-
import { TestUtils } from '@/utils/tests';
|
|
10
|
-
|
|
11
|
-
import { ${dashToPascal(name)}Entity } from '../../entity/${name}';
|
|
12
|
-
import { I${dashToPascal(name)}Repository } from '../../repository/${name}';
|
|
13
|
-
import { ${dashToPascal(name)}UpdateInput, ${dashToPascal(name)}UpdateOutput, ${dashToPascal(name)}UpdateUsecase } from '../${name}-update';
|
|
14
|
-
|
|
15
|
-
describe(${dashToPascal(name)}UpdateUsecase.name, () => {
|
|
16
|
-
let usecase: I${dashToPascal(name)}UpdateAdapter;
|
|
17
|
-
let repository: I${dashToPascal(name)}Repository;
|
|
18
|
-
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
const app = await Test.createTestingModule({
|
|
21
|
-
imports: [LoggerModule],
|
|
22
|
-
providers: [
|
|
23
|
-
{
|
|
24
|
-
provide: I${dashToPascal(name)}Repository,
|
|
25
|
-
useValue: {}
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
provide: I${dashToPascal(name)}UpdateAdapter,
|
|
29
|
-
useFactory: (${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository, logger: ILoggerAdapter) => {
|
|
30
|
-
return new ${dashToPascal(name)}UpdateUsecase(${snakeToCamel(name)}Repository, logger);
|
|
31
|
-
},
|
|
32
|
-
inject: [I${dashToPascal(name)}Repository, ILoggerAdapter]
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}).compile();
|
|
36
|
-
|
|
37
|
-
usecase = app.get(I${dashToPascal(name)}UpdateAdapter);
|
|
38
|
-
repository = app.get(I${dashToPascal(name)}Repository);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('when no input is specified, should expect an error', async () => {
|
|
42
|
-
await TestUtils.expectZodError(
|
|
43
|
-
() => usecase.execute({} as ${dashToPascal(name)}UpdateInput),
|
|
44
|
-
(issues: ZodIssue[]) => {
|
|
45
|
-
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const input: ${dashToPascal(name)}UpdateInput = {
|
|
51
|
-
id: TestUtils.getMockUUID()
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
test('when ${snakeToCamel(name)} not found, should expect an error', async () => {
|
|
55
|
-
repository.findById = jest.fn().mockResolvedValue(null);
|
|
56
|
-
|
|
57
|
-
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const ${snakeToCamel(name)}: ${dashToPascal(name)}UpdateOutput = new ${dashToPascal(name)}Entity({
|
|
61
|
-
id: TestUtils.getMockUUID(),
|
|
62
|
-
name: 'dummy'
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('when ${snakeToCamel(name)} updated successfully, should expect an ${snakeToCamel(name)}', async () => {
|
|
66
|
-
repository.findById = jest.fn().mockResolvedValue(${snakeToCamel(name)});
|
|
67
|
-
repository.updateOne = jest.fn().mockResolvedValue(null);
|
|
68
|
-
|
|
69
|
-
await expect(usecase.execute(input)).resolves.toEqual(${snakeToCamel(name)});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
`
|
|
73
|
-
|
|
74
|
-
module.exports = {
|
|
75
|
-
getCoreUsecaseUpdateTest
|
|
76
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
import { ILoggerAdapter } from '@/infra/logger';
|
|
6
|
-
import { CreatedModel } from '@/infra/repository';
|
|
7
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
8
|
-
import { IUsecase } from '@/utils/usecase';
|
|
9
|
-
import { UUIDUtils } from '@/utils/uuid';
|
|
10
|
-
|
|
11
|
-
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
12
|
-
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
13
|
-
|
|
14
|
-
export const ${dashToPascal(name)}CreateSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
15
|
-
name: true
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export type ${dashToPascal(name)}CreateInput = z.infer<typeof ${dashToPascal(name)}CreateSchema>;
|
|
19
|
-
export type ${dashToPascal(name)}CreateOutput = CreatedModel;
|
|
20
|
-
|
|
21
|
-
export class ${dashToPascal(name)}CreateUsecase implements IUsecase {
|
|
22
|
-
constructor(
|
|
23
|
-
private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository,
|
|
24
|
-
private readonly loggerService: ILoggerAdapter
|
|
25
|
-
) {}
|
|
26
|
-
|
|
27
|
-
@ValidateSchema(${dashToPascal(name)}CreateSchema)
|
|
28
|
-
async execute(input: ${dashToPascal(name)}CreateInput): Promise<${dashToPascal(name)}CreateOutput> {
|
|
29
|
-
const entity = new ${dashToPascal(name)}Entity({ id: UUIDUtils.create(), ...input });
|
|
30
|
-
|
|
31
|
-
const ${snakeToCamel(name)} = await this.${snakeToCamel(name)}Repository.create(entity);
|
|
32
|
-
|
|
33
|
-
this.loggerService.info({ message: '${snakeToCamel(name)} created.', obj: { ${snakeToCamel(name)} } });
|
|
34
|
-
return ${snakeToCamel(name)};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
module.exports = {
|
|
40
|
-
getCoreUsecaseCreate
|
|
41
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
6
|
-
import { ApiNotFoundException } from '@/utils/exception';
|
|
7
|
-
import { IUsecase } from '@/utils/usecase';
|
|
8
|
-
|
|
9
|
-
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
10
|
-
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
11
|
-
|
|
12
|
-
export const ${dashToPascal(name)}DeleteSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
13
|
-
id: true
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export type ${dashToPascal(name)}DeleteInput = z.infer<typeof ${dashToPascal(name)}DeleteSchema>;
|
|
17
|
-
export type ${dashToPascal(name)}DeleteOutput = ${dashToPascal(name)}Entity;
|
|
18
|
-
|
|
19
|
-
export class ${dashToPascal(name)}DeleteUsecase implements IUsecase {
|
|
20
|
-
constructor(private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) {}
|
|
21
|
-
|
|
22
|
-
@ValidateSchema(${dashToPascal(name)}DeleteSchema)
|
|
23
|
-
async execute({ id }: ${dashToPascal(name)}DeleteInput): Promise<${dashToPascal(name)}DeleteOutput> {
|
|
24
|
-
const model = await this.${snakeToCamel(name)}Repository.findById(id);
|
|
25
|
-
|
|
26
|
-
if (!model) {
|
|
27
|
-
throw new ApiNotFoundException('${snakeToCamel(name)}NotFound');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const ${snakeToCamel(name)} = new ${dashToPascal(name)}Entity(model);
|
|
31
|
-
|
|
32
|
-
${snakeToCamel(name)}.deactivated();
|
|
33
|
-
|
|
34
|
-
await this.${snakeToCamel(name)}Repository.updateOne({ id: ${snakeToCamel(name)}.id }, ${snakeToCamel(name)});
|
|
35
|
-
|
|
36
|
-
return ${snakeToCamel(name)};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
module.exports = {
|
|
42
|
-
getCoreUsecaseDelete
|
|
43
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreUsecaseGetById = (name) => `import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
6
|
-
import { ApiNotFoundException } from '@/utils/exception';
|
|
7
|
-
import { IUsecase } from '@/utils/usecase';
|
|
8
|
-
|
|
9
|
-
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
10
|
-
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
11
|
-
|
|
12
|
-
export const ${dashToPascal(name)}GetByIdSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
13
|
-
id: true
|
|
14
|
-
});
|
|
15
|
-
export type ${dashToPascal(name)}GetByIdInput = z.infer<typeof ${dashToPascal(name)}GetByIdSchema>;
|
|
16
|
-
export type ${dashToPascal(name)}GetByIdOutput = ${dashToPascal(name)}Entity;
|
|
17
|
-
|
|
18
|
-
export class ${dashToPascal(name)}GetByIdUsecase implements IUsecase {
|
|
19
|
-
constructor(private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) {}
|
|
20
|
-
|
|
21
|
-
@ValidateSchema(${dashToPascal(name)}GetByIdSchema)
|
|
22
|
-
async execute({ id }: ${dashToPascal(name)}GetByIdInput): Promise<${dashToPascal(name)}GetByIdOutput> {
|
|
23
|
-
const ${snakeToCamel(name)} = await this.${snakeToCamel(name)}Repository.findById(id);
|
|
24
|
-
|
|
25
|
-
if (!${snakeToCamel(name)}) {
|
|
26
|
-
throw new ApiNotFoundException('${snakeToCamel(name)}NotFound');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const entity = new ${dashToPascal(name)}Entity(${snakeToCamel(name)});
|
|
30
|
-
|
|
31
|
-
return entity;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`
|
|
35
|
-
|
|
36
|
-
module.exports = {
|
|
37
|
-
getCoreUsecaseGetById
|
|
38
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const pluralize = require('pluralize')
|
|
2
|
-
const { dashToPascal, snakeToCamel } = require('../../../../textUtils')
|
|
3
|
-
|
|
4
|
-
const getCoreUsecaseList = (name) => `import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
7
|
-
import { PaginationInput, PaginationOutput, PaginationSchema } from '@/utils/pagination';
|
|
8
|
-
import { SearchSchema } from '@/utils/search';
|
|
9
|
-
import { SortSchema } from '@/utils/sort';
|
|
10
|
-
import { IUsecase } from '@/utils/usecase';
|
|
11
|
-
|
|
12
|
-
import { ${dashToPascal(name)}Entity } from '../entity/${name}';
|
|
13
|
-
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
14
|
-
|
|
15
|
-
export const ${dashToPascal(name)}ListSchema = z.intersection(PaginationSchema, SortSchema.merge(SearchSchema));
|
|
16
|
-
|
|
17
|
-
export type ${dashToPascal(name)}ListInput = PaginationInput<${dashToPascal(name)}Entity>;
|
|
18
|
-
export type ${dashToPascal(name)}ListOutput = PaginationOutput<${dashToPascal(name)}Entity>;
|
|
19
|
-
|
|
20
|
-
export class ${dashToPascal(name)}ListUsecase implements IUsecase {
|
|
21
|
-
constructor(private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) {}
|
|
22
|
-
|
|
23
|
-
@ValidateSchema(${dashToPascal(name)}ListSchema)
|
|
24
|
-
async execute(input: ${dashToPascal(name)}ListInput): Promise<${dashToPascal(name)}ListOutput> {
|
|
25
|
-
const ${pluralize(snakeToCamel(name))} = await this.${snakeToCamel(name)}Repository.paginate(input);
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
docs: ${pluralize(snakeToCamel(name))}.docs.map((u) => new ${dashToPascal(name)}Entity(u)),
|
|
29
|
-
limit: ${pluralize(snakeToCamel(name))}.limit,
|
|
30
|
-
page: ${pluralize(snakeToCamel(name))}.page,
|
|
31
|
-
total: ${pluralize(snakeToCamel(name))}.total
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
`
|
|
36
|
-
|
|
37
|
-
module.exports = {
|
|
38
|
-
getCoreUsecaseList
|
|
39
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
import { ILoggerAdapter } from '@/infra/logger';
|
|
6
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
7
|
-
import { ApiNotFoundException } from '@/utils/exception';
|
|
8
|
-
import { IUsecase } from '@/utils/usecase';
|
|
9
|
-
|
|
10
|
-
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
11
|
-
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
12
|
-
|
|
13
|
-
export const ${dashToPascal(name)}UpdateSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
14
|
-
id: true
|
|
15
|
-
}).merge(${dashToPascal(name)}EntitySchema.omit({ id: true }).partial());
|
|
16
|
-
|
|
17
|
-
export type ${dashToPascal(name)}UpdateInput = Partial<z.infer<typeof ${dashToPascal(name)}UpdateSchema>>;
|
|
18
|
-
export type ${dashToPascal(name)}UpdateOutput = ${dashToPascal(name)}Entity;
|
|
19
|
-
|
|
20
|
-
export class ${dashToPascal(name)}UpdateUsecase implements IUsecase {
|
|
21
|
-
constructor(
|
|
22
|
-
private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository,
|
|
23
|
-
private readonly loggerService: ILoggerAdapter
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
@ValidateSchema(${dashToPascal(name)}UpdateSchema)
|
|
27
|
-
async execute(input: ${dashToPascal(name)}UpdateInput): Promise<${dashToPascal(name)}UpdateOutput> {
|
|
28
|
-
const ${snakeToCamel(name)} = await this.${snakeToCamel(name)}Repository.findById(input.id as string);
|
|
29
|
-
|
|
30
|
-
if (!${snakeToCamel(name)}) {
|
|
31
|
-
throw new ApiNotFoundException('${snakeToCamel(name)}NotFound');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const ${snakeToCamel(name)}Found = new ${dashToPascal(name)}Entity(${snakeToCamel(name)});
|
|
35
|
-
|
|
36
|
-
const entity = new ${dashToPascal(name)}Entity({ ...${snakeToCamel(name)}Found, ...input });
|
|
37
|
-
|
|
38
|
-
await this.${snakeToCamel(name)}Repository.updateOne({ id: entity.id }, entity);
|
|
39
|
-
|
|
40
|
-
this.loggerService.info({ message: '${snakeToCamel(name)} updated.', obj: { ${snakeToCamel(name)}: input } });
|
|
41
|
-
|
|
42
|
-
const updated = await this.${snakeToCamel(name)}Repository.findById(entity.id);
|
|
43
|
-
|
|
44
|
-
return new ${dashToPascal(name)}Entity(updated as ${dashToPascal(name)}Entity);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
`
|
|
48
|
-
|
|
49
|
-
module.exports = {
|
|
50
|
-
getCoreUsecaseUpdate
|
|
51
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const { dashToPascal } = require("../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreEntity = (name) => `import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
import { BaseEntity } from '@/utils/entity';
|
|
6
|
-
|
|
7
|
-
const ID = z.string().uuid();
|
|
8
|
-
const Name = z.string().min(1).max(200).trim();
|
|
9
|
-
const CreatedAt = z.date().nullish();
|
|
10
|
-
const UpdatedAt = z.date().nullish();
|
|
11
|
-
const DeletedAt = z.date().nullish();
|
|
12
|
-
|
|
13
|
-
export const ${dashToPascal(name)}EntitySchema = z.object({
|
|
14
|
-
id: ID,
|
|
15
|
-
name: Name,
|
|
16
|
-
createdAt: CreatedAt,
|
|
17
|
-
updatedAt: UpdatedAt,
|
|
18
|
-
deletedAt: DeletedAt
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
type ${dashToPascal(name)} = z.infer<typeof ${dashToPascal(name)}EntitySchema>;
|
|
22
|
-
|
|
23
|
-
export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>(${dashToPascal(name)}EntitySchema) {
|
|
24
|
-
name!: string;
|
|
25
|
-
|
|
26
|
-
constructor(entity: ${dashToPascal(name)}) {
|
|
27
|
-
super();
|
|
28
|
-
Object.assign(this, this.validate(entity));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
`
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
34
|
-
getCoreEntity
|
|
35
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const { dashToPascal } = require("../../../../textUtils")
|
|
2
|
-
|
|
3
|
-
const getCoreRepository = (name) => `import { IRepository } from '@/infra/repository';
|
|
4
|
-
|
|
5
|
-
import { ${dashToPascal(name)}Entity } from '../entity/${name}';
|
|
6
|
-
import { ${dashToPascal(name)}ListInput, ${dashToPascal(name)}ListOutput } from '../use-cases/${name}-list';
|
|
7
|
-
|
|
8
|
-
export abstract class I${dashToPascal(name)}Repository extends IRepository<${dashToPascal(name)}Entity> {
|
|
9
|
-
abstract paginate(input: ${dashToPascal(name)}ListInput): Promise<${dashToPascal(name)}ListOutput>;
|
|
10
|
-
}
|
|
11
|
-
`
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
getCoreRepository
|
|
15
|
-
}
|