@mikemajesty/microservice-crud 4.5.11 → 4.5.13
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 +8 -8
- package/src/templates/module/controller.js +0 -3
- package/src/templates/mongo/core/use-cases/__tests__/get-by-id.spec.js +10 -10
- package/src/templates/mongo/core/use-cases/get-by-id.js +5 -5
- package/src/templates/mongo/modules/adapter.js +3 -3
- package/src/templates/mongo/modules/controller.js +7 -10
- package/src/templates/mongo/modules/module.js +4 -4
- package/src/templates/mongo/modules/swagger.js +3 -3
- package/src/templates/postgres/core/use-cases/__tests__/get-by-id.spec.js +10 -10
- package/src/templates/postgres/core/use-cases/get-by-id.js +5 -5
- package/src/templates/postgres/modules/adapter.js +3 -3
- package/src/templates/postgres/modules/controller.js +7 -10
- package/src/templates/postgres/modules/module.js +2 -2
- package/src/templates/postgres/modules/swagger.js +3 -3
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -21,8 +21,8 @@ const { getCoreUsecaseCreateTest } = require('./templates/postgres/core/use-case
|
|
|
21
21
|
const { getCoreUsecaseUpdateTest } = require('./templates/postgres/core/use-cases/__tests__/update.spec');
|
|
22
22
|
const { getCoreUsecaseDeleteTest } = require('./templates/postgres/core/use-cases/__tests__/delete.spec');
|
|
23
23
|
const { getCoreUsecaseListTest } = require('./templates/postgres/core/use-cases/__tests__/list.spec');
|
|
24
|
-
const {
|
|
25
|
-
const {
|
|
24
|
+
const { getCoreUsecaseGetByIdTest } = require('./templates/postgres/core/use-cases/__tests__/get-by-id.spec');
|
|
25
|
+
const { getCoreUsecaseGetById } = require('./templates/postgres/core/use-cases/get-by-id');
|
|
26
26
|
const { getCoreUsecaseList } = require('./templates/postgres/core/use-cases/list');
|
|
27
27
|
const { getCoreEntity } = require('./templates/postgres/core/entity/entity');
|
|
28
28
|
const { getCoreRepository } = require('./templates/postgres/core/repository/repository');
|
|
@@ -41,8 +41,8 @@ const { getCoreUsecaseCreateTest: getCoreUsecaseCreateMongoTest } = require('./t
|
|
|
41
41
|
const { getCoreUsecaseUpdateTest: getCoreUsecaseUpdateMongoTest } = require('./templates/mongo/core/use-cases/__tests__/update.spec');
|
|
42
42
|
const { getCoreUsecaseDeleteTest: getCoreUsecaseDeleteMongoTest } = require('./templates/mongo/core/use-cases/__tests__/delete.spec');
|
|
43
43
|
const { getCoreUsecaseListTest: getCoreUsecaseListMongoTest } = require('./templates/mongo/core/use-cases/__tests__/list.spec');
|
|
44
|
-
const {
|
|
45
|
-
const {
|
|
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
46
|
const { getCoreUsecaseList: getCoreUsecaseListMongo } = require('./templates/mongo/core/use-cases/list');
|
|
47
47
|
const { getCoreEntity: getCoreEntityMongo } = require('./templates/mongo/core/entity/entity');
|
|
48
48
|
const { getCoreRepository: getCoreRepositoryMongo } = require('./templates/mongo/core/repository/repository');
|
|
@@ -172,7 +172,7 @@ const createPostgresCrud = async (name) => {
|
|
|
172
172
|
|
|
173
173
|
fs.writeFileSync(`${useCasesPath}/${name}-create.ts`, getCoreUsecaseCreate(name))
|
|
174
174
|
fs.writeFileSync(`${useCasesPath}/${name}-delete.ts`, getCoreUsecaseDelete(name))
|
|
175
|
-
fs.writeFileSync(`${useCasesPath}/${name}-get-by-id.ts`,
|
|
175
|
+
fs.writeFileSync(`${useCasesPath}/${name}-get-by-id.ts`, getCoreUsecaseGetById(name))
|
|
176
176
|
fs.writeFileSync(`${useCasesPath}/${name}-list.ts`, getCoreUsecaseList(name))
|
|
177
177
|
fs.writeFileSync(`${useCasesPath}/${name}-update.ts`, getCoreUsecaseUpdate(name))
|
|
178
178
|
|
|
@@ -182,7 +182,7 @@ const createPostgresCrud = async (name) => {
|
|
|
182
182
|
fs.writeFileSync(`${useCasesPathTest}/${name}-update.spec.ts`, getCoreUsecaseUpdateTest(name))
|
|
183
183
|
fs.writeFileSync(`${useCasesPathTest}/${name}-delete.spec.ts`, getCoreUsecaseDeleteTest(name))
|
|
184
184
|
fs.writeFileSync(`${useCasesPathTest}/${name}-list.spec.ts`, getCoreUsecaseListTest(name))
|
|
185
|
-
fs.writeFileSync(`${useCasesPathTest}/${name}-get-by-id.spec.ts`,
|
|
185
|
+
fs.writeFileSync(`${useCasesPathTest}/${name}-get-by-id.spec.ts`, getCoreUsecaseGetByIdTest(name))
|
|
186
186
|
|
|
187
187
|
const schemasPath = `${__dirname}/scafold/postgres/schemas`;
|
|
188
188
|
if (fs.existsSync(schemasPath)) {
|
|
@@ -244,7 +244,7 @@ const createMongoCrud = async (name) => {
|
|
|
244
244
|
|
|
245
245
|
fs.writeFileSync(`${useCasesPath}/${name}-create.ts`, getCoreUsecaseCreateMongo(name))
|
|
246
246
|
fs.writeFileSync(`${useCasesPath}/${name}-delete.ts`, getCoreUsecaseDeleteMongo(name))
|
|
247
|
-
fs.writeFileSync(`${useCasesPath}/${name}-get-by-id.ts`,
|
|
247
|
+
fs.writeFileSync(`${useCasesPath}/${name}-get-by-id.ts`, getCoreUsecaseGetByIdMongo(name))
|
|
248
248
|
fs.writeFileSync(`${useCasesPath}/${name}-list.ts`, getCoreUsecaseListMongo(name))
|
|
249
249
|
fs.writeFileSync(`${useCasesPath}/${name}-update.ts`, getCoreUsecaseUpdateMongo(name))
|
|
250
250
|
|
|
@@ -255,7 +255,7 @@ const createMongoCrud = async (name) => {
|
|
|
255
255
|
fs.writeFileSync(`${useCasesPathTest}/${name}-update.spec.ts`, getCoreUsecaseUpdateMongoTest(name))
|
|
256
256
|
fs.writeFileSync(`${useCasesPathTest}/${name}-delete.spec.ts`, getCoreUsecaseDeleteMongoTest(name))
|
|
257
257
|
fs.writeFileSync(`${useCasesPathTest}/${name}-list.spec.ts`, getCoreUsecaseListMongoTest(name))
|
|
258
|
-
fs.writeFileSync(`${useCasesPathTest}/${name}-get-by-id.spec.ts`,
|
|
258
|
+
fs.writeFileSync(`${useCasesPathTest}/${name}-get-by-id.spec.ts`, getCoreUsecaseGetByIdMongoTest(name))
|
|
259
259
|
|
|
260
260
|
const schemasPath = `${__dirname}/scafold/mongo/schemas`;
|
|
261
261
|
|
|
@@ -8,8 +8,6 @@ function capitalizeFirstLetter(string) {
|
|
|
8
8
|
const getModuleControllerModule = (name) => `import { Controller, Get, Req } from '@nestjs/common';
|
|
9
9
|
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
10
10
|
|
|
11
|
-
import { Roles } from '@/utils/decorators';
|
|
12
|
-
import { UserRoleEnum } from '@/core/user/entity/user';
|
|
13
11
|
import { ApiRequest } from '@/utils/request';
|
|
14
12
|
|
|
15
13
|
import { SwagggerResponse } from './swagger';
|
|
@@ -17,7 +15,6 @@ import { SwagggerResponse } from './swagger';
|
|
|
17
15
|
@Controller('${pluralize(name)}')
|
|
18
16
|
@ApiTags('${name}')
|
|
19
17
|
@ApiBearerAuth()
|
|
20
|
-
@Roles(UserRoleEnum.USER)
|
|
21
18
|
export class ${capitalizeFirstLetter(name)}Controller {
|
|
22
19
|
@Get()
|
|
23
20
|
@ApiResponse(SwagggerResponse.get[200])
|
|
@@ -3,24 +3,24 @@ function capitalizeFirstLetter(string) {
|
|
|
3
3
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const getCoreUsecaseGetByIdTest = (name) => `import { Test } from '@nestjs/testing';
|
|
7
7
|
|
|
8
|
-
import { I${capitalizeFirstLetter(name)}
|
|
8
|
+
import { I${capitalizeFirstLetter(name)}GetByIdAdapter } from '@/modules/${name}/adapter';
|
|
9
9
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
10
10
|
import { expectZodError, getMockUUID } from '@/utils/tests';
|
|
11
11
|
|
|
12
12
|
import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
|
|
13
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
14
|
-
import { ${capitalizeFirstLetter(name)}
|
|
14
|
+
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdOutput, ${capitalizeFirstLetter(name)}GetByIdUsecase } from '../${name}-get-by-id';
|
|
15
15
|
|
|
16
|
-
const successInput: ${capitalizeFirstLetter(name)}
|
|
16
|
+
const successInput: ${capitalizeFirstLetter(name)}GetByIdInput = {
|
|
17
17
|
id: getMockUUID()
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const failureInput: ${capitalizeFirstLetter(name)}
|
|
20
|
+
const failureInput: ${capitalizeFirstLetter(name)}GetByIdInput = {};
|
|
21
21
|
|
|
22
22
|
describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
23
|
-
let usecase: I${capitalizeFirstLetter(name)}
|
|
23
|
+
let usecase: I${capitalizeFirstLetter(name)}GetByIdAdapter;
|
|
24
24
|
let repository: I${capitalizeFirstLetter(name)}Repository;
|
|
25
25
|
|
|
26
26
|
beforeEach(async () => {
|
|
@@ -32,7 +32,7 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
32
32
|
useValue: {}
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
provide: I${capitalizeFirstLetter(name)}
|
|
35
|
+
provide: I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
36
36
|
useFactory: (${name}Repository: I${capitalizeFirstLetter(name)}Repository) => {
|
|
37
37
|
return new ${capitalizeFirstLetter(name)}GetByIdUsecase(${name}Repository);
|
|
38
38
|
},
|
|
@@ -41,7 +41,7 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
41
41
|
]
|
|
42
42
|
}).compile();
|
|
43
43
|
|
|
44
|
-
usecase = app.get(I${capitalizeFirstLetter(name)}
|
|
44
|
+
usecase = app.get(I${capitalizeFirstLetter(name)}GetByIdAdapter);
|
|
45
45
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
46
46
|
});
|
|
47
47
|
|
|
@@ -61,7 +61,7 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
test('when ${name} found, should expect a ${name} that has been found', async () => {
|
|
64
|
-
const findByIdOutput: ${capitalizeFirstLetter(name)}
|
|
64
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}GetByIdOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
65
65
|
id: '61cc35f3-03d9-4b7f-9c63-59f32b013ef5',
|
|
66
66
|
name: 'dummy'
|
|
67
67
|
});
|
|
@@ -74,5 +74,5 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
74
74
|
`
|
|
75
75
|
|
|
76
76
|
module.exports = {
|
|
77
|
-
|
|
77
|
+
getCoreUsecaseGetByIdTest
|
|
78
78
|
}
|
|
@@ -3,7 +3,7 @@ function capitalizeFirstLetter(string) {
|
|
|
3
3
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const getCoreUsecaseGetById = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
8
|
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
@@ -15,14 +15,14 @@ import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}
|
|
|
15
15
|
export const ${capitalizeFirstLetter(name)}GetByIdSchema = ${capitalizeFirstLetter(name)}EntitySchema.pick({
|
|
16
16
|
id: true
|
|
17
17
|
});
|
|
18
|
-
export type ${capitalizeFirstLetter(name)}
|
|
19
|
-
export type ${capitalizeFirstLetter(name)}
|
|
18
|
+
export type ${capitalizeFirstLetter(name)}GetByIdInput = z.infer<typeof ${capitalizeFirstLetter(name)}GetByIdSchema>;
|
|
19
|
+
export type ${capitalizeFirstLetter(name)}GetByIdOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
20
20
|
|
|
21
21
|
export class ${capitalizeFirstLetter(name)}GetByIdUsecase implements IUsecase {
|
|
22
22
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
23
23
|
|
|
24
24
|
@ValidateSchema(${capitalizeFirstLetter(name)}GetByIdSchema)
|
|
25
|
-
async execute({ id }: ${capitalizeFirstLetter(name)}
|
|
25
|
+
async execute({ id }: ${capitalizeFirstLetter(name)}GetByIdInput): Promise<${capitalizeFirstLetter(name)}GetByIdOutput> {
|
|
26
26
|
const ${name} = await this.${name}Repository.findById(id);
|
|
27
27
|
|
|
28
28
|
if (!${name}) {
|
|
@@ -37,5 +37,5 @@ export class ${capitalizeFirstLetter(name)}GetByIdUsecase implements IUsecase {
|
|
|
37
37
|
`
|
|
38
38
|
|
|
39
39
|
module.exports = {
|
|
40
|
-
|
|
40
|
+
getCoreUsecaseGetById
|
|
41
41
|
}
|
|
@@ -5,7 +5,7 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getModuleAdapter = (name) => `import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
7
7
|
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
8
|
-
import { ${capitalizeFirstLetter(name)}
|
|
8
|
+
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
9
9
|
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
10
10
|
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
11
11
|
import { IUsecase } from '@/utils/usecase';
|
|
@@ -26,8 +26,8 @@ export abstract class I${capitalizeFirstLetter(name)}DeleteAdapter implements IU
|
|
|
26
26
|
abstract execute(input: ${capitalizeFirstLetter(name)}DeleteInput): Promise<${capitalizeFirstLetter(name)}DeleteOutput>;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export abstract class I${capitalizeFirstLetter(name)}
|
|
30
|
-
abstract execute(input: ${capitalizeFirstLetter(name)}
|
|
29
|
+
export abstract class I${capitalizeFirstLetter(name)}GetByIdAdapter implements IUsecase {
|
|
30
|
+
abstract execute(input: ${capitalizeFirstLetter(name)}GetByIdInput): Promise<${capitalizeFirstLetter(name)}GetByIdOutput>;
|
|
31
31
|
}
|
|
32
32
|
`
|
|
33
33
|
|
|
@@ -7,13 +7,11 @@ function capitalizeFirstLetter(string) {
|
|
|
7
7
|
const getModuleController = (name) => `import { Controller, Delete, Get, Post, Put, Req } from '@nestjs/common';
|
|
8
8
|
import { ApiBearerAuth, ApiBody, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
9
9
|
|
|
10
|
-
import { Roles } from '@/utils/decorators';
|
|
11
10
|
import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
12
11
|
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
13
|
-
import { ${capitalizeFirstLetter(name)}
|
|
12
|
+
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
14
13
|
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
15
14
|
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
16
|
-
import { UserRoleEnum } from '@/core/user/entity/user';
|
|
17
15
|
import { ApiRequest } from '@/utils/request';
|
|
18
16
|
import { SearchHttpSchema } from '@/utils/search';
|
|
19
17
|
import { SortHttpSchema } from '@/utils/sort';
|
|
@@ -21,7 +19,7 @@ import { SortHttpSchema } from '@/utils/sort';
|
|
|
21
19
|
import {
|
|
22
20
|
I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
23
21
|
I${capitalizeFirstLetter(name)}DeleteAdapter,
|
|
24
|
-
I${capitalizeFirstLetter(name)}
|
|
22
|
+
I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
25
23
|
I${capitalizeFirstLetter(name)}ListAdapter,
|
|
26
24
|
I${capitalizeFirstLetter(name)}UpdateAdapter
|
|
27
25
|
} from './adapter';
|
|
@@ -30,14 +28,13 @@ import { SwaggerRequest, SwaggerResponse } from './swagger';
|
|
|
30
28
|
@Controller('/${pluralize(name)}')
|
|
31
29
|
@ApiTags('${pluralize(name)}')
|
|
32
30
|
@ApiBearerAuth()
|
|
33
|
-
@Roles(UserRoleEnum.USER)
|
|
34
31
|
export class ${capitalizeFirstLetter(name)}Controller {
|
|
35
32
|
constructor(
|
|
36
33
|
private readonly ${name}CreateUsecase: I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
37
34
|
private readonly ${name}UpdateUsecase: I${capitalizeFirstLetter(name)}UpdateAdapter,
|
|
38
35
|
private readonly ${name}DeleteUsecase: I${capitalizeFirstLetter(name)}DeleteAdapter,
|
|
39
36
|
private readonly ${name}ListUsecase: I${capitalizeFirstLetter(name)}ListAdapter,
|
|
40
|
-
private readonly ${name}
|
|
37
|
+
private readonly ${name}GetByIdUsecase: I${capitalizeFirstLetter(name)}GetByIdAdapter
|
|
41
38
|
) {}
|
|
42
39
|
|
|
43
40
|
@Post()
|
|
@@ -75,10 +72,10 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
75
72
|
|
|
76
73
|
@Get('/:id')
|
|
77
74
|
@ApiParam({ name: 'id', required: true })
|
|
78
|
-
@ApiResponse(SwaggerResponse.
|
|
79
|
-
@ApiResponse(SwaggerResponse.
|
|
80
|
-
async getById(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}
|
|
81
|
-
return await this.${name}
|
|
75
|
+
@ApiResponse(SwaggerResponse.getById[200])
|
|
76
|
+
@ApiResponse(SwaggerResponse.getById[404])
|
|
77
|
+
async getById(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}GetByIdOutput> {
|
|
78
|
+
return await this.${name}GetByIdUsecase.execute(params as ${capitalizeFirstLetter(name)}GetByIdInput);
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
@Delete('/:id')
|
|
@@ -25,7 +25,7 @@ import { MongoRepositoryModelSessionType } from '@/utils/database/mongoose';
|
|
|
25
25
|
import {
|
|
26
26
|
I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
27
27
|
I${capitalizeFirstLetter(name)}DeleteAdapter,
|
|
28
|
-
I${capitalizeFirstLetter(name)}
|
|
28
|
+
I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
29
29
|
I${capitalizeFirstLetter(name)}ListAdapter,
|
|
30
30
|
I${capitalizeFirstLetter(name)}UpdateAdapter
|
|
31
31
|
} from './adapter';
|
|
@@ -54,7 +54,7 @@ import { ${capitalizeFirstLetter(name)}Repository } from './repository';
|
|
|
54
54
|
|
|
55
55
|
return new ${capitalizeFirstLetter(name)}Repository(repository);
|
|
56
56
|
},
|
|
57
|
-
inject: [getConnectionToken(ConnectionName.
|
|
57
|
+
inject: [getConnectionToken(ConnectionName.CATS)]
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
provide: I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
@@ -85,7 +85,7 @@ import { ${capitalizeFirstLetter(name)}Repository } from './repository';
|
|
|
85
85
|
inject: [I${capitalizeFirstLetter(name)}Repository]
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
|
-
provide: I${capitalizeFirstLetter(name)}
|
|
88
|
+
provide: I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
89
89
|
useFactory: (${name}Repository: I${capitalizeFirstLetter(name)}Repository) => {
|
|
90
90
|
return new ${capitalizeFirstLetter(name)}GetByIdUsecase(${name}Repository);
|
|
91
91
|
},
|
|
@@ -98,7 +98,7 @@ import { ${capitalizeFirstLetter(name)}Repository } from './repository';
|
|
|
98
98
|
I${capitalizeFirstLetter(name)}UpdateAdapter,
|
|
99
99
|
I${capitalizeFirstLetter(name)}ListAdapter,
|
|
100
100
|
I${capitalizeFirstLetter(name)}DeleteAdapter,
|
|
101
|
-
I${capitalizeFirstLetter(name)}
|
|
101
|
+
I${capitalizeFirstLetter(name)}GetByIdAdapter
|
|
102
102
|
]
|
|
103
103
|
})
|
|
104
104
|
export class ${capitalizeFirstLetter(name)}Module implements NestModule {
|
|
@@ -8,7 +8,7 @@ function capitalizeFirstLetter(string) {
|
|
|
8
8
|
const getModuleSwagger = (name) => `import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
9
9
|
import { ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
10
10
|
import { ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
11
|
-
import { ${capitalizeFirstLetter(name)}
|
|
11
|
+
import { ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
12
12
|
import { ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
14
14
|
import { Swagger } from '@/utils/docs/swagger';
|
|
@@ -40,10 +40,10 @@ export const SwaggerResponse = {
|
|
|
40
40
|
description: '${name} not found.'
|
|
41
41
|
})
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
getById: {
|
|
44
44
|
200: Swagger.defaultResponseJSON({
|
|
45
45
|
status: 200,
|
|
46
|
-
json: output as ${capitalizeFirstLetter(name)}
|
|
46
|
+
json: output as ${capitalizeFirstLetter(name)}GetByIdOutput,
|
|
47
47
|
description: '${name} found.'
|
|
48
48
|
}),
|
|
49
49
|
404: Swagger.defaultResponseError({
|
|
@@ -3,24 +3,24 @@ function capitalizeFirstLetter(string) {
|
|
|
3
3
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const getCoreUsecaseGetByIdTest = (name) => `import { Test } from '@nestjs/testing';
|
|
7
7
|
|
|
8
|
-
import { I${capitalizeFirstLetter(name)}
|
|
8
|
+
import { I${capitalizeFirstLetter(name)}GetByIdAdapter } from '@/modules/${name}/adapter';
|
|
9
9
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
10
10
|
import { expectZodError, getMockUUID } from '@/utils/tests';
|
|
11
11
|
|
|
12
12
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
13
|
-
import { ${capitalizeFirstLetter(name)}
|
|
13
|
+
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdOutput, ${capitalizeFirstLetter(name)}GetByIdUsecase } from '../${name}-get-by-id';
|
|
14
14
|
import { ${capitalizeFirstLetter(name)}Entity } from './../../entity/${name}';
|
|
15
15
|
|
|
16
|
-
const successInput: ${capitalizeFirstLetter(name)}
|
|
16
|
+
const successInput: ${capitalizeFirstLetter(name)}GetByIdInput = {
|
|
17
17
|
id: getMockUUID()
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const failureInput: ${capitalizeFirstLetter(name)}
|
|
20
|
+
const failureInput: ${capitalizeFirstLetter(name)}GetByIdInput = {};
|
|
21
21
|
|
|
22
22
|
describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
23
|
-
let usecase: I${capitalizeFirstLetter(name)}
|
|
23
|
+
let usecase: I${capitalizeFirstLetter(name)}GetByIdAdapter;
|
|
24
24
|
let repository: I${capitalizeFirstLetter(name)}Repository;
|
|
25
25
|
|
|
26
26
|
beforeEach(async () => {
|
|
@@ -31,7 +31,7 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
31
31
|
useValue: {}
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
provide: I${capitalizeFirstLetter(name)}
|
|
34
|
+
provide: I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
35
35
|
useFactory: (${name}Repository: I${capitalizeFirstLetter(name)}Repository) => {
|
|
36
36
|
return new ${capitalizeFirstLetter(name)}GetByIdUsecase(${name}Repository);
|
|
37
37
|
},
|
|
@@ -40,7 +40,7 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
40
40
|
]
|
|
41
41
|
}).compile();
|
|
42
42
|
|
|
43
|
-
usecase = app.get(I${capitalizeFirstLetter(name)}
|
|
43
|
+
usecase = app.get(I${capitalizeFirstLetter(name)}GetByIdAdapter);
|
|
44
44
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -60,7 +60,7 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
test('when ${name} found, should expect a ${name} that has been found', async () => {
|
|
63
|
-
const findByIdOutput: ${capitalizeFirstLetter(name)}
|
|
63
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}GetByIdOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
64
64
|
id: getMockUUID(),
|
|
65
65
|
name: 'dummy'
|
|
66
66
|
});
|
|
@@ -72,5 +72,5 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
72
72
|
`
|
|
73
73
|
|
|
74
74
|
module.exports = {
|
|
75
|
-
|
|
75
|
+
getCoreUsecaseGetByIdTest
|
|
76
76
|
}
|
|
@@ -3,7 +3,7 @@ function capitalizeFirstLetter(string) {
|
|
|
3
3
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const getCoreUsecaseGetById = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
8
|
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ${capitalizeFirstLetter(name)}EntitySchema } from '@/core/${name}/entity/${name}';
|
|
@@ -18,14 +18,14 @@ export const ${capitalizeFirstLetter(name)}GetByIdSchema = ${capitalizeFirstLett
|
|
|
18
18
|
id: true
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
export type ${capitalizeFirstLetter(name)}
|
|
22
|
-
export type ${capitalizeFirstLetter(name)}
|
|
21
|
+
export type ${capitalizeFirstLetter(name)}GetByIdInput = z.infer<typeof ${capitalizeFirstLetter(name)}GetByIdSchema>;
|
|
22
|
+
export type ${capitalizeFirstLetter(name)}GetByIdOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
23
23
|
|
|
24
24
|
export class ${capitalizeFirstLetter(name)}GetByIdUsecase implements IUsecase {
|
|
25
25
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
26
26
|
|
|
27
27
|
@ValidateSchema(${capitalizeFirstLetter(name)}GetByIdSchema)
|
|
28
|
-
async execute({ id }: ${capitalizeFirstLetter(name)}
|
|
28
|
+
async execute({ id }: ${capitalizeFirstLetter(name)}GetByIdInput): Promise<${capitalizeFirstLetter(name)}GetByIdOutput> {
|
|
29
29
|
const ${name} = await this.${name}Repository.findById(id);
|
|
30
30
|
|
|
31
31
|
if (!${name}) {
|
|
@@ -38,5 +38,5 @@ export class ${capitalizeFirstLetter(name)}GetByIdUsecase implements IUsecase {
|
|
|
38
38
|
`
|
|
39
39
|
|
|
40
40
|
module.exports = {
|
|
41
|
-
|
|
41
|
+
getCoreUsecaseGetById
|
|
42
42
|
}
|
|
@@ -5,7 +5,7 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getModuleAdapter = (name) => `import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
7
7
|
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
8
|
-
import { ${capitalizeFirstLetter(name)}
|
|
8
|
+
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
9
9
|
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
10
10
|
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
11
11
|
import { IUsecase } from '@/utils/usecase';
|
|
@@ -18,8 +18,8 @@ export abstract class I${capitalizeFirstLetter(name)}UpdateAdapter implements IU
|
|
|
18
18
|
abstract execute(input: ${capitalizeFirstLetter(name)}UpdateInput): Promise<${capitalizeFirstLetter(name)}UpdateOutput>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export abstract class I${capitalizeFirstLetter(name)}
|
|
22
|
-
abstract execute(input: ${capitalizeFirstLetter(name)}
|
|
21
|
+
export abstract class I${capitalizeFirstLetter(name)}GetByIdAdapter implements IUsecase {
|
|
22
|
+
abstract execute(input: ${capitalizeFirstLetter(name)}GetByIdInput): Promise<${capitalizeFirstLetter(name)}GetByIdOutput>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export abstract class I${capitalizeFirstLetter(name)}ListAdapter implements IUsecase {
|
|
@@ -7,13 +7,11 @@ function capitalizeFirstLetter(string) {
|
|
|
7
7
|
const getModuleController = (name) => `import { Controller, Delete, Get, Post, Put, Req } from '@nestjs/common';
|
|
8
8
|
import { ApiBearerAuth, ApiBody, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
9
9
|
|
|
10
|
-
import { Roles } from '@/utils/decorators';
|
|
11
10
|
import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
12
11
|
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
13
|
-
import { ${capitalizeFirstLetter(name)}
|
|
12
|
+
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
14
13
|
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
15
14
|
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
16
|
-
import { UserRoleEnum } from '@/core/user/entity/user';
|
|
17
15
|
import { ApiRequest } from '@/utils/request';
|
|
18
16
|
import { SearchHttpSchema } from '@/utils/search';
|
|
19
17
|
import { SortHttpSchema } from '@/utils/sort';
|
|
@@ -21,7 +19,7 @@ import { SortHttpSchema } from '@/utils/sort';
|
|
|
21
19
|
import {
|
|
22
20
|
I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
23
21
|
I${capitalizeFirstLetter(name)}DeleteAdapter,
|
|
24
|
-
I${capitalizeFirstLetter(name)}
|
|
22
|
+
I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
25
23
|
I${capitalizeFirstLetter(name)}ListAdapter,
|
|
26
24
|
I${capitalizeFirstLetter(name)}UpdateAdapter
|
|
27
25
|
} from './adapter';
|
|
@@ -30,12 +28,11 @@ import { SwaggerRequest, SwaggerResponse } from './swagger';
|
|
|
30
28
|
@Controller('${pluralize(name)}')
|
|
31
29
|
@ApiTags('${pluralize(name)}')
|
|
32
30
|
@ApiBearerAuth()
|
|
33
|
-
@Roles(UserRoleEnum.USER)
|
|
34
31
|
export class ${capitalizeFirstLetter(name)}Controller {
|
|
35
32
|
constructor(
|
|
36
33
|
private readonly ${name}Create: I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
37
34
|
private readonly ${name}Update: I${capitalizeFirstLetter(name)}UpdateAdapter,
|
|
38
|
-
private readonly ${name}
|
|
35
|
+
private readonly ${name}GetById: I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
39
36
|
private readonly ${name}List: I${capitalizeFirstLetter(name)}ListAdapter,
|
|
40
37
|
private readonly ${name}Delete: I${capitalizeFirstLetter(name)}DeleteAdapter
|
|
41
38
|
) {}
|
|
@@ -58,10 +55,10 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
58
55
|
|
|
59
56
|
@Get('/:id')
|
|
60
57
|
@ApiParam({ name: 'id', required: true })
|
|
61
|
-
@ApiResponse(SwaggerResponse.
|
|
62
|
-
@ApiResponse(SwaggerResponse.
|
|
63
|
-
async getById(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}
|
|
64
|
-
return await this.${name}
|
|
58
|
+
@ApiResponse(SwaggerResponse.getById[200])
|
|
59
|
+
@ApiResponse(SwaggerResponse.getById[404])
|
|
60
|
+
async getById(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}GetByIdOutput> {
|
|
61
|
+
return await this.${name}GetById.execute(params as ${capitalizeFirstLetter(name)}GetByIdInput);
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
@Get()
|
|
@@ -23,7 +23,7 @@ import { TokenLibModule } from '@/libs/token';
|
|
|
23
23
|
import {
|
|
24
24
|
I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
25
25
|
I${capitalizeFirstLetter(name)}DeleteAdapter,
|
|
26
|
-
I${capitalizeFirstLetter(name)}
|
|
26
|
+
I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
27
27
|
I${capitalizeFirstLetter(name)}ListAdapter,
|
|
28
28
|
I${capitalizeFirstLetter(name)}UpdateAdapter
|
|
29
29
|
} from './adapter';
|
|
@@ -52,7 +52,7 @@ import { ${capitalizeFirstLetter(name)}Repository } from './repository';
|
|
|
52
52
|
inject: [ILoggerAdapter, I${capitalizeFirstLetter(name)}Repository]
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
provide: I${capitalizeFirstLetter(name)}
|
|
55
|
+
provide: I${capitalizeFirstLetter(name)}GetByIdAdapter,
|
|
56
56
|
useFactory: (repository: I${capitalizeFirstLetter(name)}Repository) => new ${capitalizeFirstLetter(name)}GetByIdUsecase(repository),
|
|
57
57
|
inject: [I${capitalizeFirstLetter(name)}Repository]
|
|
58
58
|
},
|
|
@@ -8,7 +8,7 @@ function capitalizeFirstLetter(string) {
|
|
|
8
8
|
const getModuleSwagger = (name) => `import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
9
9
|
import { ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
10
10
|
import { ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
11
|
-
import { ${capitalizeFirstLetter(name)}
|
|
11
|
+
import { ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
12
12
|
import { ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
14
14
|
import { Swagger } from '@/utils/docs/swagger';
|
|
@@ -40,10 +40,10 @@ export const SwaggerResponse = {
|
|
|
40
40
|
description: '${name} not found.'
|
|
41
41
|
})
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
getById: {
|
|
44
44
|
200: Swagger.defaultResponseJSON({
|
|
45
45
|
status: 200,
|
|
46
|
-
json: output as ${capitalizeFirstLetter(name)}
|
|
46
|
+
json: output as ${capitalizeFirstLetter(name)}GetByIdOutput,
|
|
47
47
|
description: '${name} found.'
|
|
48
48
|
}),
|
|
49
49
|
404: Swagger.defaultResponseError({
|