@mikemajesty/microservice-crud 4.5.6 → 4.5.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/libs/service.js +1 -1
- package/src/templates/module/controller.js +1 -1
- package/src/templates/module/module.js +1 -1
- package/src/templates/mongo/core/use-cases/create.js +5 -4
- package/src/templates/mongo/core/use-cases/delete.js +3 -2
- package/src/templates/mongo/core/use-cases/get-by-id.js +3 -2
- package/src/templates/mongo/core/use-cases/list.js +3 -2
- package/src/templates/mongo/core/use-cases/update.js +5 -4
- package/src/templates/mongo/modules/adapter.js +6 -5
- package/src/templates/mongo/modules/controller.js +16 -16
- package/src/templates/mongo/modules/module.js +1 -1
- package/src/templates/mongo/modules/repository.js +1 -1
- package/src/templates/mongo/modules/swagger.js +2 -2
- package/src/templates/postgres/core/use-cases/create.js +5 -4
- package/src/templates/postgres/core/use-cases/delete.js +3 -2
- package/src/templates/postgres/core/use-cases/get-by-id.js +3 -2
- package/src/templates/postgres/core/use-cases/list.js +3 -2
- package/src/templates/postgres/core/use-cases/update.js +5 -4
- package/src/templates/postgres/modules/adapter.js +6 -5
- package/src/templates/postgres/modules/controller.js +16 -16
- package/src/templates/postgres/modules/module.js +1 -1
- package/src/templates/postgres/modules/repository.js +1 -1
- package/src/templates/postgres/modules/swagger.js +2 -2
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ function capitalizeFirstLetter(string) {
|
|
|
6
6
|
const getServiceLib = (name) => `import { Injectable } from '@nestjs/common';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
|
-
import { ValidateSchema } from '@/
|
|
9
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
10
10
|
|
|
11
11
|
import { I${capitalizeFirstLetter(name)}Adapter } from './adapter';
|
|
12
12
|
|
|
@@ -8,7 +8,7 @@ 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 '@/
|
|
11
|
+
import { Roles } from '@/utils/decorators';
|
|
12
12
|
import { UserRole } from '@/core/user/entity/user';
|
|
13
13
|
import { ApiRequest } from '@/utils/request';
|
|
14
14
|
|
|
@@ -4,7 +4,7 @@ function capitalizeFirstLetter(string) {
|
|
|
4
4
|
|
|
5
5
|
const getModuleModule = (name) => `import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
|
6
6
|
|
|
7
|
-
import { IsLoggedMiddleware } from '@/
|
|
7
|
+
import { IsLoggedMiddleware } from '@/observables/middlewares';
|
|
8
8
|
import { RedisCacheModule } from '@/infra/cache/redis';
|
|
9
9
|
import { LoggerModule } from '@/infra/logger';
|
|
10
10
|
import { TokenModule } from '@/libs/auth';
|
|
@@ -5,9 +5,10 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
10
10
|
import { CreatedModel } from '@/infra/repository';
|
|
11
|
+
import { IUsecase } from '@/utils/usecase';
|
|
11
12
|
|
|
12
13
|
import { ${capitalizeFirstLetter(name)}Entity, ${capitalizeFirstLetter(name)}EntitySchema } from '../entity/${name}';
|
|
13
14
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
@@ -19,8 +20,8 @@ export const ${capitalizeFirstLetter(name)}CreateSchema = ${capitalizeFirstLette
|
|
|
19
20
|
export type ${capitalizeFirstLetter(name)}CreateInput = z.infer<typeof ${capitalizeFirstLetter(name)}CreateSchema>;
|
|
20
21
|
export type ${capitalizeFirstLetter(name)}CreateOutput = CreatedModel;
|
|
21
22
|
|
|
22
|
-
export class ${capitalizeFirstLetter(name)}CreateUsecase {
|
|
23
|
-
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly
|
|
23
|
+
export class ${capitalizeFirstLetter(name)}CreateUsecase implements IUsecase {
|
|
24
|
+
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerService: ILoggerAdapter) {}
|
|
24
25
|
|
|
25
26
|
@ValidateSchema(${capitalizeFirstLetter(name)}CreateSchema)
|
|
26
27
|
async execute(input: ${capitalizeFirstLetter(name)}CreateInput): Promise<${capitalizeFirstLetter(name)}CreateOutput> {
|
|
@@ -33,7 +34,7 @@ export class ${capitalizeFirstLetter(name)}CreateUsecase {
|
|
|
33
34
|
|
|
34
35
|
await session.commitTransaction();
|
|
35
36
|
|
|
36
|
-
this.
|
|
37
|
+
this.loggerService.info({ message: '${name} created.', obj: { ${name} } });
|
|
37
38
|
return ${name};
|
|
38
39
|
} catch (error) {
|
|
39
40
|
await session.abortTransaction();
|
|
@@ -5,8 +5,9 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
10
|
+
import { IUsecase } from '@/utils/usecase';
|
|
10
11
|
|
|
11
12
|
import { ${capitalizeFirstLetter(name)}Entity, ${capitalizeFirstLetter(name)}EntitySchema } from '../entity/${name}';
|
|
12
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
@@ -18,7 +19,7 @@ export const ${capitalizeFirstLetter(name)}DeleteSchema = ${capitalizeFirstLette
|
|
|
18
19
|
export type ${capitalizeFirstLetter(name)}DeleteInput = z.infer<typeof ${capitalizeFirstLetter(name)}DeleteSchema>;
|
|
19
20
|
export type ${capitalizeFirstLetter(name)}DeleteOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
20
21
|
|
|
21
|
-
export class ${capitalizeFirstLetter(name)}DeleteUsecase {
|
|
22
|
+
export class ${capitalizeFirstLetter(name)}DeleteUsecase implements IUsecase {
|
|
22
23
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
23
24
|
|
|
24
25
|
@ValidateSchema(${capitalizeFirstLetter(name)}DeleteSchema)
|
|
@@ -5,8 +5,9 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseGetByID = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
10
|
+
import { IUsecase } from '@/utils/usecase';
|
|
10
11
|
|
|
11
12
|
import { ${capitalizeFirstLetter(name)}Entity, ${capitalizeFirstLetter(name)}EntitySchema } from '../entity/${name}';
|
|
12
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
@@ -17,7 +18,7 @@ export const ${capitalizeFirstLetter(name)}GetByIdSchema = ${capitalizeFirstLett
|
|
|
17
18
|
export type ${capitalizeFirstLetter(name)}GetByIDInput = z.infer<typeof ${capitalizeFirstLetter(name)}GetByIdSchema>;
|
|
18
19
|
export type ${capitalizeFirstLetter(name)}GetByIDOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
19
20
|
|
|
20
|
-
export class ${capitalizeFirstLetter(name)}GetByIdUsecase {
|
|
21
|
+
export class ${capitalizeFirstLetter(name)}GetByIdUsecase implements IUsecase {
|
|
21
22
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
22
23
|
|
|
23
24
|
@ValidateSchema(${capitalizeFirstLetter(name)}GetByIdSchema)
|
|
@@ -6,10 +6,11 @@ function capitalizeFirstLetter(string) {
|
|
|
6
6
|
|
|
7
7
|
const getCoreUsecaseList = (name) => `import { z } from 'zod';
|
|
8
8
|
|
|
9
|
-
import { ValidateSchema } from '@/
|
|
9
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
10
10
|
import { PaginationInput, PaginationOutput, PaginationSchema } from '@/utils/pagination';
|
|
11
11
|
import { SearchSchema } from '@/utils/search';
|
|
12
12
|
import { SortSchema } from '@/utils/sort';
|
|
13
|
+
import { IUsecase } from '@/utils/usecase';
|
|
13
14
|
|
|
14
15
|
import { ${capitalizeFirstLetter(name)}Entity } from '../entity/${name}';
|
|
15
16
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
@@ -19,7 +20,7 @@ export const ${capitalizeFirstLetter(name)}ListSchema = z.intersection(Paginatio
|
|
|
19
20
|
export type ${capitalizeFirstLetter(name)}ListInput = PaginationInput<${capitalizeFirstLetter(name)}Entity>;
|
|
20
21
|
export type ${capitalizeFirstLetter(name)}ListOutput = PaginationOutput<${capitalizeFirstLetter(name)}Entity>;
|
|
21
22
|
|
|
22
|
-
export class ${capitalizeFirstLetter(name)}ListUsecase {
|
|
23
|
+
export class ${capitalizeFirstLetter(name)}ListUsecase implements IUsecase {
|
|
23
24
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
24
25
|
|
|
25
26
|
@ValidateSchema(${capitalizeFirstLetter(name)}ListSchema)
|
|
@@ -5,9 +5,10 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
10
10
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
11
|
+
import { IUsecase } from '@/utils/usecase';
|
|
11
12
|
|
|
12
13
|
import { ${capitalizeFirstLetter(name)}Entity, ${capitalizeFirstLetter(name)}EntitySchema } from '../entity/${name}';
|
|
13
14
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
@@ -19,8 +20,8 @@ export const ${capitalizeFirstLetter(name)}UpdateSchema = ${capitalizeFirstLette
|
|
|
19
20
|
export type ${capitalizeFirstLetter(name)}UpdateInput = Partial<z.infer<typeof ${capitalizeFirstLetter(name)}UpdateSchema>>;
|
|
20
21
|
export type ${capitalizeFirstLetter(name)}UpdateOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
21
22
|
|
|
22
|
-
export class ${capitalizeFirstLetter(name)}UpdateUsecase {
|
|
23
|
-
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly
|
|
23
|
+
export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
|
|
24
|
+
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerService: ILoggerAdapter) {}
|
|
24
25
|
|
|
25
26
|
@ValidateSchema(${capitalizeFirstLetter(name)}UpdateSchema)
|
|
26
27
|
async execute(input: ${capitalizeFirstLetter(name)}UpdateInput): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
|
|
@@ -36,7 +37,7 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase {
|
|
|
36
37
|
|
|
37
38
|
await this.${name}Repository.updateOne({ id: entity.id }, entity);
|
|
38
39
|
|
|
39
|
-
this.
|
|
40
|
+
this.loggerService.info({ message: '${name} updated.', obj: { ${name}: input } });
|
|
40
41
|
|
|
41
42
|
const updated = await this.${name}Repository.findById(entity.id);
|
|
42
43
|
|
|
@@ -8,24 +8,25 @@ import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name
|
|
|
8
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
|
+
import { IUsecase } from '@/utils/usecase';
|
|
11
12
|
|
|
12
|
-
export abstract class I${capitalizeFirstLetter(name)}CreateAdapter {
|
|
13
|
+
export abstract class I${capitalizeFirstLetter(name)}CreateAdapter implements IUsecase {
|
|
13
14
|
abstract execute(input: ${capitalizeFirstLetter(name)}CreateInput): Promise<${capitalizeFirstLetter(name)}CreateOutput>;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export abstract class I${capitalizeFirstLetter(name)}UpdateAdapter {
|
|
17
|
+
export abstract class I${capitalizeFirstLetter(name)}UpdateAdapter implements IUsecase {
|
|
17
18
|
abstract execute(input: ${capitalizeFirstLetter(name)}UpdateInput): Promise<${capitalizeFirstLetter(name)}UpdateOutput>;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export abstract class I${capitalizeFirstLetter(name)}ListAdapter {
|
|
21
|
+
export abstract class I${capitalizeFirstLetter(name)}ListAdapter implements IUsecase {
|
|
21
22
|
abstract execute(input: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export abstract class I${capitalizeFirstLetter(name)}DeleteAdapter {
|
|
25
|
+
export abstract class I${capitalizeFirstLetter(name)}DeleteAdapter implements IUsecase {
|
|
25
26
|
abstract execute(input: ${capitalizeFirstLetter(name)}DeleteInput): Promise<${capitalizeFirstLetter(name)}DeleteOutput>;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export abstract class I${capitalizeFirstLetter(name)}GetByIDAdapter {
|
|
29
|
+
export abstract class I${capitalizeFirstLetter(name)}GetByIDAdapter implements IUsecase {
|
|
29
30
|
abstract execute(input: ${capitalizeFirstLetter(name)}GetByIDInput): Promise<${capitalizeFirstLetter(name)}GetByIDOutput>;
|
|
30
31
|
}
|
|
31
32
|
`
|
|
@@ -7,7 +7,7 @@ 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 '@/
|
|
10
|
+
import { Roles } from '@/utils/decorators';
|
|
11
11
|
import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
12
12
|
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}GetByIDInput, ${capitalizeFirstLetter(name)}GetByIDOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
I${capitalizeFirstLetter(name)}ListAdapter,
|
|
26
26
|
I${capitalizeFirstLetter(name)}UpdateAdapter
|
|
27
27
|
} from './adapter';
|
|
28
|
-
import {
|
|
28
|
+
import { SwaggerRequest, SwaggerResponse } from './swagger';
|
|
29
29
|
|
|
30
30
|
@Controller('/${pluralize(name)}')
|
|
31
31
|
@ApiTags('${pluralize(name)}')
|
|
@@ -41,26 +41,26 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
41
41
|
) {}
|
|
42
42
|
|
|
43
43
|
@Post()
|
|
44
|
-
@ApiResponse(
|
|
45
|
-
@ApiBody(
|
|
44
|
+
@ApiResponse(SwaggerResponse.create[200])
|
|
45
|
+
@ApiBody(SwaggerRequest.createBody)
|
|
46
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
50
|
@Put()
|
|
51
|
-
@ApiResponse(
|
|
52
|
-
@ApiResponse(
|
|
53
|
-
@ApiBody(
|
|
51
|
+
@ApiResponse(SwaggerResponse.update[200])
|
|
52
|
+
@ApiResponse(SwaggerResponse.update[404])
|
|
53
|
+
@ApiBody(SwaggerRequest.updateBody)
|
|
54
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
58
|
@Get()
|
|
59
|
-
@ApiQuery(
|
|
60
|
-
@ApiQuery(
|
|
61
|
-
@ApiQuery(
|
|
62
|
-
@ApiQuery(
|
|
63
|
-
@ApiResponse(
|
|
59
|
+
@ApiQuery(SwaggerRequest.listQuery.pagination.limit)
|
|
60
|
+
@ApiQuery(SwaggerRequest.listQuery.pagination.page)
|
|
61
|
+
@ApiQuery(SwaggerRequest.listQuery.sort)
|
|
62
|
+
@ApiQuery(SwaggerRequest.listQuery.search)
|
|
63
|
+
@ApiResponse(SwaggerResponse.list[200])
|
|
64
64
|
async list(@Req() { query }: ApiRequest): Promise<${capitalizeFirstLetter(name)}ListOutput> {
|
|
65
65
|
const input: ${capitalizeFirstLetter(name)}ListInput = {
|
|
66
66
|
sort: SortHttpSchema.parse(query.sort),
|
|
@@ -74,16 +74,16 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
74
74
|
|
|
75
75
|
@Get('/:id')
|
|
76
76
|
@ApiParam({ name: 'id', required: true })
|
|
77
|
-
@ApiResponse(
|
|
78
|
-
@ApiResponse(
|
|
77
|
+
@ApiResponse(SwaggerResponse.getByID[200])
|
|
78
|
+
@ApiResponse(SwaggerResponse.getByID[404])
|
|
79
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
83
|
@Delete('/:id')
|
|
84
84
|
@ApiParam({ name: 'id', required: true })
|
|
85
|
-
@ApiResponse(
|
|
86
|
-
@ApiResponse(
|
|
85
|
+
@ApiResponse(SwaggerResponse.delete[200])
|
|
86
|
+
@ApiResponse(SwaggerResponse.delete[404])
|
|
87
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
|
}
|
|
@@ -7,7 +7,7 @@ const getModule = (name) => `import { MiddlewareConsumer, Module, NestModule } f
|
|
|
7
7
|
import { getConnectionToken } from '@nestjs/mongoose';
|
|
8
8
|
import mongoose, { Connection, PaginateModel, Schema } from 'mongoose';
|
|
9
9
|
|
|
10
|
-
import { IsLoggedMiddleware } from '@/
|
|
10
|
+
import { IsLoggedMiddleware } from '@/observables/middlewares';
|
|
11
11
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
12
12
|
import { ${capitalizeFirstLetter(name)}CreateUsecase } from '@/core/${name}/use-cases/${name}-create';
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}DeleteUsecase } from '@/core/${name}/use-cases/${name}-delete';
|
|
@@ -8,7 +8,7 @@ const getModuleRepository = (name) => `import { Injectable } from '@nestjs/commo
|
|
|
8
8
|
import { InjectModel } from '@nestjs/mongoose';
|
|
9
9
|
import { PaginateModel } from 'mongoose';
|
|
10
10
|
|
|
11
|
-
import { SearchTypeEnum, ValidateDatabaseSortAllowed, ValidateMongooseFilter } from '@/
|
|
11
|
+
import { SearchTypeEnum, ValidateDatabaseSortAllowed, ValidateMongooseFilter } from '@/utils/decorators';
|
|
12
12
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
14
14
|
import { ${capitalizeFirstLetter(name)}, ${capitalizeFirstLetter(name)}Document } from '@/infra/database/mongo/schemas/${name}';
|
|
@@ -19,7 +19,7 @@ const input = new ${capitalizeFirstLetter(name)}Entity({
|
|
|
19
19
|
|
|
20
20
|
const output = new ${capitalizeFirstLetter(name)}Entity({ ...input, updatedAt: new Date(), createdAt: new Date(), deletedAt: null });
|
|
21
21
|
|
|
22
|
-
export const
|
|
22
|
+
export const SwaggerResponse = {
|
|
23
23
|
create: {
|
|
24
24
|
200: Swagger.defaultResponseJSON({
|
|
25
25
|
status: 200,
|
|
@@ -75,7 +75,7 @@ export const SwagggerResponse = {
|
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
export const
|
|
78
|
+
export const SwaggerRequest = {
|
|
79
79
|
createBody: Swagger.defaultRequestJSON({ ...input, id: undefined } as ${capitalizeFirstLetter(name)}Entity),
|
|
80
80
|
updateBody: Swagger.defaultRequestJSON({ ...input, id: '<id>' } as ${capitalizeFirstLetter(name)}Entity),
|
|
81
81
|
listQuery: {
|
|
@@ -5,10 +5,11 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
10
10
|
import { CreatedModel } from '@/infra/repository';
|
|
11
11
|
import { DatabaseOptionsType } from '@/utils/database/sequelize';
|
|
12
|
+
import { IUsecase } from '@/utils/usecase';
|
|
12
13
|
|
|
13
14
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
14
15
|
import { ${capitalizeFirstLetter(name)}Entity, ${capitalizeFirstLetter(name)}EntitySchema } from './../entity/${name}';
|
|
@@ -20,8 +21,8 @@ export const ${capitalizeFirstLetter(name)}CreateSchema = ${capitalizeFirstLette
|
|
|
20
21
|
export type ${capitalizeFirstLetter(name)}CreateInput = z.infer<typeof ${capitalizeFirstLetter(name)}CreateSchema>;
|
|
21
22
|
export type ${capitalizeFirstLetter(name)}CreateOutput = CreatedModel;
|
|
22
23
|
|
|
23
|
-
export class ${capitalizeFirstLetter(name)}CreateUsecase {
|
|
24
|
-
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly
|
|
24
|
+
export class ${capitalizeFirstLetter(name)}CreateUsecase implements IUsecase {
|
|
25
|
+
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerService: ILoggerAdapter) {}
|
|
25
26
|
|
|
26
27
|
@ValidateSchema(${capitalizeFirstLetter(name)}CreateSchema)
|
|
27
28
|
async execute(input: ${capitalizeFirstLetter(name)}CreateInput): Promise<${capitalizeFirstLetter(name)}CreateOutput> {
|
|
@@ -33,7 +34,7 @@ export class ${capitalizeFirstLetter(name)}CreateUsecase {
|
|
|
33
34
|
|
|
34
35
|
await transaction.commit();
|
|
35
36
|
|
|
36
|
-
this.
|
|
37
|
+
this.loggerService.info({ message: '${name} created.', obj: { ${name} } });
|
|
37
38
|
|
|
38
39
|
return ${name};
|
|
39
40
|
} catch (error) {
|
|
@@ -5,10 +5,11 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
10
10
|
import { DatabaseOptionsType } from '@/utils/database/sequelize';
|
|
11
11
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
12
|
+
import { IUsecase } from '@/utils/usecase';
|
|
12
13
|
|
|
13
14
|
import { ${capitalizeFirstLetter(name)}Entity, ${capitalizeFirstLetter(name)}EntitySchema } from '../entity/${name}';
|
|
14
15
|
|
|
@@ -19,7 +20,7 @@ export const ${capitalizeFirstLetter(name)}DeleteSchema = ${capitalizeFirstLette
|
|
|
19
20
|
export type ${capitalizeFirstLetter(name)}DeleteInput = z.infer<typeof ${capitalizeFirstLetter(name)}DeleteSchema>;
|
|
20
21
|
export type ${capitalizeFirstLetter(name)}DeleteOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
21
22
|
|
|
22
|
-
export class ${capitalizeFirstLetter(name)}DeleteUsecase {
|
|
23
|
+
export class ${capitalizeFirstLetter(name)}DeleteUsecase implements IUsecase {
|
|
23
24
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
24
25
|
|
|
25
26
|
@ValidateSchema(${capitalizeFirstLetter(name)}DeleteSchema)
|
|
@@ -5,10 +5,11 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseGetByID = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ${capitalizeFirstLetter(name)}EntitySchema } from '@/core/${name}/entity/${name}';
|
|
10
10
|
import { DatabaseOptionsType } from '@/utils/database/sequelize';
|
|
11
11
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
12
|
+
import { IUsecase } from '@/utils/usecase';
|
|
12
13
|
|
|
13
14
|
import { ${capitalizeFirstLetter(name)}Entity } from '../entity/${name}';
|
|
14
15
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
@@ -20,7 +21,7 @@ export const ${capitalizeFirstLetter(name)}GetByIdSchema = ${capitalizeFirstLett
|
|
|
20
21
|
export type ${capitalizeFirstLetter(name)}GetByIDInput = z.infer<typeof ${capitalizeFirstLetter(name)}GetByIdSchema>;
|
|
21
22
|
export type ${capitalizeFirstLetter(name)}GetByIDOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
22
23
|
|
|
23
|
-
export class ${capitalizeFirstLetter(name)}GetByIdUsecase {
|
|
24
|
+
export class ${capitalizeFirstLetter(name)}GetByIdUsecase implements IUsecase {
|
|
24
25
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
25
26
|
|
|
26
27
|
@ValidateSchema(${capitalizeFirstLetter(name)}GetByIdSchema)
|
|
@@ -5,11 +5,12 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseList = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
10
10
|
import { PaginationInput, PaginationOutput, PaginationSchema } from '@/utils/pagination';
|
|
11
11
|
import { SearchSchema } from '@/utils/search';
|
|
12
12
|
import { SortSchema } from '@/utils/sort';
|
|
13
|
+
import { IUsecase } from '@/utils/usecase';
|
|
13
14
|
|
|
14
15
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
15
16
|
|
|
@@ -18,7 +19,7 @@ export const ${capitalizeFirstLetter(name)}ListSchema = z.intersection(Paginatio
|
|
|
18
19
|
export type ${capitalizeFirstLetter(name)}ListInput = PaginationInput<${capitalizeFirstLetter(name)}Entity>;
|
|
19
20
|
export type ${capitalizeFirstLetter(name)}ListOutput = PaginationOutput<${capitalizeFirstLetter(name)}Entity>;
|
|
20
21
|
|
|
21
|
-
export class ${capitalizeFirstLetter(name)}ListUsecase {
|
|
22
|
+
export class ${capitalizeFirstLetter(name)}ListUsecase implements IUsecase {
|
|
22
23
|
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository) {}
|
|
23
24
|
|
|
24
25
|
@ValidateSchema(${capitalizeFirstLetter(name)}ListSchema)
|
|
@@ -5,11 +5,12 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/
|
|
8
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
10
10
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
11
11
|
import { DatabaseOptionsType } from '@/utils/database/sequelize';
|
|
12
12
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
13
|
+
import { IUsecase } from '@/utils/usecase';
|
|
13
14
|
|
|
14
15
|
import { ${capitalizeFirstLetter(name)}Entity, ${capitalizeFirstLetter(name)}EntitySchema } from './../entity/${name}';
|
|
15
16
|
|
|
@@ -20,8 +21,8 @@ export const ${capitalizeFirstLetter(name)}UpdateSchema = ${capitalizeFirstLette
|
|
|
20
21
|
export type ${capitalizeFirstLetter(name)}UpdateInput = z.infer<typeof ${capitalizeFirstLetter(name)}UpdateSchema>;
|
|
21
22
|
export type ${capitalizeFirstLetter(name)}UpdateOutput = ${capitalizeFirstLetter(name)}Entity;
|
|
22
23
|
|
|
23
|
-
export class ${capitalizeFirstLetter(name)}UpdateUsecase {
|
|
24
|
-
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly
|
|
24
|
+
export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
|
|
25
|
+
constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerService: ILoggerAdapter) {}
|
|
25
26
|
|
|
26
27
|
@ValidateSchema(${capitalizeFirstLetter(name)}UpdateSchema)
|
|
27
28
|
async execute(input: ${capitalizeFirstLetter(name)}UpdateInput): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
|
|
@@ -37,7 +38,7 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase {
|
|
|
37
38
|
|
|
38
39
|
await this.${name}Repository.updateOne({ id: entity.id }, entity);
|
|
39
40
|
|
|
40
|
-
this.
|
|
41
|
+
this.loggerService.info({ message: '${name} updated.', obj: { ${name}: input } });
|
|
41
42
|
|
|
42
43
|
const updated = await this.${name}Repository.findById<DatabaseOptionsType>(entity.id);
|
|
43
44
|
|
|
@@ -8,24 +8,25 @@ import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name
|
|
|
8
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
|
+
import { IUsecase } from '@/utils/usecase';
|
|
11
12
|
|
|
12
|
-
export abstract class I${capitalizeFirstLetter(name)}CreateAdapter {
|
|
13
|
+
export abstract class I${capitalizeFirstLetter(name)}CreateAdapter implements IUsecase {
|
|
13
14
|
abstract execute(input: ${capitalizeFirstLetter(name)}CreateInput): Promise<${capitalizeFirstLetter(name)}CreateOutput>;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export abstract class I${capitalizeFirstLetter(name)}UpdateAdapter {
|
|
17
|
+
export abstract class I${capitalizeFirstLetter(name)}UpdateAdapter implements IUsecase {
|
|
17
18
|
abstract execute(input: ${capitalizeFirstLetter(name)}UpdateInput): Promise<${capitalizeFirstLetter(name)}UpdateOutput>;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export abstract class I${capitalizeFirstLetter(name)}GetByIDAdapter {
|
|
21
|
+
export abstract class I${capitalizeFirstLetter(name)}GetByIDAdapter implements IUsecase {
|
|
21
22
|
abstract execute(input: ${capitalizeFirstLetter(name)}GetByIDInput): Promise<${capitalizeFirstLetter(name)}GetByIDOutput>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export abstract class I${capitalizeFirstLetter(name)}ListAdapter {
|
|
25
|
+
export abstract class I${capitalizeFirstLetter(name)}ListAdapter implements IUsecase {
|
|
25
26
|
abstract execute(input: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput>;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export abstract class I${capitalizeFirstLetter(name)}DeleteAdapter {
|
|
29
|
+
export abstract class I${capitalizeFirstLetter(name)}DeleteAdapter implements IUsecase {
|
|
29
30
|
abstract execute(input: ${capitalizeFirstLetter(name)}DeleteInput): Promise<${capitalizeFirstLetter(name)}DeleteOutput>;
|
|
30
31
|
}
|
|
31
32
|
`
|
|
@@ -7,7 +7,7 @@ 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 '@/
|
|
10
|
+
import { Roles } from '@/utils/decorators';
|
|
11
11
|
import { ${capitalizeFirstLetter(name)}CreateInput, ${capitalizeFirstLetter(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
|
|
12
12
|
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
|
|
13
13
|
import { ${capitalizeFirstLetter(name)}GetByIDInput, ${capitalizeFirstLetter(name)}GetByIDOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
I${capitalizeFirstLetter(name)}ListAdapter,
|
|
26
26
|
I${capitalizeFirstLetter(name)}UpdateAdapter
|
|
27
27
|
} from './adapter';
|
|
28
|
-
import {
|
|
28
|
+
import { SwaggerRequest, SwaggerResponse } from './swagger';
|
|
29
29
|
|
|
30
30
|
@Controller('${pluralize(name)}')
|
|
31
31
|
@ApiTags('${pluralize(name)}')
|
|
@@ -41,34 +41,34 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
41
41
|
) {}
|
|
42
42
|
|
|
43
43
|
@Post()
|
|
44
|
-
@ApiResponse(
|
|
45
|
-
@ApiBody(
|
|
44
|
+
@ApiResponse(SwaggerResponse.create[200])
|
|
45
|
+
@ApiBody(SwaggerRequest.createBody)
|
|
46
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
50
|
@Put()
|
|
51
|
-
@ApiResponse(
|
|
52
|
-
@ApiResponse(
|
|
53
|
-
@ApiBody(
|
|
51
|
+
@ApiResponse(SwaggerResponse.update[200])
|
|
52
|
+
@ApiResponse(SwaggerResponse.update[404])
|
|
53
|
+
@ApiBody(SwaggerRequest.updateBody)
|
|
54
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
58
|
@Get('/:id')
|
|
59
59
|
@ApiParam({ name: 'id', required: true })
|
|
60
|
-
@ApiResponse(
|
|
61
|
-
@ApiResponse(
|
|
60
|
+
@ApiResponse(SwaggerResponse.getByID[200])
|
|
61
|
+
@ApiResponse(SwaggerResponse.getByID[404])
|
|
62
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
66
|
@Get()
|
|
67
|
-
@ApiQuery(
|
|
68
|
-
@ApiQuery(
|
|
69
|
-
@ApiQuery(
|
|
70
|
-
@ApiQuery(
|
|
71
|
-
@ApiResponse(
|
|
67
|
+
@ApiQuery(SwaggerRequest.listQuery.pagination.limit)
|
|
68
|
+
@ApiQuery(SwaggerRequest.listQuery.pagination.page)
|
|
69
|
+
@ApiQuery(SwaggerRequest.listQuery.sort)
|
|
70
|
+
@ApiQuery(SwaggerRequest.listQuery.search)
|
|
71
|
+
@ApiResponse(SwaggerResponse.list[200])
|
|
72
72
|
async list(@Req() { query }: ApiRequest): Promise<${capitalizeFirstLetter(name)}ListOutput> {
|
|
73
73
|
const input: ${capitalizeFirstLetter(name)}ListInput = {
|
|
74
74
|
sort: SortHttpSchema.parse(query.sort),
|
|
@@ -82,8 +82,8 @@ export class ${capitalizeFirstLetter(name)}Controller {
|
|
|
82
82
|
|
|
83
83
|
@Delete('/:id')
|
|
84
84
|
@ApiParam({ name: 'id', required: true })
|
|
85
|
-
@ApiResponse(
|
|
86
|
-
@ApiResponse(
|
|
85
|
+
@ApiResponse(SwaggerResponse.delete[200])
|
|
86
|
+
@ApiResponse(SwaggerResponse.delete[404])
|
|
87
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
|
}
|
|
@@ -6,7 +6,7 @@ function capitalizeFirstLetter(string) {
|
|
|
6
6
|
const getModule = (name) => `import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
|
7
7
|
import { ModelCtor, Sequelize } from 'sequelize-typescript';
|
|
8
8
|
|
|
9
|
-
import { IsLoggedMiddleware } from '@/
|
|
9
|
+
import { IsLoggedMiddleware } from '@/observables/middlewares';
|
|
10
10
|
import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
11
11
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
12
12
|
import { ${capitalizeFirstLetter(name)}CreateUsecase } from '@/core/${name}/use-cases/${name}-create';
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
ConvertPaginateInputToSequelizeFilter,
|
|
12
12
|
SearchTypeEnum,
|
|
13
13
|
ValidateDatabaseSortAllowed
|
|
14
|
-
} from '@/
|
|
14
|
+
} from '@/utils/decorators';
|
|
15
15
|
import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
16
16
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
17
17
|
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
|
|
@@ -19,7 +19,7 @@ const input = new ${capitalizeFirstLetter(name)}Entity({
|
|
|
19
19
|
|
|
20
20
|
const output = new ${capitalizeFirstLetter(name)}Entity({ ...input, updatedAt: new Date(), createdAt: new Date(), deletedAt: null });
|
|
21
21
|
|
|
22
|
-
export const
|
|
22
|
+
export const SwaggerResponse = {
|
|
23
23
|
create: {
|
|
24
24
|
200: Swagger.defaultResponseJSON({
|
|
25
25
|
status: 200,
|
|
@@ -75,7 +75,7 @@ export const SwagggerResponse = {
|
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
export const
|
|
78
|
+
export const SwaggerRequest = {
|
|
79
79
|
createBody: Swagger.defaultRequestJSON({ ...input, id: undefined } as ${capitalizeFirstLetter(name)}Entity),
|
|
80
80
|
updateBody: Swagger.defaultRequestJSON({ ...input, id: '<id>' } as ${capitalizeFirstLetter(name)}Entity),
|
|
81
81
|
listQuery: {
|