@mikemajesty/microservice-crud 4.5.9 → 4.5.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikemajesty/microservice-crud",
3
- "version": "4.5.9",
3
+ "version": "4.5.10",
4
4
  "description": "Monorepo CLI",
5
5
  "main": "src/cli.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@ const getModuleControllerModule = (name) => `import { Controller, Get, Req } fro
9
9
  import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
10
10
 
11
11
  import { Roles } from '@/utils/decorators';
12
- import { UserRole } from '@/core/user/entity/user';
12
+ import { UserRoleEnum } from '@/core/user/entity/user';
13
13
  import { ApiRequest } from '@/utils/request';
14
14
 
15
15
  import { SwagggerResponse } from './swagger';
@@ -17,7 +17,7 @@ import { SwagggerResponse } from './swagger';
17
17
  @Controller('${pluralize(name)}')
18
18
  @ApiTags('${name}')
19
19
  @ApiBearerAuth()
20
- @Roles(UserRole.USER)
20
+ @Roles(UserRoleEnum.USER)
21
21
  export class ${capitalizeFirstLetter(name)}Controller {
22
22
  @Get()
23
23
  @ApiResponse(SwagggerResponse.get[200])
@@ -13,7 +13,7 @@ import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name
13
13
  import { ${capitalizeFirstLetter(name)}GetByIDInput, ${capitalizeFirstLetter(name)}GetByIDOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
14
14
  import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
15
15
  import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
16
- import { UserRole } from '@/core/user/entity/user';
16
+ import { UserRoleEnum } from '@/core/user/entity/user';
17
17
  import { ApiRequest } from '@/utils/request';
18
18
  import { SearchHttpSchema } from '@/utils/search';
19
19
  import { SortHttpSchema } from '@/utils/sort';
@@ -30,7 +30,7 @@ import { SwaggerRequest, SwaggerResponse } from './swagger';
30
30
  @Controller('/${pluralize(name)}')
31
31
  @ApiTags('${pluralize(name)}')
32
32
  @ApiBearerAuth()
33
- @Roles(UserRole.USER)
33
+ @Roles(UserRoleEnum.USER)
34
34
  export class ${capitalizeFirstLetter(name)}Controller {
35
35
  constructor(
36
36
  private readonly ${name}CreateUsecase: I${capitalizeFirstLetter(name)}CreateAdapter,
@@ -47,12 +47,13 @@ export class ${capitalizeFirstLetter(name)}Controller {
47
47
  return this.${name}CreateUsecase.execute(body as ${capitalizeFirstLetter(name)}CreateInput);
48
48
  }
49
49
 
50
- @Put()
50
+ @Put(':id')
51
51
  @ApiResponse(SwaggerResponse.update[200])
52
52
  @ApiResponse(SwaggerResponse.update[404])
53
53
  @ApiBody(SwaggerRequest.updateBody)
54
- async update(@Req() { body }: ApiRequest): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
55
- return this.${name}UpdateUsecase.execute(body as ${capitalizeFirstLetter(name)}UpdateInput);
54
+ @ApiParam({ name: 'id', required: true })
55
+ async update(@Req() { body, params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
56
+ return this.${name}UpdateUsecase.execute({ ...body, id: params.id } as ${capitalizeFirstLetter(name)}UpdateInput);
56
57
  }
57
58
 
58
59
  @Get()
@@ -35,7 +35,7 @@ export const SwaggerResponse = {
35
35
  }),
36
36
  404: Swagger.defaultResponseError({
37
37
  status: 404,
38
- route: 'api/${pluralize(name)}',
38
+ route: 'api/v1/${pluralize(name)}',
39
39
  message: '${name}NotFound',
40
40
  description: '${name} not found.'
41
41
  })
@@ -48,7 +48,7 @@ export const SwaggerResponse = {
48
48
  }),
49
49
  404: Swagger.defaultResponseError({
50
50
  status: 404,
51
- route: 'api/${pluralize(name)}/:id',
51
+ route: 'api/v1/${pluralize(name)}/:id',
52
52
  message: '${name}NotFound',
53
53
  description: '${name} not found.'
54
54
  })
@@ -61,7 +61,7 @@ export const SwaggerResponse = {
61
61
  }),
62
62
  404: Swagger.defaultResponseError({
63
63
  status: 404,
64
- route: 'api/${pluralize(name)}/:id',
64
+ route: 'api/v1/${pluralize(name)}/:id',
65
65
  message: '${name}NotFound',
66
66
  description: '${name} not found.'
67
67
  })
@@ -3,17 +3,13 @@ function capitalizeFirstLetter(string) {
3
3
  return string.charAt(0).toUpperCase() + string.slice(1);
4
4
  }
5
5
 
6
- const getCoreRepository = (name) => `import { Transaction } from 'sequelize';
7
-
8
- import { IRepository } from '@/infra/repository';
9
- import { DatabaseOptionsType } from '@/utils/database/sequelize';
6
+ const getCoreRepository = (name) => `import { IRepository } from '@/infra/repository';
10
7
 
11
8
  import { ${capitalizeFirstLetter(name)}Entity } from '../entity/${name}';
12
9
  import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '../use-cases/${name}-list';
13
10
 
14
11
  export abstract class I${capitalizeFirstLetter(name)}Repository extends IRepository<${capitalizeFirstLetter(name)}Entity> {
15
- abstract paginate<TOptions = DatabaseOptionsType>(input: ${capitalizeFirstLetter(name)}ListInput, options?: TOptions): Promise<${capitalizeFirstLetter(name)}ListOutput>;
16
- abstract startSession<TTransaction = Transaction>(): Promise<TTransaction>;
12
+ abstract paginate(input: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput>;
17
13
  }
18
14
  `
19
15
 
@@ -64,22 +64,9 @@ describe('${capitalizeFirstLetter(name)}CreateUsecase', () => {
64
64
  const createOutput: ${capitalizeFirstLetter(name)}CreateOutput = { created: true, id: getMockUUID() };
65
65
 
66
66
  repository.create = jest.fn().mockResolvedValue(createOutput);
67
- repository.startSession = jest.fn().mockResolvedValue({
68
- commit: jest.fn()
69
- });
70
-
67
+
71
68
  await expect(usecase.execute(successInput)).resolves.toEqual(createOutput);
72
69
  });
73
-
74
- test('when transaction throw an error, should expect an error', async () => {
75
- repository.startSession = jest.fn().mockResolvedValue({
76
- commit: jest.fn(),
77
- rollback: jest.fn()
78
- });
79
- repository.create = jest.fn().mockRejectedValue(new ApiInternalServerException());
80
-
81
- await expect(usecase.execute(successInput)).rejects.toThrow(ApiInternalServerException);
82
- });
83
70
  });
84
71
  `
85
72
 
@@ -8,7 +8,7 @@ const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
8
8
  import { ValidateSchema } from '@/utils/decorators';
9
9
  import { ILoggerAdapter } from '@/infra/logger';
10
10
  import { CreatedModel } from '@/infra/repository';
11
- import { DatabaseOptionsType } from '@/utils/database/sequelize';
11
+ ;
12
12
  import { IUsecase } from '@/utils/usecase';
13
13
 
14
14
  import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
@@ -28,19 +28,11 @@ export class ${capitalizeFirstLetter(name)}CreateUsecase implements IUsecase {
28
28
  async execute(input: ${capitalizeFirstLetter(name)}CreateInput): Promise<${capitalizeFirstLetter(name)}CreateOutput> {
29
29
  const entity = new ${capitalizeFirstLetter(name)}Entity(input);
30
30
 
31
- const transaction = await this.${name}Repository.startSession();
32
- try {
33
- const ${name} = await this.${name}Repository.create<DatabaseOptionsType>(entity, { transaction });
31
+ const ${name} = await this.${name}Repository.create(entity);
34
32
 
35
- await transaction.commit();
33
+ this.loggerService.info({ message: '${name} created.', obj: { ${name} } });
36
34
 
37
- this.loggerService.info({ message: '${name} created.', obj: { ${name} } });
38
-
39
- return ${name};
40
- } catch (error) {
41
- await transaction.rollback();
42
- throw error;
43
- }
35
+ return ${name};
44
36
  }
45
37
  }
46
38
  `
@@ -7,7 +7,7 @@ const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
7
7
 
8
8
  import { ValidateSchema } from '@/utils/decorators';
9
9
  import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
10
- import { DatabaseOptionsType } from '@/utils/database/sequelize';
10
+ ;
11
11
  import { ApiNotFoundException } from '@/utils/exception';
12
12
  import { IUsecase } from '@/utils/usecase';
13
13
 
@@ -25,7 +25,7 @@ export class ${capitalizeFirstLetter(name)}DeleteUsecase implements IUsecase {
25
25
 
26
26
  @ValidateSchema(${capitalizeFirstLetter(name)}DeleteSchema)
27
27
  async execute({ id }: ${capitalizeFirstLetter(name)}DeleteInput): Promise<${capitalizeFirstLetter(name)}DeleteOutput> {
28
- const model = await this.${name}Repository.findById<DatabaseOptionsType>(id);
28
+ const model = await this.${name}Repository.findById(id);
29
29
 
30
30
  if (!model) {
31
31
  throw new ApiNotFoundException();
@@ -7,7 +7,7 @@ const getCoreUsecaseGetByID = (name) => `import { z } from 'zod';
7
7
 
8
8
  import { ValidateSchema } from '@/utils/decorators';
9
9
  import { ${capitalizeFirstLetter(name)}EntitySchema } from '@/core/${name}/entity/${name}';
10
- import { DatabaseOptionsType } from '@/utils/database/sequelize';
10
+ ;
11
11
  import { ApiNotFoundException } from '@/utils/exception';
12
12
  import { IUsecase } from '@/utils/usecase';
13
13
 
@@ -26,7 +26,7 @@ export class ${capitalizeFirstLetter(name)}GetByIdUsecase implements IUsecase {
26
26
 
27
27
  @ValidateSchema(${capitalizeFirstLetter(name)}GetByIdSchema)
28
28
  async execute({ id }: ${capitalizeFirstLetter(name)}GetByIDInput): Promise<${capitalizeFirstLetter(name)}GetByIDOutput> {
29
- const ${name} = await this.${name}Repository.findById<DatabaseOptionsType>(id);
29
+ const ${name} = await this.${name}Repository.findById(id);
30
30
 
31
31
  if (!${name}) {
32
32
  throw new ApiNotFoundException();
@@ -8,7 +8,7 @@ const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
8
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
- import { DatabaseOptionsType } from '@/utils/database/sequelize';
11
+ ;
12
12
  import { ApiNotFoundException } from '@/utils/exception';
13
13
  import { IUsecase } from '@/utils/usecase';
14
14
 
@@ -26,7 +26,7 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
26
26
 
27
27
  @ValidateSchema(${capitalizeFirstLetter(name)}UpdateSchema)
28
28
  async execute(input: ${capitalizeFirstLetter(name)}UpdateInput): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
29
- const ${name} = await this.${name}Repository.findById<DatabaseOptionsType>(input.id);
29
+ const ${name} = await this.${name}Repository.findById(input.id);
30
30
 
31
31
  if (!${name}) {
32
32
  throw new ApiNotFoundException();
@@ -40,7 +40,7 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
40
40
 
41
41
  this.loggerService.info({ message: '${name} updated.', obj: { ${name}: input } });
42
42
 
43
- const updated = await this.${name}Repository.findById<DatabaseOptionsType>(entity.id);
43
+ const updated = await this.${name}Repository.findById(entity.id);
44
44
 
45
45
  return new ${capitalizeFirstLetter(name)}Entity(updated);
46
46
  }
@@ -13,7 +13,7 @@ import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name
13
13
  import { ${capitalizeFirstLetter(name)}GetByIDInput, ${capitalizeFirstLetter(name)}GetByIDOutput } from '@/core/${name}/use-cases/${name}-get-by-id';
14
14
  import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
15
15
  import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
16
- import { UserRole } from '@/core/user/entity/user';
16
+ import { UserRoleEnum } from '@/core/user/entity/user';
17
17
  import { ApiRequest } from '@/utils/request';
18
18
  import { SearchHttpSchema } from '@/utils/search';
19
19
  import { SortHttpSchema } from '@/utils/sort';
@@ -30,7 +30,7 @@ import { SwaggerRequest, SwaggerResponse } from './swagger';
30
30
  @Controller('${pluralize(name)}')
31
31
  @ApiTags('${pluralize(name)}')
32
32
  @ApiBearerAuth()
33
- @Roles(UserRole.USER)
33
+ @Roles(UserRoleEnum.USER)
34
34
  export class ${capitalizeFirstLetter(name)}Controller {
35
35
  constructor(
36
36
  private readonly ${name}Create: I${capitalizeFirstLetter(name)}CreateAdapter,
@@ -47,12 +47,13 @@ export class ${capitalizeFirstLetter(name)}Controller {
47
47
  return await this.${name}Create.execute(body as ${capitalizeFirstLetter(name)}CreateInput);
48
48
  }
49
49
 
50
- @Put()
50
+ @Put(':id')
51
51
  @ApiResponse(SwaggerResponse.update[200])
52
52
  @ApiResponse(SwaggerResponse.update[404])
53
53
  @ApiBody(SwaggerRequest.updateBody)
54
- async update(@Req() { body }: ApiRequest): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
55
- return await this.${name}Update.execute(body as ${capitalizeFirstLetter(name)}UpdateInput);
54
+ @ApiParam({ name: 'id', required: true })
55
+ async update(@Req() { body, params }: ApiRequest): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
56
+ return await this.${name}Update.execute({ ...body, id: params.id } as ${capitalizeFirstLetter(name)}UpdateInput);
56
57
  }
57
58
 
58
59
  @Get('/:id')
@@ -4,7 +4,8 @@ function capitalizeFirstLetter(string) {
4
4
  }
5
5
 
6
6
  const getModule = (name) => `import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
7
- import { ModelCtor, Sequelize } from 'sequelize-typescript';
7
+ import { getRepositoryToken, TypeOrmModule } from '@nestjs/typeorm';
8
+ import { Repository } from 'typeorm';
8
9
 
9
10
  import { IsLoggedMiddleware } from '@/observables/middlewares';
10
11
  import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
@@ -15,8 +16,6 @@ import { ${capitalizeFirstLetter(name)}GetByIdUsecase } from '@/core/${name}/use
15
16
  import { ${capitalizeFirstLetter(name)}ListUsecase } from '@/core/${name}/use-cases/${name}-list';
16
17
  import { ${capitalizeFirstLetter(name)}UpdateUsecase } from '@/core/${name}/use-cases/${name}-update';
17
18
  import { RedisCacheModule } from '@/infra/cache/redis';
18
- import { IDataBaseAdapter } from '@/infra/database';
19
- import { PostgresDatabaseModule } from '@/infra/database/postgres/module';
20
19
  import { ${capitalizeFirstLetter(name)}Schema } from '@/infra/database/postgres/schemas/${name}';
21
20
  import { ILoggerAdapter, LoggerModule } from '@/infra/logger';
22
21
  import { TokenLibModule } from '@/libs/token';
@@ -32,16 +31,15 @@ import { ${capitalizeFirstLetter(name)}Controller } from './controller';
32
31
  import { ${capitalizeFirstLetter(name)}Repository } from './repository';
33
32
 
34
33
  @Module({
35
- imports: [TokenLibModule, LoggerModule, RedisCacheModule, PostgresDatabaseModule],
34
+ imports: [TokenLibModule, LoggerModule, RedisCacheModule, TypeOrmModule.forFeature([${capitalizeFirstLetter(name)}Schema])],
36
35
  controllers: [${capitalizeFirstLetter(name)}Controller],
37
36
  providers: [
38
37
  {
39
38
  provide: I${capitalizeFirstLetter(name)}Repository,
40
- useFactory: (database: IDataBaseAdapter) => {
41
- const repossitory = database.getDatabase<Sequelize>().model(${capitalizeFirstLetter(name)}Schema);
42
- return new ${capitalizeFirstLetter(name)}Repository(repossitory as ModelCtor<${capitalizeFirstLetter(name)}Schema> & ${capitalizeFirstLetter(name)}Entity);
39
+ useFactory: (repository: Repository<${capitalizeFirstLetter(name)}Schema & ${capitalizeFirstLetter(name)}Entity>) => {
40
+ return new ${capitalizeFirstLetter(name)}Repository(repository);
43
41
  },
44
- inject: [IDataBaseAdapter]
42
+ inject: [getRepositoryToken(${capitalizeFirstLetter(name)}Schema)]
45
43
  },
46
44
  {
47
45
  provide: I${capitalizeFirstLetter(name)}CreateAdapter,
@@ -4,43 +4,39 @@ function capitalizeFirstLetter(string) {
4
4
  }
5
5
 
6
6
  const getModuleRepository = (name) => `import { Injectable } from '@nestjs/common';
7
- import { Transaction } from 'sequelize';
8
- import { ModelCtor } from 'sequelize-typescript';
9
-
10
- import {
11
- ConvertPaginateInputToSequelizeFilter,
12
- SearchTypeEnum,
13
- ValidateDatabaseSortAllowed
14
- } from '@/utils/decorators';
7
+ import { FindOptionsWhere, Repository } from 'typeorm';
8
+
15
9
  import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
16
10
  import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
17
11
  import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
18
12
  import { ${capitalizeFirstLetter(name)}Schema } from '@/infra/database/postgres/schemas/${name}';
19
- import { SequelizeRepository } from '@/infra/repository/postgres/repository';
20
- import { DatabaseOptionsSchema, DatabaseOptionsType } from '@/utils/database/sequelize';
13
+ import { TypeORMRepository } from '@/infra/repository/postgres/repository';
14
+ import { SearchTypeEnum, ValidateDatabaseSortAllowed, ValidateMongooseFilter } from '@/utils/decorators';
15
+ import { calculateSkip } from '@/utils/pagination';
21
16
 
22
- type Model = ModelCtor<${capitalizeFirstLetter(name)}Schema> & ${capitalizeFirstLetter(name)}Entity;
17
+ type Model = ${capitalizeFirstLetter(name)}Schema & ${capitalizeFirstLetter(name)}Entity;
23
18
 
24
19
  @Injectable()
25
- export class ${capitalizeFirstLetter(name)}Repository extends SequelizeRepository<Model> implements I${capitalizeFirstLetter(name)}Repository {
26
- constructor(readonly repository: Model) {
20
+ export class ${capitalizeFirstLetter(name)}Repository extends TypeORMRepository<Model> implements I${capitalizeFirstLetter(name)}Repository {
21
+ constructor(readonly repository: Repository<Model>) {
27
22
  super(repository);
28
23
  }
29
24
 
30
- async startSession<TTransaction = Transaction>(): Promise<TTransaction> {
31
- const transaction = await this.repository.sequelize.transaction();
32
-
33
- return transaction as TTransaction;
34
- }
35
-
36
- @ValidateDatabaseSortAllowed('createdAt', 'name')
37
- @ConvertPaginateInputToSequelizeFilter([{ name: 'name', type: SearchTypeEnum.like }])
38
- async paginate(input: ${capitalizeFirstLetter(name)}ListInput, options: DatabaseOptionsType): Promise<${capitalizeFirstLetter(name)}ListOutput> {
39
- const { schema } = DatabaseOptionsSchema.parse(options);
40
-
41
- const list = await this.repository.schema(schema).findAndCountAll(input);
42
-
43
- return { docs: list.rows.map((r) => new ${capitalizeFirstLetter(name)}Entity(r)), limit: input.limit, page: input.page, total: list.count };
25
+ @ValidateMongooseFilter<${capitalizeFirstLetter(name)}Entity>([
26
+ { name: 'name', type: SearchTypeEnum.like },
27
+ ])
28
+ @ValidateDatabaseSortAllowed<${capitalizeFirstLetter(name)}Entity>('name', 'createdAt')
29
+ async paginate(input: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput> {
30
+ const skip = calculateSkip(input);
31
+
32
+ const [docs, total] = await this.repository.findAndCount({
33
+ take: input.limit,
34
+ skip,
35
+ order: input.sort,
36
+ where: input.search as FindOptionsWhere<unknown>
37
+ });
38
+
39
+ return { docs, total, page: input.page, limit: input.limit };
44
40
  }
45
41
  }
46
42
  `
@@ -35,7 +35,7 @@ export const SwaggerResponse = {
35
35
  }),
36
36
  404: Swagger.defaultResponseError({
37
37
  status: 404,
38
- route: 'api/${pluralize(name)}',
38
+ route: 'api/v1/${pluralize(name)}',
39
39
  message: '${name}NotFound',
40
40
  description: '${name} not found.'
41
41
  })
@@ -48,7 +48,7 @@ export const SwaggerResponse = {
48
48
  }),
49
49
  404: Swagger.defaultResponseError({
50
50
  status: 404,
51
- route: 'api/${pluralize(name)}/:id',
51
+ route: 'api/v1/${pluralize(name)}/:id',
52
52
  message: '${name}NotFound',
53
53
  description: '${name} not found.'
54
54
  })
@@ -61,7 +61,7 @@ export const SwaggerResponse = {
61
61
  }),
62
62
  404: Swagger.defaultResponseError({
63
63
  status: 404,
64
- route: 'api/${pluralize(name)}/:id',
64
+ route: 'api/v1/${pluralize(name)}/:id',
65
65
  message: '${name}NotFound',
66
66
  description: '${name} not found.'
67
67
  })
@@ -5,18 +5,32 @@ function capitalizeFirstLetter(string) {
5
5
  return string.charAt(0).toUpperCase() + string.slice(1);
6
6
  }
7
7
 
8
- const getModuleSchema = (name) => `import { Column, DataType, Model, Table } from 'sequelize-typescript';
8
+ const getModuleSchema = (name) => `import {
9
+ BaseEntity,
10
+ Column,
11
+ CreateDateColumn,
12
+ DeleteDateColumn,
13
+ Entity,
14
+ UpdateDateColumn
15
+ } from 'typeorm';
9
16
 
10
- @Table({ timestamps: true, tableName: '${pluralize(name)}', underscored: true })
11
- export class ${capitalizeFirstLetter(name)}Schema extends Model {
12
- @Column({ primaryKey: true, type: DataType.UUID })
17
+
18
+ @Entity({ name: '${pluralize(name)}' })
19
+ export class ${capitalizeFirstLetter(name)}Schema extends BaseEntity {
20
+ @Column({ type: 'uuid', primary: true })
13
21
  id: string;
14
22
 
15
- @Column(DataType.STRING)
23
+ @Column('text')
16
24
  name: string;
17
25
 
18
- @Column({ allowNull: true, type: DataType.DATE })
19
- deletedAt?: Date;
26
+ @CreateDateColumn()
27
+ createdAt: Date;
28
+
29
+ @UpdateDateColumn()
30
+ updatedAt: Date;
31
+
32
+ @DeleteDateColumn({ nullable: true })
33
+ deletedAt: Date;
20
34
  }
21
35
  `
22
36