@mikemajesty/microservice-crud 6.0.14 → 6.0.16
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 +1 -1
- package/src/templates/infra/adapter.js +4 -7
- package/src/templates/infra/module.js +7 -10
- package/src/templates/infra/service.js +6 -9
- package/src/templates/libs/adapter.js +4 -7
- package/src/templates/libs/module.js +7 -10
- package/src/templates/libs/service.js +8 -11
- package/src/templates/module/controller.js +2 -5
- package/src/templates/module/module.js +4 -6
- package/src/templates/mongo/core/entity/entity.js +5 -8
- package/src/templates/mongo/core/repository/repository.js +5 -8
- package/src/templates/mongo/core/use-cases/__tests__/create.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/__tests__/delete.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/__tests__/get-by-id.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/__tests__/list.spec.js +20 -23
- package/src/templates/mongo/core/use-cases/__tests__/update.spec.js +19 -22
- package/src/templates/mongo/core/use-cases/create.js +11 -14
- package/src/templates/mongo/core/use-cases/delete.js +11 -14
- package/src/templates/mongo/core/use-cases/get-by-id.js +11 -14
- package/src/templates/mongo/core/use-cases/list.js +11 -14
- package/src/templates/mongo/core/use-cases/update.js +14 -17
- package/src/templates/mongo/modules/adapter.js +16 -19
- package/src/templates/mongo/modules/controller.js +27 -30
- package/src/templates/mongo/modules/module.js +52 -54
- package/src/templates/mongo/modules/repository.js +7 -10
- package/src/templates/mongo/modules/swagger.js +16 -19
- package/src/templates/mongo/schemas/schema.js +9 -12
- package/src/templates/postgres/core/entity/entity.js +5 -8
- package/src/templates/postgres/core/repository/repository.js +5 -8
- package/src/templates/postgres/core/use-cases/__tests__/create.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/__tests__/delete.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/__tests__/get-by-id.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/__tests__/list.spec.js +20 -23
- package/src/templates/postgres/core/use-cases/__tests__/update.spec.js +19 -22
- package/src/templates/postgres/core/use-cases/create.js +11 -14
- package/src/templates/postgres/core/use-cases/delete.js +11 -14
- package/src/templates/postgres/core/use-cases/get-by-id.js +12 -15
- package/src/templates/postgres/core/use-cases/list.js +10 -13
- package/src/templates/postgres/core/use-cases/update.js +14 -17
- package/src/templates/postgres/modules/adapter.js +16 -19
- package/src/templates/postgres/modules/controller.js +27 -30
- package/src/templates/postgres/modules/module.js +40 -43
- package/src/templates/postgres/modules/repository.js +10 -13
- package/src/templates/postgres/modules/swagger.js +16 -20
- package/src/templates/postgres/schemas/schema.js +2 -5
- package/src/textUtils.js +9 -0
|
@@ -1,56 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
function capitalizeFirstLetter(string) {
|
|
3
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
|
-
}
|
|
1
|
+
const { dashToPascal } = require("../../../../../textUtils")
|
|
5
2
|
|
|
6
3
|
const getCoreUsecaseUpdateTest = (name) => `import { Test } from '@nestjs/testing';
|
|
7
4
|
import { ZodIssue } from 'zod';
|
|
8
5
|
|
|
9
6
|
import { ILoggerAdapter, LoggerModule } from '@/infra/logger';
|
|
10
|
-
import { I${
|
|
7
|
+
import { I${dashToPascal(name)}UpdateAdapter } from '@/modules/${name}/adapter';
|
|
11
8
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
12
9
|
import { TestUtils } from '@/utils/tests';
|
|
13
10
|
|
|
14
|
-
import { ${
|
|
15
|
-
import { I${
|
|
16
|
-
import { ${
|
|
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';
|
|
17
14
|
|
|
18
|
-
describe(${
|
|
19
|
-
let usecase: I${
|
|
20
|
-
let repository: I${
|
|
15
|
+
describe(${dashToPascal(name)}UpdateUsecase.name, () => {
|
|
16
|
+
let usecase: I${dashToPascal(name)}UpdateAdapter;
|
|
17
|
+
let repository: I${dashToPascal(name)}Repository;
|
|
21
18
|
|
|
22
19
|
beforeEach(async () => {
|
|
23
20
|
const app = await Test.createTestingModule({
|
|
24
21
|
imports: [LoggerModule],
|
|
25
22
|
providers: [
|
|
26
23
|
{
|
|
27
|
-
provide: I${
|
|
24
|
+
provide: I${dashToPascal(name)}Repository,
|
|
28
25
|
useValue: {}
|
|
29
26
|
},
|
|
30
27
|
{
|
|
31
|
-
provide: I${
|
|
32
|
-
useFactory: (${name}Repository: I${
|
|
33
|
-
return new ${
|
|
28
|
+
provide: I${dashToPascal(name)}UpdateAdapter,
|
|
29
|
+
useFactory: (${name}Repository: I${dashToPascal(name)}Repository, logger: ILoggerAdapter) => {
|
|
30
|
+
return new ${dashToPascal(name)}UpdateUsecase(${name}Repository, logger);
|
|
34
31
|
},
|
|
35
|
-
inject: [I${
|
|
32
|
+
inject: [I${dashToPascal(name)}Repository, ILoggerAdapter]
|
|
36
33
|
}
|
|
37
34
|
]
|
|
38
35
|
}).compile();
|
|
39
36
|
|
|
40
|
-
usecase = app.get(I${
|
|
41
|
-
repository = app.get(I${
|
|
37
|
+
usecase = app.get(I${dashToPascal(name)}UpdateAdapter);
|
|
38
|
+
repository = app.get(I${dashToPascal(name)}Repository);
|
|
42
39
|
});
|
|
43
40
|
|
|
44
41
|
test('when no input is specified, should expect an error', async () => {
|
|
45
42
|
await TestUtils.expectZodError(
|
|
46
|
-
() => usecase.execute({} as ${
|
|
43
|
+
() => usecase.execute({} as ${dashToPascal(name)}UpdateInput),
|
|
47
44
|
(issues: ZodIssue[]) => {
|
|
48
|
-
expect(issues).toEqual([{ message: 'Required', path: ${
|
|
45
|
+
expect(issues).toEqual([{ message: 'Required', path: ${dashToPascal(name)}Entity.nameOf('id') }]);
|
|
49
46
|
}
|
|
50
47
|
);
|
|
51
48
|
});
|
|
52
49
|
|
|
53
|
-
const input: ${
|
|
50
|
+
const input: ${dashToPascal(name)}UpdateInput = {
|
|
54
51
|
id: TestUtils.getMockUUID()
|
|
55
52
|
};
|
|
56
53
|
|
|
@@ -60,7 +57,7 @@ describe(${capitalizeFirstLetter(name)}UpdateUsecase.name, () => {
|
|
|
60
57
|
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
61
58
|
});
|
|
62
59
|
|
|
63
|
-
const ${name}: ${
|
|
60
|
+
const ${name}: ${dashToPascal(name)}UpdateOutput = new ${dashToPascal(name)}Entity({
|
|
64
61
|
id: TestUtils.getMockUUID(),
|
|
65
62
|
name: 'dummy'
|
|
66
63
|
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function capitalizeFirstLetter(string) {
|
|
3
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
|
-
}
|
|
1
|
+
const { dashToPascal } = require("../../../../textUtils")
|
|
5
2
|
|
|
6
3
|
const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
|
|
7
4
|
|
|
@@ -11,25 +8,25 @@ import { ValidateSchema } from '@/utils/decorators';
|
|
|
11
8
|
import { IUsecase } from '@/utils/usecase';
|
|
12
9
|
import { UUIDUtils } from '@/utils/uuid';
|
|
13
10
|
|
|
14
|
-
import { ${
|
|
15
|
-
import { I${
|
|
11
|
+
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
12
|
+
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
16
13
|
|
|
17
|
-
export const ${
|
|
14
|
+
export const ${dashToPascal(name)}CreateSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
18
15
|
name: true
|
|
19
16
|
});
|
|
20
17
|
|
|
21
|
-
export type ${
|
|
22
|
-
export type ${
|
|
18
|
+
export type ${dashToPascal(name)}CreateInput = z.infer<typeof ${dashToPascal(name)}CreateSchema>;
|
|
19
|
+
export type ${dashToPascal(name)}CreateOutput = CreatedModel;
|
|
23
20
|
|
|
24
|
-
export class ${
|
|
21
|
+
export class ${dashToPascal(name)}CreateUsecase implements IUsecase {
|
|
25
22
|
constructor(
|
|
26
|
-
private readonly ${name}Repository: I${
|
|
23
|
+
private readonly ${name}Repository: I${dashToPascal(name)}Repository,
|
|
27
24
|
private readonly loggerService: ILoggerAdapter
|
|
28
25
|
) {}
|
|
29
26
|
|
|
30
|
-
@ValidateSchema(${
|
|
31
|
-
async execute(input: ${
|
|
32
|
-
const entity = new ${
|
|
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 });
|
|
33
30
|
|
|
34
31
|
const ${name} = await this.${name}Repository.create(entity);
|
|
35
32
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function capitalizeFirstLetter(string) {
|
|
3
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
|
-
}
|
|
1
|
+
const { dashToPascal } = require("../../../../textUtils")
|
|
5
2
|
|
|
6
3
|
const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
|
|
7
4
|
|
|
@@ -9,28 +6,28 @@ import { ValidateSchema } from '@/utils/decorators';
|
|
|
9
6
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
10
7
|
import { IUsecase } from '@/utils/usecase';
|
|
11
8
|
|
|
12
|
-
import { ${
|
|
13
|
-
import { I${
|
|
9
|
+
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
10
|
+
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
14
11
|
|
|
15
|
-
export const ${
|
|
12
|
+
export const ${dashToPascal(name)}DeleteSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
16
13
|
id: true
|
|
17
14
|
});
|
|
18
15
|
|
|
19
|
-
export type ${
|
|
20
|
-
export type ${
|
|
16
|
+
export type ${dashToPascal(name)}DeleteInput = z.infer<typeof ${dashToPascal(name)}DeleteSchema>;
|
|
17
|
+
export type ${dashToPascal(name)}DeleteOutput = ${dashToPascal(name)}Entity;
|
|
21
18
|
|
|
22
|
-
export class ${
|
|
23
|
-
constructor(private readonly ${name}Repository: I${
|
|
19
|
+
export class ${dashToPascal(name)}DeleteUsecase implements IUsecase {
|
|
20
|
+
constructor(private readonly ${name}Repository: I${dashToPascal(name)}Repository) {}
|
|
24
21
|
|
|
25
|
-
@ValidateSchema(${
|
|
26
|
-
async execute({ id }: ${
|
|
22
|
+
@ValidateSchema(${dashToPascal(name)}DeleteSchema)
|
|
23
|
+
async execute({ id }: ${dashToPascal(name)}DeleteInput): Promise<${dashToPascal(name)}DeleteOutput> {
|
|
27
24
|
const model = await this.${name}Repository.findById(id);
|
|
28
25
|
|
|
29
26
|
if (!model) {
|
|
30
27
|
throw new ApiNotFoundException('${name}NotFound');
|
|
31
28
|
}
|
|
32
29
|
|
|
33
|
-
const ${name} = new ${
|
|
30
|
+
const ${name} = new ${dashToPascal(name)}Entity(model);
|
|
34
31
|
|
|
35
32
|
${name}.deactivated();
|
|
36
33
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function capitalizeFirstLetter(string) {
|
|
3
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
|
-
}
|
|
1
|
+
const { dashToPascal } = require("../../../../textUtils")
|
|
5
2
|
|
|
6
3
|
const getCoreUsecaseGetById = (name) => `import { z } from 'zod';
|
|
7
4
|
|
|
@@ -9,27 +6,27 @@ import { ValidateSchema } from '@/utils/decorators';
|
|
|
9
6
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
10
7
|
import { IUsecase } from '@/utils/usecase';
|
|
11
8
|
|
|
12
|
-
import { ${
|
|
13
|
-
import { I${
|
|
9
|
+
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
10
|
+
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
14
11
|
|
|
15
|
-
export const ${
|
|
12
|
+
export const ${dashToPascal(name)}GetByIdSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
16
13
|
id: true
|
|
17
14
|
});
|
|
18
|
-
export type ${
|
|
19
|
-
export type ${
|
|
15
|
+
export type ${dashToPascal(name)}GetByIdInput = z.infer<typeof ${dashToPascal(name)}GetByIdSchema>;
|
|
16
|
+
export type ${dashToPascal(name)}GetByIdOutput = ${dashToPascal(name)}Entity;
|
|
20
17
|
|
|
21
|
-
export class ${
|
|
22
|
-
constructor(private readonly ${name}Repository: I${
|
|
18
|
+
export class ${dashToPascal(name)}GetByIdUsecase implements IUsecase {
|
|
19
|
+
constructor(private readonly ${name}Repository: I${dashToPascal(name)}Repository) {}
|
|
23
20
|
|
|
24
|
-
@ValidateSchema(${
|
|
25
|
-
async execute({ id }: ${
|
|
21
|
+
@ValidateSchema(${dashToPascal(name)}GetByIdSchema)
|
|
22
|
+
async execute({ id }: ${dashToPascal(name)}GetByIdInput): Promise<${dashToPascal(name)}GetByIdOutput> {
|
|
26
23
|
const ${name} = await this.${name}Repository.findById(id);
|
|
27
24
|
|
|
28
25
|
if (!${name}) {
|
|
29
26
|
throw new ApiNotFoundException('${name}NotFound');
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
const entity = new ${
|
|
29
|
+
const entity = new ${dashToPascal(name)}Entity(${name});
|
|
33
30
|
|
|
34
31
|
return entity;
|
|
35
32
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
const pluralize = require('pluralize')
|
|
2
|
-
|
|
3
|
-
function capitalizeFirstLetter(string) {
|
|
4
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
5
|
-
}
|
|
2
|
+
const { dashToPascal } = require('../../../../textUtils')
|
|
6
3
|
|
|
7
4
|
const getCoreUsecaseList = (name) => `import { z } from 'zod';
|
|
8
5
|
|
|
@@ -12,23 +9,23 @@ import { SearchSchema } from '@/utils/search';
|
|
|
12
9
|
import { SortSchema } from '@/utils/sort';
|
|
13
10
|
import { IUsecase } from '@/utils/usecase';
|
|
14
11
|
|
|
15
|
-
import { ${
|
|
16
|
-
import { I${
|
|
12
|
+
import { ${dashToPascal(name)}Entity } from '../entity/${name}';
|
|
13
|
+
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
17
14
|
|
|
18
|
-
export const ${
|
|
15
|
+
export const ${dashToPascal(name)}ListSchema = z.intersection(PaginationSchema, SortSchema.merge(SearchSchema));
|
|
19
16
|
|
|
20
|
-
export type ${
|
|
21
|
-
export type ${
|
|
17
|
+
export type ${dashToPascal(name)}ListInput = PaginationInput<${dashToPascal(name)}Entity>;
|
|
18
|
+
export type ${dashToPascal(name)}ListOutput = PaginationOutput<${dashToPascal(name)}Entity>;
|
|
22
19
|
|
|
23
|
-
export class ${
|
|
24
|
-
constructor(private readonly ${name}Repository: I${
|
|
20
|
+
export class ${dashToPascal(name)}ListUsecase implements IUsecase {
|
|
21
|
+
constructor(private readonly ${name}Repository: I${dashToPascal(name)}Repository) {}
|
|
25
22
|
|
|
26
|
-
@ValidateSchema(${
|
|
27
|
-
async execute(input: ${
|
|
23
|
+
@ValidateSchema(${dashToPascal(name)}ListSchema)
|
|
24
|
+
async execute(input: ${dashToPascal(name)}ListInput): Promise<${dashToPascal(name)}ListOutput> {
|
|
28
25
|
const ${pluralize(name)} = await this.${name}Repository.paginate(input);
|
|
29
26
|
|
|
30
27
|
return {
|
|
31
|
-
docs: ${pluralize(name)}.docs.map((u) => new ${
|
|
28
|
+
docs: ${pluralize(name)}.docs.map((u) => new ${dashToPascal(name)}Entity(u)),
|
|
32
29
|
limit: ${pluralize(name)}.limit,
|
|
33
30
|
page: ${pluralize(name)}.page,
|
|
34
31
|
total: ${pluralize(name)}.total
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
function capitalizeFirstLetter(string) {
|
|
3
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
|
-
}
|
|
1
|
+
const { dashToPascal } = require("../../../../textUtils")
|
|
5
2
|
|
|
6
3
|
const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
|
|
7
4
|
|
|
@@ -10,33 +7,33 @@ import { ValidateSchema } from '@/utils/decorators';
|
|
|
10
7
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
11
8
|
import { IUsecase } from '@/utils/usecase';
|
|
12
9
|
|
|
13
|
-
import { ${
|
|
14
|
-
import { I${
|
|
10
|
+
import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
|
|
11
|
+
import { I${dashToPascal(name)}Repository } from '../repository/${name}';
|
|
15
12
|
|
|
16
|
-
export const ${
|
|
13
|
+
export const ${dashToPascal(name)}UpdateSchema = ${dashToPascal(name)}EntitySchema.pick({
|
|
17
14
|
id: true
|
|
18
|
-
}).merge(${
|
|
15
|
+
}).merge(${dashToPascal(name)}EntitySchema.omit({ id: true }).partial());
|
|
19
16
|
|
|
20
|
-
export type ${
|
|
21
|
-
export type ${
|
|
17
|
+
export type ${dashToPascal(name)}UpdateInput = Partial<z.infer<typeof ${dashToPascal(name)}UpdateSchema>>;
|
|
18
|
+
export type ${dashToPascal(name)}UpdateOutput = ${dashToPascal(name)}Entity;
|
|
22
19
|
|
|
23
|
-
export class ${
|
|
20
|
+
export class ${dashToPascal(name)}UpdateUsecase implements IUsecase {
|
|
24
21
|
constructor(
|
|
25
|
-
private readonly ${name}Repository: I${
|
|
22
|
+
private readonly ${name}Repository: I${dashToPascal(name)}Repository,
|
|
26
23
|
private readonly loggerService: ILoggerAdapter
|
|
27
24
|
) {}
|
|
28
25
|
|
|
29
|
-
@ValidateSchema(${
|
|
30
|
-
async execute(input: ${
|
|
26
|
+
@ValidateSchema(${dashToPascal(name)}UpdateSchema)
|
|
27
|
+
async execute(input: ${dashToPascal(name)}UpdateInput): Promise<${dashToPascal(name)}UpdateOutput> {
|
|
31
28
|
const ${name} = await this.${name}Repository.findById(input.id as string);
|
|
32
29
|
|
|
33
30
|
if (!${name}) {
|
|
34
31
|
throw new ApiNotFoundException('${name}NotFound');
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
const ${name}Found = new ${
|
|
34
|
+
const ${name}Found = new ${dashToPascal(name)}Entity(${name});
|
|
38
35
|
|
|
39
|
-
const entity = new ${
|
|
36
|
+
const entity = new ${dashToPascal(name)}Entity({ ...${name}Found, ...input });
|
|
40
37
|
|
|
41
38
|
await this.${name}Repository.updateOne({ id: entity.id }, entity);
|
|
42
39
|
|
|
@@ -44,7 +41,7 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
|
|
|
44
41
|
|
|
45
42
|
const updated = await this.${name}Repository.findById(entity.id);
|
|
46
43
|
|
|
47
|
-
return new ${
|
|
44
|
+
return new ${dashToPascal(name)}Entity(updated as ${dashToPascal(name)}Entity);
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
`
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
+
const { dashToPascal } = require("../../../textUtils")
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
8
|
-
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
9
|
-
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
10
|
-
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
3
|
+
const getModuleAdapter = (name) => `import { ${dashToPascal(name)}CreateInput, ${dashToPascal(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
4
|
+
import { ${dashToPascal(name)}DeleteInput, ${dashToPascal(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
5
|
+
import { ${dashToPascal(name)}GetByIdInput, ${dashToPascal(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
6
|
+
import { ${dashToPascal(name)}ListInput, ${dashToPascal(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
7
|
+
import { ${dashToPascal(name)}UpdateInput, ${dashToPascal(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
11
8
|
import { IUsecase } from '@/utils/usecase';
|
|
12
9
|
|
|
13
|
-
export abstract class I${
|
|
14
|
-
abstract execute(input: ${
|
|
10
|
+
export abstract class I${dashToPascal(name)}CreateAdapter implements IUsecase {
|
|
11
|
+
abstract execute(input: ${dashToPascal(name)}CreateInput): Promise<${dashToPascal(name)}CreateOutput>;
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
export abstract class I${
|
|
18
|
-
abstract execute(input: ${
|
|
14
|
+
export abstract class I${dashToPascal(name)}UpdateAdapter implements IUsecase {
|
|
15
|
+
abstract execute(input: ${dashToPascal(name)}UpdateInput): Promise<${dashToPascal(name)}UpdateOutput>;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
export abstract class I${
|
|
22
|
-
abstract execute(input: ${
|
|
18
|
+
export abstract class I${dashToPascal(name)}ListAdapter implements IUsecase {
|
|
19
|
+
abstract execute(input: ${dashToPascal(name)}ListInput): Promise<${dashToPascal(name)}ListOutput>;
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
export abstract class I${
|
|
26
|
-
abstract execute(input: ${
|
|
22
|
+
export abstract class I${dashToPascal(name)}DeleteAdapter implements IUsecase {
|
|
23
|
+
abstract execute(input: ${dashToPascal(name)}DeleteInput): Promise<${dashToPascal(name)}DeleteOutput>;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
export abstract class I${
|
|
30
|
-
abstract execute(input: ${
|
|
26
|
+
export abstract class I${dashToPascal(name)}GetByIdAdapter implements IUsecase {
|
|
27
|
+
abstract execute(input: ${dashToPascal(name)}GetByIdInput): Promise<${dashToPascal(name)}GetByIdOutput>;
|
|
31
28
|
}
|
|
32
29
|
`
|
|
33
30
|
|
|
@@ -1,47 +1,44 @@
|
|
|
1
1
|
const pluralize = require('pluralize')
|
|
2
|
-
|
|
3
|
-
function capitalizeFirstLetter(string) {
|
|
4
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
5
|
-
}
|
|
2
|
+
const { dashToPascal } = require('../../../textUtils')
|
|
6
3
|
|
|
7
4
|
const getModuleController = (name) => `import { Controller, Delete, Get, Post, Put, Req } from '@nestjs/common';
|
|
8
5
|
import { ApiBearerAuth, ApiBody, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
9
6
|
|
|
10
|
-
import { ${
|
|
11
|
-
import { ${
|
|
12
|
-
import { ${
|
|
13
|
-
import { ${
|
|
14
|
-
import { ${
|
|
7
|
+
import { ${dashToPascal(name)}CreateInput, ${dashToPascal(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
8
|
+
import { ${dashToPascal(name)}DeleteInput, ${dashToPascal(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
9
|
+
import { ${dashToPascal(name)}GetByIdInput, ${dashToPascal(name)}GetByIdOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
10
|
+
import { ${dashToPascal(name)}ListInput, ${dashToPascal(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
11
|
+
import { ${dashToPascal(name)}UpdateInput, ${dashToPascal(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
|
|
15
12
|
import { ApiRequest } from '@/utils/request';
|
|
16
13
|
import { SearchHttpSchema } from '@/utils/search';
|
|
17
14
|
import { SortHttpSchema } from '@/utils/sort';
|
|
18
15
|
|
|
19
16
|
import {
|
|
20
|
-
I${
|
|
21
|
-
I${
|
|
22
|
-
I${
|
|
23
|
-
I${
|
|
24
|
-
I${
|
|
17
|
+
I${dashToPascal(name)}CreateAdapter,
|
|
18
|
+
I${dashToPascal(name)}DeleteAdapter,
|
|
19
|
+
I${dashToPascal(name)}GetByIdAdapter,
|
|
20
|
+
I${dashToPascal(name)}ListAdapter,
|
|
21
|
+
I${dashToPascal(name)}UpdateAdapter
|
|
25
22
|
} from './adapter';
|
|
26
23
|
import { SwaggerRequest, SwaggerResponse } from './swagger';
|
|
27
24
|
|
|
28
25
|
@Controller('/${pluralize(name)}')
|
|
29
26
|
@ApiTags('${pluralize(name)}')
|
|
30
27
|
@ApiBearerAuth()
|
|
31
|
-
export class ${
|
|
28
|
+
export class ${dashToPascal(name)}Controller {
|
|
32
29
|
constructor(
|
|
33
|
-
private readonly ${name}CreateUsecase: I${
|
|
34
|
-
private readonly ${name}UpdateUsecase: I${
|
|
35
|
-
private readonly ${name}DeleteUsecase: I${
|
|
36
|
-
private readonly ${name}ListUsecase: I${
|
|
37
|
-
private readonly ${name}GetByIdUsecase: I${
|
|
30
|
+
private readonly ${name}CreateUsecase: I${dashToPascal(name)}CreateAdapter,
|
|
31
|
+
private readonly ${name}UpdateUsecase: I${dashToPascal(name)}UpdateAdapter,
|
|
32
|
+
private readonly ${name}DeleteUsecase: I${dashToPascal(name)}DeleteAdapter,
|
|
33
|
+
private readonly ${name}ListUsecase: I${dashToPascal(name)}ListAdapter,
|
|
34
|
+
private readonly ${name}GetByIdUsecase: I${dashToPascal(name)}GetByIdAdapter
|
|
38
35
|
) {}
|
|
39
36
|
|
|
40
37
|
@Post()
|
|
41
38
|
@ApiResponse(SwaggerResponse.create[200])
|
|
42
39
|
@ApiBody(SwaggerRequest.createBody)
|
|
43
|
-
async create(@Req() { body }: ApiRequest): Promise<${
|
|
44
|
-
return this.${name}CreateUsecase.execute(body as ${
|
|
40
|
+
async create(@Req() { body }: ApiRequest): Promise<${dashToPascal(name)}CreateOutput> {
|
|
41
|
+
return this.${name}CreateUsecase.execute(body as ${dashToPascal(name)}CreateInput);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
@Put(':id')
|
|
@@ -49,8 +46,8 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
49
46
|
@ApiResponse(SwaggerResponse.update[404])
|
|
50
47
|
@ApiBody(SwaggerRequest.updateBody)
|
|
51
48
|
@ApiParam({ name: 'id', required: true })
|
|
52
|
-
async update(@Req() { body, params }: ApiRequest): Promise<${
|
|
53
|
-
return this.${name}UpdateUsecase.execute({ ...body, id: params.id } as ${
|
|
49
|
+
async update(@Req() { body, params }: ApiRequest): Promise<${dashToPascal(name)}UpdateOutput> {
|
|
50
|
+
return this.${name}UpdateUsecase.execute({ ...body, id: params.id } as ${dashToPascal(name)}UpdateInput);
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
@Get()
|
|
@@ -59,8 +56,8 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
59
56
|
@ApiQuery(SwaggerRequest.listQuery.sort)
|
|
60
57
|
@ApiQuery(SwaggerRequest.listQuery.search)
|
|
61
58
|
@ApiResponse(SwaggerResponse.list[200])
|
|
62
|
-
async list(@Req() { query }: ApiRequest): Promise<${
|
|
63
|
-
const input: ${
|
|
59
|
+
async list(@Req() { query }: ApiRequest): Promise<${dashToPascal(name)}ListOutput> {
|
|
60
|
+
const input: ${dashToPascal(name)}ListInput = {
|
|
64
61
|
sort: SortHttpSchema.parse(query.sort),
|
|
65
62
|
search: SearchHttpSchema.parse(query.search),
|
|
66
63
|
limit: Number(query.limit),
|
|
@@ -74,16 +71,16 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
74
71
|
@ApiParam({ name: 'id', required: true })
|
|
75
72
|
@ApiResponse(SwaggerResponse.getById[200])
|
|
76
73
|
@ApiResponse(SwaggerResponse.getById[404])
|
|
77
|
-
async getById(@Req() { params }: ApiRequest): Promise<${
|
|
78
|
-
return await this.${name}GetByIdUsecase.execute(params as ${
|
|
74
|
+
async getById(@Req() { params }: ApiRequest): Promise<${dashToPascal(name)}GetByIdOutput> {
|
|
75
|
+
return await this.${name}GetByIdUsecase.execute(params as ${dashToPascal(name)}GetByIdInput);
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
@Delete('/:id')
|
|
82
79
|
@ApiParam({ name: 'id', required: true })
|
|
83
80
|
@ApiResponse(SwaggerResponse.delete[200])
|
|
84
81
|
@ApiResponse(SwaggerResponse.delete[404])
|
|
85
|
-
async delete(@Req() { params }: ApiRequest): Promise<${
|
|
86
|
-
return await this.${name}DeleteUsecase.execute(params as ${
|
|
82
|
+
async delete(@Req() { params }: ApiRequest): Promise<${dashToPascal(name)}DeleteOutput> {
|
|
83
|
+
return await this.${name}DeleteUsecase.execute(params as ${dashToPascal(name)}DeleteInput);
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
`
|