@mikemajesty/microservice-crud 0.1.8 → 0.2.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/src/templates/mongo/core/use-cases/__tests__/create.spec.js +22 -16
- package/src/templates/mongo/core/use-cases/__tests__/delete.spec.js +24 -16
- package/src/templates/mongo/core/use-cases/__tests__/getByID.spec.js +24 -15
- package/src/templates/mongo/core/use-cases/__tests__/list.spec.js +29 -21
- package/src/templates/mongo/core/use-cases/__tests__/update.spec.js +24 -21
- package/src/templates/mongo/core/use-cases/create.js +1 -1
- package/src/templates/mongo/core/use-cases/delete.js +1 -1
- package/src/templates/mongo/core/use-cases/getByID.js +1 -1
- package/src/templates/mongo/core/use-cases/list.js +1 -1
- package/src/templates/mongo/core/use-cases/update.js +1 -1
- package/src/templates/mongo/modules/controller.js +13 -13
- package/src/templates/mongo/modules/swagger.js +22 -12
- package/src/templates/postgres/core/use-cases/__tests__/create.spec.js +22 -13
- package/src/templates/postgres/core/use-cases/__tests__/delete.spec.js +23 -15
- package/src/templates/postgres/core/use-cases/__tests__/getByID.spec.js +21 -14
- package/src/templates/postgres/core/use-cases/__tests__/list.spec.js +27 -21
- package/src/templates/postgres/core/use-cases/__tests__/update.spec.js +22 -14
- package/src/templates/postgres/core/use-cases/create.js +1 -1
- package/src/templates/postgres/core/use-cases/delete.js +1 -1
- package/src/templates/postgres/core/use-cases/getByID.js +1 -1
- package/src/templates/postgres/core/use-cases/list.js +1 -1
- package/src/templates/postgres/core/use-cases/update.js +1 -1
- package/src/templates/postgres/modules/controller.js +12 -12
- package/src/templates/postgres/modules/swagger.js +22 -12
package/package.json
CHANGED
|
@@ -8,14 +8,16 @@ const getCoreUsecaseCreateTest = (name) => `import { Test } from '@nestjs/testin
|
|
|
8
8
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}CreateAdapter } from '@/modules/${name}/adapter';
|
|
10
10
|
import { ApiInternalServerException } from '@/utils/exception';
|
|
11
|
-
import { expectZodError } from '@/utils/tests/tests';;
|
|
11
|
+
import { expectZodError, generateUUID } from '@/utils/tests/tests';;
|
|
12
12
|
|
|
13
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
14
|
-
import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateUsecase } from '../${name}-create';
|
|
14
|
+
import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput, ${capitalizeFirstLetter(name)}CreateUsecase } from '../${name}-create';
|
|
15
|
+
import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
|
|
15
16
|
|
|
16
|
-
const ${name} = {
|
|
17
|
-
name:
|
|
18
|
-
}
|
|
17
|
+
const successInput: ${capitalizeFirstLetter(name)}CreateInput = {
|
|
18
|
+
name: "name"
|
|
19
|
+
}
|
|
20
|
+
const failureInput: ${capitalizeFirstLetter(name)}CreateInput = {}
|
|
19
21
|
|
|
20
22
|
describe('${capitalizeFirstLetter(name)}CreateUsecase', () => {
|
|
21
23
|
let usecase: I${capitalizeFirstLetter(name)}CreateAdapter;
|
|
@@ -36,8 +38,8 @@ describe('${capitalizeFirstLetter(name)}CreateUsecase', () => {
|
|
|
36
38
|
},
|
|
37
39
|
{
|
|
38
40
|
provide: I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
39
|
-
useFactory: (
|
|
40
|
-
return new ${capitalizeFirstLetter(name)}CreateUsecase(
|
|
41
|
+
useFactory: (birdRepository: I${capitalizeFirstLetter(name)}Repository, logger: ILoggerAdapter) => {
|
|
42
|
+
return new ${capitalizeFirstLetter(name)}CreateUsecase(birdRepository, logger);
|
|
41
43
|
},
|
|
42
44
|
inject: [I${capitalizeFirstLetter(name)}Repository, ILoggerAdapter]
|
|
43
45
|
}
|
|
@@ -48,32 +50,36 @@ describe('${capitalizeFirstLetter(name)}CreateUsecase', () => {
|
|
|
48
50
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
49
51
|
});
|
|
50
52
|
|
|
51
|
-
test('
|
|
53
|
+
test('when no input is specified, should expect an error', async () => {
|
|
52
54
|
await expectZodError(
|
|
53
|
-
() => usecase.execute(
|
|
55
|
+
() => usecase.execute(failureInput),
|
|
54
56
|
(issues) => {
|
|
55
|
-
expect(issues).toEqual([{ message: 'Required', path: 'name' }]);
|
|
57
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof('name') }]);
|
|
56
58
|
}
|
|
57
59
|
);
|
|
58
60
|
});
|
|
59
61
|
|
|
60
|
-
test('should
|
|
62
|
+
test('when ${name} created successfully, should expect a ${name} that has been created', async () => {
|
|
63
|
+
const createOutput: ${capitalizeFirstLetter(name)}CreateOutput = { created: true, id: generateUUID() }
|
|
64
|
+
|
|
61
65
|
repository.findOne = jest.fn().mockResolvedValue(null);
|
|
62
|
-
repository.create = jest.fn().mockResolvedValue(
|
|
66
|
+
repository.create = jest.fn().mockResolvedValue(createOutput);
|
|
63
67
|
repository.startSession = jest.fn().mockResolvedValue({
|
|
64
68
|
commitTransaction: jest.fn()
|
|
65
69
|
});
|
|
66
|
-
|
|
70
|
+
|
|
71
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(createOutput);
|
|
67
72
|
});
|
|
68
73
|
|
|
69
|
-
test('
|
|
74
|
+
test('when transaction throw an error, should expect an error', async () => {
|
|
70
75
|
repository.findOne = jest.fn().mockResolvedValue(null);
|
|
71
|
-
repository.create = jest.fn().mockRejectedValue(new ApiInternalServerException(
|
|
76
|
+
repository.create = jest.fn().mockRejectedValue(new ApiInternalServerException());
|
|
72
77
|
repository.startSession = jest.fn().mockResolvedValue({
|
|
73
78
|
commitTransaction: jest.fn(),
|
|
74
79
|
abortTransaction: jest.fn()
|
|
75
80
|
});
|
|
76
|
-
|
|
81
|
+
|
|
82
|
+
await expect(usecase.execute(successInput)).rejects.toThrow(ApiInternalServerException);
|
|
77
83
|
});
|
|
78
84
|
});
|
|
79
85
|
`
|
|
@@ -11,12 +11,13 @@ import { expectZodError, generateUUID } from '@/utils/tests/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)}DeleteUsecase } from '../${name}-delete';
|
|
14
|
+
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput, ${capitalizeFirstLetter(name)}DeleteUsecase } from '../${name}-delete';
|
|
15
15
|
|
|
16
|
-
const ${name}
|
|
17
|
-
id: generateUUID()
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const successInput: ${capitalizeFirstLetter(name)}DeleteInput = {
|
|
17
|
+
id: generateUUID()
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const failureInput: ${capitalizeFirstLetter(name)}DeleteInput = {};
|
|
20
21
|
|
|
21
22
|
describe('${capitalizeFirstLetter(name)}DeleteUsecase', () => {
|
|
22
23
|
let usecase: I${capitalizeFirstLetter(name)}DeleteAdapter;
|
|
@@ -32,8 +33,8 @@ describe('${capitalizeFirstLetter(name)}DeleteUsecase', () => {
|
|
|
32
33
|
},
|
|
33
34
|
{
|
|
34
35
|
provide: I${capitalizeFirstLetter(name)}DeleteAdapter,
|
|
35
|
-
useFactory: (
|
|
36
|
-
return new ${capitalizeFirstLetter(name)}DeleteUsecase(
|
|
36
|
+
useFactory: (birdRepository: I${capitalizeFirstLetter(name)}Repository) => {
|
|
37
|
+
return new ${capitalizeFirstLetter(name)}DeleteUsecase(birdRepository);
|
|
37
38
|
},
|
|
38
39
|
inject: [I${capitalizeFirstLetter(name)}Repository]
|
|
39
40
|
}
|
|
@@ -44,25 +45,32 @@ describe('${capitalizeFirstLetter(name)}DeleteUsecase', () => {
|
|
|
44
45
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
45
46
|
});
|
|
46
47
|
|
|
47
|
-
test('
|
|
48
|
+
test('when no input is specified, should expect an error', async () => {
|
|
48
49
|
await expectZodError(
|
|
49
|
-
() => usecase.execute(
|
|
50
|
+
() => usecase.execute(failureInput),
|
|
50
51
|
(issues) => {
|
|
51
|
-
expect(issues).toEqual([{ message: '
|
|
52
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof("id") }]);
|
|
52
53
|
}
|
|
53
54
|
);
|
|
54
55
|
});
|
|
55
56
|
|
|
56
|
-
test('
|
|
57
|
+
test('when ${name} not found, should expect an error', async () => {
|
|
57
58
|
repository.findById = jest.fn().mockResolvedValue(null);
|
|
58
|
-
|
|
59
|
+
|
|
60
|
+
await expect(usecase.execute(successInput)).rejects.toThrowError(ApiNotFoundException);
|
|
59
61
|
});
|
|
60
62
|
|
|
61
|
-
test('should
|
|
62
|
-
|
|
63
|
+
test('when ${name} deleted successfully, should expect a ${name} that has been deleted', async () => {
|
|
64
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}DeleteOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
65
|
+
id: generateUUID(),
|
|
66
|
+
name: 'dummy'
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
repository.findById = jest.fn().mockResolvedValue(findByIdOutput);
|
|
63
70
|
repository.updateOne = jest.fn();
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
|
|
72
|
+
await expect(usecase.execute(successInput)).resolves.toEqual({
|
|
73
|
+
...findByIdOutput,
|
|
66
74
|
deletedAt: expect.any(Date)
|
|
67
75
|
});
|
|
68
76
|
});
|
|
@@ -11,12 +11,14 @@ import { expectZodError, generateUUID } from '@/utils/tests/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)}GetByIdUsecase } from '../${name}-getByID';
|
|
14
|
+
import { ${capitalizeFirstLetter(name)}GetByIDInput, ${capitalizeFirstLetter(name)}GetByIDOutput, ${capitalizeFirstLetter(name)}GetByIdUsecase } from '../${name}-getByID';
|
|
15
|
+
|
|
16
|
+
const successInput: ${capitalizeFirstLetter(name)}GetByIDInput = {
|
|
17
|
+
id: generateUUID()
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const failureInput: ${capitalizeFirstLetter(name)}GetByIDInput = {};
|
|
15
21
|
|
|
16
|
-
const ${name}Response = {
|
|
17
|
-
id: '61cc35f3-03d9-4b7f-9c63-59f32b013ef5',
|
|
18
|
-
name: 'dummy'
|
|
19
|
-
} as ${capitalizeFirstLetter(name)}Entity;
|
|
20
22
|
|
|
21
23
|
describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
22
24
|
let usecase: I${capitalizeFirstLetter(name)}GetByIDAdapter;
|
|
@@ -32,8 +34,8 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
32
34
|
},
|
|
33
35
|
{
|
|
34
36
|
provide: I${capitalizeFirstLetter(name)}GetByIDAdapter,
|
|
35
|
-
useFactory: (
|
|
36
|
-
return new ${capitalizeFirstLetter(name)}GetByIdUsecase(
|
|
37
|
+
useFactory: (birdRepository: I${capitalizeFirstLetter(name)}Repository) => {
|
|
38
|
+
return new ${capitalizeFirstLetter(name)}GetByIdUsecase(birdRepository);
|
|
37
39
|
},
|
|
38
40
|
inject: [I${capitalizeFirstLetter(name)}Repository]
|
|
39
41
|
}
|
|
@@ -44,23 +46,30 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
44
46
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
45
47
|
});
|
|
46
48
|
|
|
47
|
-
test('
|
|
49
|
+
test('when no input is specified, should expect an error', async () => {
|
|
48
50
|
await expectZodError(
|
|
49
|
-
() => usecase.execute(
|
|
51
|
+
() => usecase.execute(failureInput),
|
|
50
52
|
(issues) => {
|
|
51
|
-
expect(issues).toEqual([{ message: 'Required', path:
|
|
53
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof("id") }]);
|
|
52
54
|
}
|
|
53
55
|
);
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
test('
|
|
58
|
+
test('when ${name} not found, should expect an error', async () => {
|
|
57
59
|
repository.findById = jest.fn().mockResolvedValue(null);
|
|
58
|
-
|
|
60
|
+
|
|
61
|
+
await expect(usecase.execute(successInput)).rejects.toThrowError(ApiNotFoundException);
|
|
59
62
|
});
|
|
60
63
|
|
|
61
|
-
test('should
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
test('when ${name} found, should expect a ${name} that has been found', async () => {
|
|
65
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}GetByIDOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
66
|
+
id: '61cc35f3-03d9-4b7f-9c63-59f32b013ef5',
|
|
67
|
+
name: 'dummy'
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
repository.findById = jest.fn().mockResolvedValue(findByIdOutput);
|
|
71
|
+
|
|
72
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(findByIdOutput);
|
|
64
73
|
});
|
|
65
74
|
});
|
|
66
75
|
`
|
|
@@ -10,14 +10,11 @@ import { expectZodError, generateUUID } from '@/utils/tests/tests';;
|
|
|
10
10
|
|
|
11
11
|
import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
|
|
12
12
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
13
|
-
import { ${capitalizeFirstLetter(name)}ListUsecase } from '../${name}-list';
|
|
13
|
+
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput, ${capitalizeFirstLetter(name)}ListUsecase } from '../${name}-list';
|
|
14
14
|
|
|
15
|
-
const ${name}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
createdAt: new Date(),
|
|
19
|
-
updatedAt: new Date()
|
|
20
|
-
} as ${capitalizeFirstLetter(name)}Entity;
|
|
15
|
+
const successInput: ${capitalizeFirstLetter(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } }
|
|
16
|
+
|
|
17
|
+
const failureInput: ${capitalizeFirstLetter(name)}ListInput = { search: null, sort: null, limit: 10, page: 1 };
|
|
21
18
|
|
|
22
19
|
describe('${capitalizeFirstLetter(name)}ListUsecase', () => {
|
|
23
20
|
let usecase: I${capitalizeFirstLetter(name)}ListAdapter;
|
|
@@ -33,8 +30,8 @@ describe('${capitalizeFirstLetter(name)}ListUsecase', () => {
|
|
|
33
30
|
},
|
|
34
31
|
{
|
|
35
32
|
provide: I${capitalizeFirstLetter(name)}ListAdapter,
|
|
36
|
-
useFactory: (
|
|
37
|
-
return new ${capitalizeFirstLetter(name)}ListUsecase(
|
|
33
|
+
useFactory: (birdRepository: I${capitalizeFirstLetter(name)}Repository) => {
|
|
34
|
+
return new ${capitalizeFirstLetter(name)}ListUsecase(birdRepository);
|
|
38
35
|
},
|
|
39
36
|
inject: [I${capitalizeFirstLetter(name)}Repository]
|
|
40
37
|
}
|
|
@@ -45,31 +42,42 @@ describe('${capitalizeFirstLetter(name)}ListUsecase', () => {
|
|
|
45
42
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
46
43
|
});
|
|
47
44
|
|
|
48
|
-
test('
|
|
45
|
+
test('when sort input is specified, should expect an error', async () => {
|
|
49
46
|
await expectZodError(
|
|
50
|
-
() => usecase.execute(
|
|
47
|
+
() => usecase.execute(failureInput),
|
|
51
48
|
(issues) => {
|
|
52
49
|
expect(issues).toEqual([{ message: 'Expected object, received null', path: 'sort' }]);
|
|
53
50
|
}
|
|
54
51
|
);
|
|
55
52
|
});
|
|
56
53
|
|
|
57
|
-
test('should list
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
test('when ${name} are found, should expect an ${name} list', async () => {
|
|
55
|
+
const doc = new ${capitalizeFirstLetter(name)}Entity({
|
|
56
|
+
id: generateUUID(),
|
|
57
|
+
name: 'dummy',
|
|
58
|
+
createdAt: new Date(),
|
|
59
|
+
updatedAt: new Date()
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const paginateOutput: ${capitalizeFirstLetter(name)}ListOutput = { docs: [doc], page: 1, limit: 1, total: 1 };
|
|
63
|
+
|
|
64
|
+
repository.paginate = jest.fn().mockResolvedValue(paginateOutput);
|
|
65
|
+
|
|
66
|
+
await expect(usecase.execute(successInput)).resolves.toEqual({
|
|
67
|
+
docs: [doc],
|
|
62
68
|
page: 1,
|
|
63
69
|
limit: 1,
|
|
64
70
|
total: 1
|
|
65
71
|
});
|
|
66
72
|
});
|
|
67
73
|
|
|
68
|
-
test('
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
test('when ${name} not found, should expect an empty list', async () => {
|
|
75
|
+
const paginateOutput: ${capitalizeFirstLetter(name)}ListOutput = { docs: [], page: 1, limit: 1, total: 1 };
|
|
76
|
+
|
|
77
|
+
repository.paginate = jest.fn().mockResolvedValue(paginateOutput);
|
|
78
|
+
|
|
79
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(
|
|
80
|
+
paginateOutput
|
|
73
81
|
);
|
|
74
82
|
});
|
|
75
83
|
});
|
|
@@ -12,18 +12,14 @@ import { expectZodError, generateUUID } from '@/utils/tests/tests';;
|
|
|
12
12
|
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
|
|
14
14
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
15
|
-
import { ${capitalizeFirstLetter(name)}UpdateInput } from '../${name}-update';
|
|
15
|
+
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '../${name}-update';
|
|
16
16
|
import { ${capitalizeFirstLetter(name)}UpdateUsecase } from '../${name}-update';
|
|
17
17
|
|
|
18
|
-
const ${name}
|
|
19
|
-
id: generateUUID()
|
|
20
|
-
|
|
21
|
-
} as ${capitalizeFirstLetter(name)}UpdateInput;
|
|
18
|
+
const successInput: ${capitalizeFirstLetter(name)}UpdateInput = {
|
|
19
|
+
id: generateUUID()
|
|
20
|
+
};
|
|
22
21
|
|
|
23
|
-
const ${name}
|
|
24
|
-
id: generateUUID(),
|
|
25
|
-
name: 'dummy'
|
|
26
|
-
} as ${capitalizeFirstLetter(name)}Entity;
|
|
22
|
+
const failureInput: ${capitalizeFirstLetter(name)}UpdateInput = {};
|
|
27
23
|
|
|
28
24
|
describe('${capitalizeFirstLetter(name)}UpdateUsecase', () => {
|
|
29
25
|
let usecase: I${capitalizeFirstLetter(name)}UpdateAdapter;
|
|
@@ -39,8 +35,8 @@ describe('${capitalizeFirstLetter(name)}UpdateUsecase', () => {
|
|
|
39
35
|
},
|
|
40
36
|
{
|
|
41
37
|
provide: I${capitalizeFirstLetter(name)}UpdateAdapter,
|
|
42
|
-
useFactory: (
|
|
43
|
-
return new ${capitalizeFirstLetter(name)}UpdateUsecase(
|
|
38
|
+
useFactory: (birdRepository: I${capitalizeFirstLetter(name)}Repository, logger: ILoggerAdapter) => {
|
|
39
|
+
return new ${capitalizeFirstLetter(name)}UpdateUsecase(birdRepository, logger);
|
|
44
40
|
},
|
|
45
41
|
inject: [I${capitalizeFirstLetter(name)}Repository, ILoggerAdapter]
|
|
46
42
|
}
|
|
@@ -51,24 +47,31 @@ describe('${capitalizeFirstLetter(name)}UpdateUsecase', () => {
|
|
|
51
47
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
52
48
|
});
|
|
53
49
|
|
|
54
|
-
test('
|
|
50
|
+
test('when no input is specified, should expect an error', async () => {
|
|
55
51
|
await expectZodError(
|
|
56
|
-
() => usecase.execute(
|
|
52
|
+
() => usecase.execute(failureInput),
|
|
57
53
|
(issues) => {
|
|
58
|
-
expect(issues).toEqual([{ message: 'Required', path:
|
|
54
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof("id") }]);
|
|
59
55
|
}
|
|
60
56
|
);
|
|
61
57
|
});
|
|
62
58
|
|
|
63
|
-
test('should
|
|
64
|
-
repository.findById = jest.fn().mockResolvedValue(
|
|
65
|
-
|
|
66
|
-
await expect(usecase.execute(
|
|
59
|
+
test('when ${name} not found, should expect an error', async () => {
|
|
60
|
+
repository.findById = jest.fn().mockResolvedValue(null);
|
|
61
|
+
|
|
62
|
+
await expect(usecase.execute(successInput)).rejects.toThrowError(ApiNotFoundException);
|
|
67
63
|
});
|
|
68
64
|
|
|
69
|
-
test('should
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
test('when ${name} updated successfully, should expect an ${name} that has been updated', async () => {
|
|
66
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}UpdateOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
67
|
+
id: generateUUID(),
|
|
68
|
+
name: 'dummy'
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
repository.findById = jest.fn().mockResolvedValue(findByIdOutput);
|
|
72
|
+
repository.updateOne = jest.fn().mockResolvedValue(null);
|
|
73
|
+
|
|
74
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(findByIdOutput);
|
|
72
75
|
});
|
|
73
76
|
});
|
|
74
77
|
`
|
|
@@ -17,7 +17,7 @@ export const ${capitalizeFirstLetter(name)}CreateSchema = ${capitalizeFirstLette
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
export type ${capitalizeFirstLetter(name)}CreateInput = z.infer<typeof ${capitalizeFirstLetter(name)}CreateSchema>;
|
|
20
|
-
export type ${capitalizeFirstLetter(name)}CreateOutput =
|
|
20
|
+
export type ${capitalizeFirstLetter(name)}CreateOutput = CreatedModel;
|
|
21
21
|
|
|
22
22
|
export class ${capitalizeFirstLetter(name)}CreateUsecase {
|
|
23
23
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerServide: ILoggerAdapter) {}
|
|
@@ -16,7 +16,7 @@ export const ${capitalizeFirstLetter(name)}DeleteSchema = ${capitalizeFirstLette
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
export type ${capitalizeFirstLetter(name)}DeleteInput = z.infer<typeof ${capitalizeFirstLetter(name)}DeleteSchema>;
|
|
19
|
-
export type ${capitalizeFirstLetter(name)}DeleteOutput =
|
|
19
|
+
export type ${capitalizeFirstLetter(name)}DeleteOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
20
20
|
|
|
21
21
|
export class ${capitalizeFirstLetter(name)}DeleteUsecase {
|
|
22
22
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
@@ -15,7 +15,7 @@ export const ${capitalizeFirstLetter(name)}GetByIdSchema = ${capitalizeFirstLett
|
|
|
15
15
|
id: true
|
|
16
16
|
});
|
|
17
17
|
export type ${capitalizeFirstLetter(name)}GetByIDInput = z.infer<typeof ${capitalizeFirstLetter(name)}GetByIdSchema>;
|
|
18
|
-
export type ${capitalizeFirstLetter(name)}GetByIDOutput =
|
|
18
|
+
export type ${capitalizeFirstLetter(name)}GetByIDOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
19
19
|
|
|
20
20
|
export class ${capitalizeFirstLetter(name)}GetByIdUsecase {
|
|
21
21
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
@@ -17,7 +17,7 @@ import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}
|
|
|
17
17
|
export const ${capitalizeFirstLetter(name)}ListSchema = z.intersection(PaginationSchema, SortSchema.merge(SearchSchema));
|
|
18
18
|
|
|
19
19
|
export type ${capitalizeFirstLetter(name)}ListInput = PaginationInput<${capitalizeFirstLetter(name)}Entity>;
|
|
20
|
-
export type ${capitalizeFirstLetter(name)}ListOutput =
|
|
20
|
+
export type ${capitalizeFirstLetter(name)}ListOutput = PaginationOutput<${capitalizeFirstLetter(name)}Entity>;
|
|
21
21
|
|
|
22
22
|
export class ${capitalizeFirstLetter(name)}ListUsecase {
|
|
23
23
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
@@ -17,7 +17,7 @@ export const ${capitalizeFirstLetter(name)}UpdateSchema = ${capitalizeFirstLette
|
|
|
17
17
|
}).merge(${capitalizeFirstLetter(name)}EntitySchema.omit({ id: true }).partial());
|
|
18
18
|
|
|
19
19
|
export type ${capitalizeFirstLetter(name)}UpdateInput = Partial<z.infer<typeof ${capitalizeFirstLetter(name)}UpdateSchema>>;
|
|
20
|
-
export type ${capitalizeFirstLetter(name)}UpdateOutput =
|
|
20
|
+
export type ${capitalizeFirstLetter(name)}UpdateOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
21
21
|
|
|
22
22
|
export class ${capitalizeFirstLetter(name)}UpdateUsecase {
|
|
23
23
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerServide: ILoggerAdapter) {}
|
|
@@ -27,10 +27,10 @@ import {
|
|
|
27
27
|
} from './adapter';
|
|
28
28
|
import { SwagggerRequest, SwagggerResponse } from './swagger';
|
|
29
29
|
|
|
30
|
-
@Controller()
|
|
31
|
-
@ApiTags('${name}')
|
|
30
|
+
@Controller('/${pluralize(name)}')
|
|
31
|
+
@ApiTags('${pluralize(name)}')
|
|
32
32
|
@ApiBearerAuth()
|
|
33
|
-
@Roles(UserRole.
|
|
33
|
+
@Roles(UserRole.USER)
|
|
34
34
|
export class ${capitalizeFirstLetter(name)}Controller {
|
|
35
35
|
constructor(
|
|
36
36
|
private readonly ${name}CreateUsecase: I${capitalizeFirstLetter(name)}CreateAdapter,
|
|
@@ -40,28 +40,28 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
40
40
|
private readonly ${name}GetByIDUsecase: I${capitalizeFirstLetter(name)}GetByIDAdapter
|
|
41
41
|
) {}
|
|
42
42
|
|
|
43
|
-
@Post(
|
|
43
|
+
@Post()
|
|
44
44
|
@ApiResponse(SwagggerResponse.create[200])
|
|
45
45
|
@ApiBody(SwagggerRequest.createBody)
|
|
46
|
-
async create(@Req() { body }: ApiRequest):
|
|
46
|
+
async create(@Req() { body }: ApiRequest): Promise<${capitalizeFirstLetter(name)}CreateOutput> {
|
|
47
47
|
return this.${name}CreateUsecase.execute(body as ${capitalizeFirstLetter(name)}CreateInput);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
@Put(
|
|
50
|
+
@Put()
|
|
51
51
|
@ApiResponse(SwagggerResponse.update[200])
|
|
52
52
|
@ApiResponse(SwagggerResponse.update[404])
|
|
53
53
|
@ApiBody(SwagggerRequest.updateBody)
|
|
54
|
-
async update(@Req() { body }: ApiRequest):
|
|
54
|
+
async update(@Req() { body }: ApiRequest): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
|
|
55
55
|
return this.${name}UpdateUsecase.execute(body as ${capitalizeFirstLetter(name)}UpdateInput);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
@Get(
|
|
58
|
+
@Get()
|
|
59
59
|
@ApiQuery(SwagggerRequest.listQuery.pagination.limit)
|
|
60
60
|
@ApiQuery(SwagggerRequest.listQuery.pagination.page)
|
|
61
61
|
@ApiQuery(SwagggerRequest.listQuery.sort)
|
|
62
62
|
@ApiQuery(SwagggerRequest.listQuery.search)
|
|
63
63
|
@ApiResponse(SwagggerResponse.list[200])
|
|
64
|
-
async list(@Req() { query }: ApiRequest):
|
|
64
|
+
async list(@Req() { query }: ApiRequest): Promise<${capitalizeFirstLetter(name)}ListOutput> {
|
|
65
65
|
const input: ${capitalizeFirstLetter(name)}ListInput = {
|
|
66
66
|
sort: SortHttpSchema.parse(query.sort),
|
|
67
67
|
search: SearchHttpSchema.parse(query.search),
|
|
@@ -72,19 +72,19 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
72
72
|
return await this.${name}ListUsecase.execute(input);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
@Get('
|
|
75
|
+
@Get('/:id')
|
|
76
76
|
@ApiParam({ name: 'id', required: true })
|
|
77
77
|
@ApiResponse(SwagggerResponse.getByID[200])
|
|
78
78
|
@ApiResponse(SwagggerResponse.getByID[404])
|
|
79
|
-
async getById(@Req() { params }: ApiRequest):
|
|
79
|
+
async getById(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}GetByIDOutput> {
|
|
80
80
|
return await this.${name}GetByIDUsecase.execute(params as ${capitalizeFirstLetter(name)}GetByIDInput);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
@Delete('
|
|
83
|
+
@Delete('/:id')
|
|
84
84
|
@ApiParam({ name: 'id', required: true })
|
|
85
85
|
@ApiResponse(SwagggerResponse.delete[200])
|
|
86
86
|
@ApiResponse(SwagggerResponse.delete[404])
|
|
87
|
-
async delete(@Req() { params }: ApiRequest):
|
|
87
|
+
async delete(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}DeleteOutput> {
|
|
88
88
|
return await this.${name}DeleteUsecase.execute(params as ${capitalizeFirstLetter(name)}DeleteInput);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
const pluralize = require('pluralize')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function capitalizeFirstLetter(string) {
|
|
4
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const getModuleSwagger = (name) => `import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
9
|
+
import { ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
10
|
+
import { ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
11
|
+
import { ${capitalizeFirstLetter(name)}GetByIDOutput } from '@/core/${name}/use-cases/${name}-getByID';
|
|
12
|
+
import { ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
13
|
+
import { ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
4
14
|
import { Swagger } from '@/utils/docs/swagger';
|
|
5
15
|
|
|
6
|
-
const
|
|
16
|
+
const input = new ${capitalizeFirstLetter(name)}Entity({
|
|
7
17
|
name: '<name>'
|
|
8
|
-
};
|
|
18
|
+
});
|
|
9
19
|
|
|
10
|
-
const
|
|
20
|
+
const output = new ${capitalizeFirstLetter(name)}Entity({ ...input, updatedAt: new Date(), createdAt: new Date(), deletedAt: null });
|
|
11
21
|
|
|
12
22
|
export const SwagggerResponse = {
|
|
13
23
|
create: {
|
|
14
24
|
200: Swagger.defaultResponseJSON({
|
|
15
25
|
status: 200,
|
|
16
|
-
json: { created: true, id: '<uuid>' } as
|
|
26
|
+
json: { created: true, id: '<uuid>' } as ${capitalizeFirstLetter(name)}CreateOutput,
|
|
17
27
|
description: '${name} created.'
|
|
18
28
|
})
|
|
19
29
|
},
|
|
20
30
|
update: {
|
|
21
31
|
200: Swagger.defaultResponseJSON({
|
|
22
32
|
status: 200,
|
|
23
|
-
json:
|
|
33
|
+
json: output as ${capitalizeFirstLetter(name)}UpdateOutput,
|
|
24
34
|
description: '${name} updated.'
|
|
25
35
|
}),
|
|
26
36
|
404: Swagger.defaultResponseError({
|
|
@@ -33,7 +43,7 @@ export const SwagggerResponse = {
|
|
|
33
43
|
getByID: {
|
|
34
44
|
200: Swagger.defaultResponseJSON({
|
|
35
45
|
status: 200,
|
|
36
|
-
json:
|
|
46
|
+
json: output as ${capitalizeFirstLetter(name)}GetByIDOutput,
|
|
37
47
|
description: '${name} found.'
|
|
38
48
|
}),
|
|
39
49
|
404: Swagger.defaultResponseError({
|
|
@@ -46,12 +56,12 @@ export const SwagggerResponse = {
|
|
|
46
56
|
delete: {
|
|
47
57
|
200: Swagger.defaultResponseJSON({
|
|
48
58
|
status: 200,
|
|
49
|
-
json:
|
|
59
|
+
json: output as ${capitalizeFirstLetter(name)}DeleteOutput,
|
|
50
60
|
description: '${name} found.'
|
|
51
61
|
}),
|
|
52
62
|
404: Swagger.defaultResponseError({
|
|
53
63
|
status: 404,
|
|
54
|
-
route: 'api/${pluralize(name)}
|
|
64
|
+
route: 'api/${pluralize(name)}/:id',
|
|
55
65
|
message: '${name}NotFound',
|
|
56
66
|
description: '${name} not found.'
|
|
57
67
|
})
|
|
@@ -59,15 +69,15 @@ export const SwagggerResponse = {
|
|
|
59
69
|
list: {
|
|
60
70
|
200: Swagger.defaultResponseJSON({
|
|
61
71
|
status: 200,
|
|
62
|
-
json: { docs:
|
|
72
|
+
json: { docs: [output], page: 1, limit: 1, total: 1 } as ${capitalizeFirstLetter(name)}ListOutput,
|
|
63
73
|
description: '${name} created.'
|
|
64
74
|
})
|
|
65
75
|
}
|
|
66
76
|
};
|
|
67
77
|
|
|
68
78
|
export const SwagggerRequest = {
|
|
69
|
-
createBody: Swagger.defaultRequestJSON({ ...
|
|
70
|
-
updateBody: Swagger.defaultRequestJSON({ ...
|
|
79
|
+
createBody: Swagger.defaultRequestJSON({ ...input, id: undefined } as ${capitalizeFirstLetter(name)}Entity),
|
|
80
|
+
updateBody: Swagger.defaultRequestJSON({ ...input, id: '<id>' } as ${capitalizeFirstLetter(name)}Entity),
|
|
71
81
|
listQuery: {
|
|
72
82
|
pagination: {
|
|
73
83
|
limit: Swagger.defaultApiQueryOptions({ example: 10, name: 'limit', required: false }),
|
|
@@ -8,10 +8,17 @@ const getCoreUsecaseCreateTest = (name) => `import { Test } from '@nestjs/testin
|
|
|
8
8
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}CreateAdapter } from '@/modules/${name}/adapter';
|
|
10
10
|
import { ApiInternalServerException } from '@/utils/exception';
|
|
11
|
-
import { expectZodError } from '@/utils/tests/tests'
|
|
11
|
+
import { expectZodError, generateUUID } from '@/utils/tests/tests';
|
|
12
12
|
|
|
13
|
+
import { ${capitalizeFirstLetter(name)}Entity } from '../../entity/${name}';
|
|
13
14
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
14
|
-
import { ${capitalizeFirstLetter(name)}CreateUsecase } from '../${name}-create';
|
|
15
|
+
import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput, ${capitalizeFirstLetter(name)}CreateUsecase } from '../${name}-create';
|
|
16
|
+
|
|
17
|
+
const successInput: ${capitalizeFirstLetter(name)}CreateInput = {
|
|
18
|
+
name: 'dummy'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const failureInput: ${capitalizeFirstLetter(name)}CreateInput = {};
|
|
15
22
|
|
|
16
23
|
describe('${capitalizeFirstLetter(name)}CreateUsecase', () => {
|
|
17
24
|
let usecase: I${capitalizeFirstLetter(name)}CreateAdapter;
|
|
@@ -44,32 +51,34 @@ describe('${capitalizeFirstLetter(name)}CreateUsecase', () => {
|
|
|
44
51
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
45
52
|
});
|
|
46
53
|
|
|
47
|
-
test('
|
|
54
|
+
test('when no input is specified, should expect an error', async () => {
|
|
48
55
|
await expectZodError(
|
|
49
|
-
() => usecase.execute(
|
|
56
|
+
() => usecase.execute(failureInput),
|
|
50
57
|
(issues) => {
|
|
51
|
-
expect(issues).toEqual([{ message: 'Required', path: 'name' }]);
|
|
58
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof('name') }]);
|
|
52
59
|
}
|
|
53
60
|
);
|
|
54
61
|
});
|
|
55
62
|
|
|
56
|
-
test('should ${name}
|
|
57
|
-
const ${name} = {
|
|
58
|
-
|
|
63
|
+
test('when ${name} created successfully, should expect a ${name} that has been created', async () => {
|
|
64
|
+
const createOutput: ${capitalizeFirstLetter(name)}CreateOutput = { created: true, id: generateUUID() };
|
|
65
|
+
|
|
66
|
+
repository.create = jest.fn().mockResolvedValue(createOutput);
|
|
59
67
|
repository.startSession = jest.fn().mockResolvedValue({
|
|
60
68
|
commit: jest.fn()
|
|
61
69
|
});
|
|
62
|
-
|
|
70
|
+
|
|
71
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(createOutput);
|
|
63
72
|
});
|
|
64
73
|
|
|
65
|
-
test('
|
|
66
|
-
const ${name} = { name: 'dummy' };
|
|
67
|
-
repository.create = jest.fn().mockRejectedValue(new ApiInternalServerException('error'));
|
|
74
|
+
test('when transaction throw an error, should expect an error', async () => {
|
|
68
75
|
repository.startSession = jest.fn().mockResolvedValue({
|
|
69
76
|
commit: jest.fn(),
|
|
70
77
|
rollback: jest.fn()
|
|
71
78
|
});
|
|
72
|
-
|
|
79
|
+
repository.create = jest.fn().mockRejectedValue(new ApiInternalServerException());
|
|
80
|
+
|
|
81
|
+
await expect(usecase.execute(successInput)).rejects.toThrow(ApiInternalServerException);
|
|
73
82
|
});
|
|
74
83
|
});
|
|
75
84
|
`
|
|
@@ -5,18 +5,19 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseDeleteTest = (name) => `import { Test } from '@nestjs/testing';
|
|
7
7
|
|
|
8
|
-
import { ${capitalizeFirstLetter(name)}DeleteUsecase } from '@/core/${name}/use-cases/${name}-delete';
|
|
8
|
+
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput, ${capitalizeFirstLetter(name)}DeleteUsecase } from '@/core/${name}/use-cases/${name}-delete';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}DeleteAdapter } from '@/modules/${name}/adapter';
|
|
10
10
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
11
|
-
import { expectZodError, generateUUID } from '@/utils/tests/tests'
|
|
11
|
+
import { expectZodError, generateUUID } from '@/utils/tests/tests';
|
|
12
12
|
|
|
13
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
14
14
|
import { ${capitalizeFirstLetter(name)}Entity } from './../../entity/${name}';
|
|
15
15
|
|
|
16
|
-
const ${name}
|
|
17
|
-
id: generateUUID()
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const successInput: ${capitalizeFirstLetter(name)}DeleteInput = {
|
|
17
|
+
id: generateUUID()
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const failureInput: ${capitalizeFirstLetter(name)}DeleteInput = {};
|
|
20
21
|
|
|
21
22
|
describe('${capitalizeFirstLetter(name)}DeleteUsecase', () => {
|
|
22
23
|
let usecase: I${capitalizeFirstLetter(name)}DeleteAdapter;
|
|
@@ -43,25 +44,32 @@ describe('${capitalizeFirstLetter(name)}DeleteUsecase', () => {
|
|
|
43
44
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
test('
|
|
47
|
+
test('when no input is specified, should expect an error', async () => {
|
|
47
48
|
await expectZodError(
|
|
48
|
-
() => usecase.execute(
|
|
49
|
+
() => usecase.execute(failureInput),
|
|
49
50
|
(issues) => {
|
|
50
|
-
expect(issues).toEqual([{ message: 'Required', path: 'id' }]);
|
|
51
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof('id') }]);
|
|
51
52
|
}
|
|
52
53
|
);
|
|
53
54
|
});
|
|
54
55
|
|
|
55
|
-
test('
|
|
56
|
+
test('when ${name} not found, should expect an error', async () => {
|
|
56
57
|
repository.findById = jest.fn().mockResolvedValue(null);
|
|
57
|
-
|
|
58
|
+
|
|
59
|
+
await expect(usecase.execute(successInput)).rejects.toThrowError(ApiNotFoundException);
|
|
58
60
|
});
|
|
59
61
|
|
|
60
|
-
test('should
|
|
61
|
-
|
|
62
|
+
test('when ${name} deleted successfully, should expect a ${name} that has been deleted', async () => {
|
|
63
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}DeleteOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
64
|
+
id: generateUUID(),
|
|
65
|
+
name: 'dummy'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
repository.findById = jest.fn().mockResolvedValue(findByIdOutput);
|
|
62
69
|
repository.updateOne = jest.fn();
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
|
|
71
|
+
await expect(usecase.execute(successInput)).resolves.toEqual({
|
|
72
|
+
...findByIdOutput,
|
|
65
73
|
deletedAt: expect.any(Date)
|
|
66
74
|
});
|
|
67
75
|
});
|
|
@@ -7,16 +7,17 @@ const getCoreUsecaseGetByIDTest = (name) => `import { Test } from '@nestjs/testi
|
|
|
7
7
|
|
|
8
8
|
import { I${capitalizeFirstLetter(name)}GetByIDAdapter } from '@/modules/${name}/adapter';
|
|
9
9
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
10
|
-
import { expectZodError, generateUUID } from '@/utils/tests/tests'
|
|
10
|
+
import { expectZodError, generateUUID } from '@/utils/tests/tests';
|
|
11
11
|
|
|
12
12
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
13
|
-
import { ${capitalizeFirstLetter(name)}GetByIdUsecase } from '../${name}-getByID';
|
|
13
|
+
import { ${capitalizeFirstLetter(name)}GetByIDInput, ${capitalizeFirstLetter(name)}GetByIDOutput, ${capitalizeFirstLetter(name)}GetByIdUsecase } from '../${name}-getByID';
|
|
14
14
|
import { ${capitalizeFirstLetter(name)}Entity } from './../../entity/${name}';
|
|
15
15
|
|
|
16
|
-
const ${name}
|
|
17
|
-
id: generateUUID()
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const successInput: ${capitalizeFirstLetter(name)}GetByIDInput = {
|
|
17
|
+
id: generateUUID()
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const failureInput: ${capitalizeFirstLetter(name)}GetByIDInput = {};
|
|
20
21
|
|
|
21
22
|
describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
22
23
|
let usecase: I${capitalizeFirstLetter(name)}GetByIDAdapter;
|
|
@@ -43,23 +44,29 @@ describe('${capitalizeFirstLetter(name)}GetByIdUsecase', () => {
|
|
|
43
44
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
test('
|
|
47
|
+
test('when no input is specified, should expect an error', async () => {
|
|
47
48
|
await expectZodError(
|
|
48
|
-
() => usecase.execute(
|
|
49
|
+
() => usecase.execute(failureInput),
|
|
49
50
|
(issues) => {
|
|
50
|
-
expect(issues).toEqual([{ message: 'Required', path: 'id' }]);
|
|
51
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof('id') }]);
|
|
51
52
|
}
|
|
52
53
|
);
|
|
53
54
|
});
|
|
54
55
|
|
|
55
|
-
test('
|
|
56
|
+
test('when ${name} not found, should expect an error', async () => {
|
|
56
57
|
repository.findById = jest.fn().mockResolvedValue(null);
|
|
57
|
-
|
|
58
|
+
|
|
59
|
+
await expect(usecase.execute(successInput)).rejects.toThrowError(ApiNotFoundException);
|
|
58
60
|
});
|
|
59
61
|
|
|
60
|
-
test('should
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
test('when ${name} found, should expect a ${name} that has been found', async () => {
|
|
63
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}GetByIDOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
64
|
+
id: generateUUID(),
|
|
65
|
+
name: 'dummy'
|
|
66
|
+
});
|
|
67
|
+
repository.findById = jest.fn().mockResolvedValue(findByIdOutput);
|
|
68
|
+
|
|
69
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(findByIdOutput);
|
|
63
70
|
});
|
|
64
71
|
});
|
|
65
72
|
`
|
|
@@ -5,19 +5,16 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseListTest = (name) => `import { Test } from '@nestjs/testing';
|
|
7
7
|
|
|
8
|
-
import { ${capitalizeFirstLetter(name)}ListUsecase } from '@/core/${name}/use-cases/${name}-list';
|
|
8
|
+
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput, ${capitalizeFirstLetter(name)}ListUsecase } from '@/core/${name}/use-cases/${name}-list';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}ListAdapter } from '@/modules/${name}/adapter';
|
|
10
|
-
import { expectZodError, generateUUID } from '@/utils/tests/tests'
|
|
10
|
+
import { expectZodError, generateUUID } from '@/utils/tests/tests';
|
|
11
11
|
|
|
12
12
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}Entity } from './../../entity/${name}';
|
|
14
14
|
|
|
15
|
-
const ${name}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
createdAt: new Date(),
|
|
19
|
-
updatedAt: new Date()
|
|
20
|
-
} as ${capitalizeFirstLetter(name)}Entity;
|
|
15
|
+
const successInput: ${capitalizeFirstLetter(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } };
|
|
16
|
+
|
|
17
|
+
const failureInput: ${capitalizeFirstLetter(name)}ListInput = { search: null, sort: null, limit: 10, page: 1 };
|
|
21
18
|
|
|
22
19
|
describe('${capitalizeFirstLetter(name)}ListUsecase', () => {
|
|
23
20
|
let usecase: I${capitalizeFirstLetter(name)}ListAdapter;
|
|
@@ -44,32 +41,41 @@ describe('${capitalizeFirstLetter(name)}ListUsecase', () => {
|
|
|
44
41
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
45
42
|
});
|
|
46
43
|
|
|
47
|
-
test('
|
|
44
|
+
test('when sort input is specified, should expect an error', async () => {
|
|
48
45
|
await expectZodError(
|
|
49
|
-
() => usecase.execute(
|
|
46
|
+
() => usecase.execute(failureInput),
|
|
50
47
|
(issues) => {
|
|
51
48
|
expect(issues).toEqual([{ message: 'Expected object, received null', path: 'sort' }]);
|
|
52
49
|
}
|
|
53
50
|
);
|
|
54
51
|
});
|
|
55
52
|
|
|
56
|
-
test('should list
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
test('when ${name} are found, should expect an ${name} list', async () => {
|
|
54
|
+
const doc = new ${capitalizeFirstLetter(name)}Entity({
|
|
55
|
+
id: generateUUID(),
|
|
56
|
+
name: 'dummy',
|
|
57
|
+
createdAt: new Date(),
|
|
58
|
+
updatedAt: new Date()
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const paginateOutput: ${capitalizeFirstLetter(name)}ListOutput = { docs: [doc], page: 1, limit: 1, total: 1 };
|
|
62
|
+
|
|
63
|
+
repository.paginate = jest.fn().mockResolvedValue(paginateOutput);
|
|
64
|
+
|
|
65
|
+
await expect(usecase.execute(successInput)).resolves.toEqual({
|
|
66
|
+
docs: [doc],
|
|
61
67
|
page: 1,
|
|
62
68
|
limit: 1,
|
|
63
69
|
total: 1
|
|
64
70
|
});
|
|
65
71
|
});
|
|
66
72
|
|
|
67
|
-
test('
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
73
|
+
test('when ${name} not found, should expect an empty list', async () => {
|
|
74
|
+
const paginateOutput: ${capitalizeFirstLetter(name)}ListOutput = { docs: [], page: 1, limit: 1, total: 1 };
|
|
75
|
+
|
|
76
|
+
repository.paginate = jest.fn().mockResolvedValue(paginateOutput);
|
|
77
|
+
|
|
78
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(paginateOutput);
|
|
73
79
|
});
|
|
74
80
|
});
|
|
75
81
|
`
|
|
@@ -8,16 +8,17 @@ const getCoreUsecaseUpdateTest = (name) => `import { Test } from '@nestjs/testin
|
|
|
8
8
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}UpdateAdapter } from '@/modules/${name}/adapter';
|
|
10
10
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
11
|
-
import { expectZodError, generateUUID } from '@/utils/tests/tests'
|
|
11
|
+
import { expectZodError, generateUUID } from '@/utils/tests/tests';
|
|
12
12
|
|
|
13
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
14
|
-
import { ${capitalizeFirstLetter(name)}UpdateUsecase } from '../${name}-update';
|
|
14
|
+
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput, ${capitalizeFirstLetter(name)}UpdateUsecase } from '../${name}-update';
|
|
15
15
|
import { ${capitalizeFirstLetter(name)}Entity } from './../../entity/${name}';
|
|
16
16
|
|
|
17
|
-
const ${name}
|
|
18
|
-
id: generateUUID()
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const successInput: ${capitalizeFirstLetter(name)}UpdateInput = {
|
|
18
|
+
id: generateUUID()
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const failureInput: ${capitalizeFirstLetter(name)}UpdateInput = {};
|
|
21
22
|
|
|
22
23
|
describe('${capitalizeFirstLetter(name)}UpdateUsecase', () => {
|
|
23
24
|
let usecase: I${capitalizeFirstLetter(name)}UpdateAdapter;
|
|
@@ -50,24 +51,31 @@ describe('${capitalizeFirstLetter(name)}UpdateUsecase', () => {
|
|
|
50
51
|
repository = app.get(I${capitalizeFirstLetter(name)}Repository);
|
|
51
52
|
});
|
|
52
53
|
|
|
53
|
-
test('
|
|
54
|
+
test('when no input is specified, should expect an error', async () => {
|
|
54
55
|
await expectZodError(
|
|
55
|
-
() => usecase.execute(
|
|
56
|
+
() => usecase.execute(failureInput),
|
|
56
57
|
(issues) => {
|
|
57
|
-
expect(issues).toEqual([{ message: 'Required', path: 'id' }]);
|
|
58
|
+
expect(issues).toEqual([{ message: 'Required', path: ${capitalizeFirstLetter(name)}Entity.nameof('id') }]);
|
|
58
59
|
}
|
|
59
60
|
);
|
|
60
61
|
});
|
|
61
62
|
|
|
62
|
-
test('
|
|
63
|
+
test('when ${name} not found, should expect an error', async () => {
|
|
63
64
|
repository.findById = jest.fn().mockResolvedValue(null);
|
|
64
|
-
|
|
65
|
+
|
|
66
|
+
await expect(usecase.execute(successInput)).rejects.toThrowError(ApiNotFoundException);
|
|
65
67
|
});
|
|
66
68
|
|
|
67
|
-
test('should
|
|
68
|
-
|
|
69
|
+
test('when ${name} updated successfully, should expect an ${name} that has been updated', async () => {
|
|
70
|
+
const findByIdOutput: ${capitalizeFirstLetter(name)}UpdateOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
71
|
+
id: generateUUID(),
|
|
72
|
+
name: 'dummy'
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
repository.findById = jest.fn().mockResolvedValue(findByIdOutput);
|
|
69
76
|
repository.updateOne = jest.fn().mockResolvedValue(null);
|
|
70
|
-
|
|
77
|
+
|
|
78
|
+
await expect(usecase.execute(successInput)).resolves.toEqual(findByIdOutput);
|
|
71
79
|
});
|
|
72
80
|
});
|
|
73
81
|
`
|
|
@@ -18,7 +18,7 @@ export const ${capitalizeFirstLetter(name)}CreateSchema = ${capitalizeFirstLette
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export type ${capitalizeFirstLetter(name)}CreateInput = z.infer<typeof ${capitalizeFirstLetter(name)}CreateSchema>;
|
|
21
|
-
export type ${capitalizeFirstLetter(name)}CreateOutput =
|
|
21
|
+
export type ${capitalizeFirstLetter(name)}CreateOutput = CreatedModel;
|
|
22
22
|
|
|
23
23
|
export class ${capitalizeFirstLetter(name)}CreateUsecase {
|
|
24
24
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerServide: ILoggerAdapter) {}
|
|
@@ -17,7 +17,7 @@ export const ${capitalizeFirstLetter(name)}DeleteSchema = ${capitalizeFirstLette
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
export type ${capitalizeFirstLetter(name)}DeleteInput = z.infer<typeof ${capitalizeFirstLetter(name)}DeleteSchema>;
|
|
20
|
-
export type ${capitalizeFirstLetter(name)}DeleteOutput =
|
|
20
|
+
export type ${capitalizeFirstLetter(name)}DeleteOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
21
21
|
|
|
22
22
|
export class ${capitalizeFirstLetter(name)}DeleteUsecase {
|
|
23
23
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
@@ -18,7 +18,7 @@ export const ${capitalizeFirstLetter(name)}GetByIdSchema = ${capitalizeFirstLett
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export type ${capitalizeFirstLetter(name)}GetByIDInput = z.infer<typeof ${capitalizeFirstLetter(name)}GetByIdSchema>;
|
|
21
|
-
export type ${capitalizeFirstLetter(name)}GetByIDOutput =
|
|
21
|
+
export type ${capitalizeFirstLetter(name)}GetByIDOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
22
22
|
|
|
23
23
|
export class ${capitalizeFirstLetter(name)}GetByIdUsecase {
|
|
24
24
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
@@ -16,7 +16,7 @@ import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}
|
|
|
16
16
|
export const ${capitalizeFirstLetter(name)}ListSchema = z.intersection(PaginationSchema, SortSchema.merge(SearchSchema));
|
|
17
17
|
|
|
18
18
|
export type ${capitalizeFirstLetter(name)}ListInput = PaginationInput<${capitalizeFirstLetter(name)}Entity>;
|
|
19
|
-
export type ${capitalizeFirstLetter(name)}ListOutput =
|
|
19
|
+
export type ${capitalizeFirstLetter(name)}ListOutput = PaginationOutput<${capitalizeFirstLetter(name)}Entity>;
|
|
20
20
|
|
|
21
21
|
export class ${capitalizeFirstLetter(name)}ListUsecase {
|
|
22
22
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
@@ -18,7 +18,7 @@ export const ${capitalizeFirstLetter(name)}UpdateSchema = ${capitalizeFirstLette
|
|
|
18
18
|
}).merge(${capitalizeFirstLetter(name)}EntitySchema.omit({ id: true }).partial());
|
|
19
19
|
|
|
20
20
|
export type ${capitalizeFirstLetter(name)}UpdateInput = z.infer<typeof ${capitalizeFirstLetter(name)}UpdateSchema>;
|
|
21
|
-
export type ${capitalizeFirstLetter(name)}UpdateOutput =
|
|
21
|
+
export type ${capitalizeFirstLetter(name)}UpdateOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
22
22
|
|
|
23
23
|
export class ${capitalizeFirstLetter(name)}UpdateUsecase {
|
|
24
24
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerServide: ILoggerAdapter) {}
|
|
@@ -27,8 +27,8 @@ import {
|
|
|
27
27
|
} from './adapter';
|
|
28
28
|
import { SwagggerRequest, SwagggerResponse } from './swagger';
|
|
29
29
|
|
|
30
|
-
@Controller()
|
|
31
|
-
@ApiTags('${name}')
|
|
30
|
+
@Controller('${pluralize(name)}')
|
|
31
|
+
@ApiTags('${pluralize(name)}')
|
|
32
32
|
@ApiBearerAuth()
|
|
33
33
|
@Roles(UserRole.USER)
|
|
34
34
|
export class ${capitalizeFirstLetter(name)}Controller {
|
|
@@ -40,36 +40,36 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
40
40
|
private readonly ${name}Delete: I${capitalizeFirstLetter(name)}DeleteAdapter
|
|
41
41
|
) {}
|
|
42
42
|
|
|
43
|
-
@Post(
|
|
43
|
+
@Post()
|
|
44
44
|
@ApiResponse(SwagggerResponse.create[200])
|
|
45
45
|
@ApiBody(SwagggerRequest.createBody)
|
|
46
|
-
async create(@Req() { body }: ApiRequest):
|
|
46
|
+
async create(@Req() { body }: ApiRequest): Promise<${capitalizeFirstLetter(name)}CreateOutput> {
|
|
47
47
|
return await this.${name}Create.execute(body as ${capitalizeFirstLetter(name)}CreateInput);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
@Put(
|
|
50
|
+
@Put()
|
|
51
51
|
@ApiResponse(SwagggerResponse.update[200])
|
|
52
52
|
@ApiResponse(SwagggerResponse.update[404])
|
|
53
53
|
@ApiBody(SwagggerRequest.updateBody)
|
|
54
|
-
async update(@Req() { body }: ApiRequest):
|
|
54
|
+
async update(@Req() { body }: ApiRequest): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
|
|
55
55
|
return await this.${name}Update.execute(body as ${capitalizeFirstLetter(name)}UpdateInput);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
@Get('
|
|
58
|
+
@Get('/:id')
|
|
59
59
|
@ApiParam({ name: 'id', required: true })
|
|
60
60
|
@ApiResponse(SwagggerResponse.getByID[200])
|
|
61
61
|
@ApiResponse(SwagggerResponse.getByID[404])
|
|
62
|
-
async getById(@Req() { params }: ApiRequest):
|
|
62
|
+
async getById(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}GetByIDOutput> {
|
|
63
63
|
return await this.${name}GetByID.execute(params as ${capitalizeFirstLetter(name)}GetByIDInput);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
@Get(
|
|
66
|
+
@Get()
|
|
67
67
|
@ApiQuery(SwagggerRequest.listQuery.pagination.limit)
|
|
68
68
|
@ApiQuery(SwagggerRequest.listQuery.pagination.page)
|
|
69
69
|
@ApiQuery(SwagggerRequest.listQuery.sort)
|
|
70
70
|
@ApiQuery(SwagggerRequest.listQuery.search)
|
|
71
71
|
@ApiResponse(SwagggerResponse.list[200])
|
|
72
|
-
async list(@Req() { query }: ApiRequest):
|
|
72
|
+
async list(@Req() { query }: ApiRequest): Promise<${capitalizeFirstLetter(name)}ListOutput> {
|
|
73
73
|
const input: ${capitalizeFirstLetter(name)}ListInput = {
|
|
74
74
|
sort: SortHttpSchema.parse(query.sort),
|
|
75
75
|
search: SearchHttpSchema.parse(query.search),
|
|
@@ -80,11 +80,11 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
80
80
|
return await this.${name}List.execute(input);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
@Delete('
|
|
83
|
+
@Delete('/:id')
|
|
84
84
|
@ApiParam({ name: 'id', required: true })
|
|
85
85
|
@ApiResponse(SwagggerResponse.delete[200])
|
|
86
86
|
@ApiResponse(SwagggerResponse.delete[404])
|
|
87
|
-
async delete(@Req() { params }: ApiRequest):
|
|
87
|
+
async delete(@Req() { params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}DeleteOutput> {
|
|
88
88
|
return await this.${name}Delete.execute(params as ${capitalizeFirstLetter(name)}DeleteInput);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
const pluralize = require('pluralize')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function capitalizeFirstLetter(string) {
|
|
4
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const getModuleSwagger = (name) => `import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
9
|
+
import { ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
10
|
+
import { ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
11
|
+
import { ${capitalizeFirstLetter(name)}GetByIDOutput } from '@/core/${name}/use-cases/${name}-getByID';
|
|
12
|
+
import { ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
13
|
+
import { ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
4
14
|
import { Swagger } from '@/utils/docs/swagger';
|
|
5
15
|
|
|
6
|
-
const
|
|
16
|
+
const input = new ${capitalizeFirstLetter(name)}Entity({
|
|
7
17
|
name: '<name>'
|
|
8
|
-
};
|
|
18
|
+
});
|
|
9
19
|
|
|
10
|
-
const
|
|
20
|
+
const output = new ${capitalizeFirstLetter(name)}Entity({ ...input, updatedAt: new Date(), createdAt: new Date(), deletedAt: null });
|
|
11
21
|
|
|
12
22
|
export const SwagggerResponse = {
|
|
13
23
|
create: {
|
|
14
24
|
200: Swagger.defaultResponseJSON({
|
|
15
25
|
status: 200,
|
|
16
|
-
json: { created: true, id: '<uuid>' } as
|
|
26
|
+
json: { created: true, id: '<uuid>' } as ${capitalizeFirstLetter(name)}CreateOutput,
|
|
17
27
|
description: '${name} created.'
|
|
18
28
|
})
|
|
19
29
|
},
|
|
20
30
|
update: {
|
|
21
31
|
200: Swagger.defaultResponseJSON({
|
|
22
32
|
status: 200,
|
|
23
|
-
json:
|
|
33
|
+
json: output as ${capitalizeFirstLetter(name)}UpdateOutput,
|
|
24
34
|
description: '${name} updated.'
|
|
25
35
|
}),
|
|
26
36
|
404: Swagger.defaultResponseError({
|
|
@@ -33,7 +43,7 @@ export const SwagggerResponse = {
|
|
|
33
43
|
getByID: {
|
|
34
44
|
200: Swagger.defaultResponseJSON({
|
|
35
45
|
status: 200,
|
|
36
|
-
json:
|
|
46
|
+
json: output as ${capitalizeFirstLetter(name)}GetByIDOutput,
|
|
37
47
|
description: '${name} found.'
|
|
38
48
|
}),
|
|
39
49
|
404: Swagger.defaultResponseError({
|
|
@@ -46,12 +56,12 @@ export const SwagggerResponse = {
|
|
|
46
56
|
delete: {
|
|
47
57
|
200: Swagger.defaultResponseJSON({
|
|
48
58
|
status: 200,
|
|
49
|
-
json:
|
|
59
|
+
json: output as ${capitalizeFirstLetter(name)}DeleteOutput,
|
|
50
60
|
description: '${name} found.'
|
|
51
61
|
}),
|
|
52
62
|
404: Swagger.defaultResponseError({
|
|
53
63
|
status: 404,
|
|
54
|
-
route: 'api/${pluralize(name)}
|
|
64
|
+
route: 'api/${pluralize(name)}/:id',
|
|
55
65
|
message: '${name}NotFound',
|
|
56
66
|
description: '${name} not found.'
|
|
57
67
|
})
|
|
@@ -59,15 +69,15 @@ export const SwagggerResponse = {
|
|
|
59
69
|
list: {
|
|
60
70
|
200: Swagger.defaultResponseJSON({
|
|
61
71
|
status: 200,
|
|
62
|
-
json: { docs:
|
|
72
|
+
json: { docs: [output], page: 1, limit: 1, total: 1 } as ${capitalizeFirstLetter(name)}ListOutput,
|
|
63
73
|
description: '${name} created.'
|
|
64
74
|
})
|
|
65
75
|
}
|
|
66
76
|
};
|
|
67
77
|
|
|
68
78
|
export const SwagggerRequest = {
|
|
69
|
-
createBody: Swagger.defaultRequestJSON({ ...
|
|
70
|
-
updateBody: Swagger.defaultRequestJSON({ ...
|
|
79
|
+
createBody: Swagger.defaultRequestJSON({ ...input, id: undefined } as ${capitalizeFirstLetter(name)}Entity),
|
|
80
|
+
updateBody: Swagger.defaultRequestJSON({ ...input, id: '<id>' } as ${capitalizeFirstLetter(name)}Entity),
|
|
71
81
|
listQuery: {
|
|
72
82
|
pagination: {
|
|
73
83
|
limit: Swagger.defaultApiQueryOptions({ example: 10, name: 'limit', required: false }),
|