@mikemajesty/microservice-crud 6.0.8 → 6.0.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": "6.0.8",
3
+ "version": "6.0.10",
4
4
  "description": "Monorepo CLI",
5
5
  "main": "src/cli.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@ const ID = z.string().uuid();
11
11
  const Name = z.string().min(1).max(200).trim();
12
12
  const CreatedAt = z.date().nullish();
13
13
  const UpdatedAt = z.date().nullish();
14
- const DeletedAt = z.date().default(null).nullish();
14
+ const DeletedAt = z.date().nullish();
15
15
 
16
16
  export const ${capitalizeFirstLetter(name)}EntitySchema = z.object({
17
17
  id: ID,
@@ -21,11 +21,14 @@ export type ${capitalizeFirstLetter(name)}UpdateInput = Partial<z.infer<typeof $
21
21
  export type ${capitalizeFirstLetter(name)}UpdateOutput = ${capitalizeFirstLetter(name)}Entity;
22
22
 
23
23
  export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
24
- constructor(private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository, private readonly loggerService: ILoggerAdapter) {}
24
+ constructor(
25
+ private readonly ${name}Repository: I${capitalizeFirstLetter(name)}Repository,
26
+ private readonly loggerService: ILoggerAdapter
27
+ ) {}
25
28
 
26
29
  @ValidateSchema(${capitalizeFirstLetter(name)}UpdateSchema)
27
30
  async execute(input: ${capitalizeFirstLetter(name)}UpdateInput): Promise<${capitalizeFirstLetter(name)}UpdateOutput> {
28
- const ${name} = await this.${name}Repository.findById(input.id);
31
+ const ${name} = await this.${name}Repository.findById(input.id as string);
29
32
 
30
33
  if (!${name}) {
31
34
  throw new ApiNotFoundException('${name}NotFound');
@@ -6,14 +6,15 @@ function capitalizeFirstLetter(string) {
6
6
 
7
7
  const getModuleRepository = (name) => `import { Injectable } from '@nestjs/common';
8
8
  import { InjectModel } from '@nestjs/mongoose';
9
- import { PaginateModel } from 'mongoose';
9
+ import { FilterQuery, PaginateModel } from 'mongoose';
10
10
 
11
11
  import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
12
12
  import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
13
13
  import { ${capitalizeFirstLetter(name)}, ${capitalizeFirstLetter(name)}Document } from '@/infra/database/mongo/schemas/${name}';
14
14
  import { MongoRepository } from '@/infra/repository';
15
- import { MongoRepositoryModelSessionType } from '@/utils/mongoose';
16
15
  import { ConvertMongooseFilter, SearchTypeEnum, ValidateDatabaseSortAllowed } from '@/utils/decorators';
16
+ import { IEntity } from '@/utils/entity';
17
+ import { MongoRepositoryModelSessionType } from '@/utils/mongoose';
17
18
 
18
19
  @Injectable()
19
20
  export class ${capitalizeFirstLetter(name)}Repository extends MongoRepository<${capitalizeFirstLetter(name)}Document> implements I${capitalizeFirstLetter(name)}Repository {
@@ -24,7 +25,11 @@ export class ${capitalizeFirstLetter(name)}Repository extends MongoRepository<${
24
25
  @ConvertMongooseFilter([{ name: 'name', type: SearchTypeEnum.like }])
25
26
  @ValidateDatabaseSortAllowed({ name: 'name' }, { name: 'createdAt' })
26
27
  async paginate({ limit, page, sort, search }: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput> {
27
- const ${pluralize(name)} = await this.entity.paginate(search, { page, limit, sort });
28
+ const ${pluralize(name)} = await this.entity.paginate(search as FilterQuery<IEntity>, {
29
+ page,
30
+ limit,
31
+ sort
32
+ });
28
33
 
29
34
  return { docs: ${pluralize(name)}.docs.map((u) => u.toObject({ virtuals: true })), limit, page, total: ${name}s.totalDocs };
30
35
  }
@@ -12,8 +12,10 @@ import { ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-
12
12
  import { ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
13
13
  import { ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
14
14
  import { Swagger } from '@/utils/docs/swagger';
15
+ import { TestUtils } from '@/utils/tests';
15
16
 
16
17
  const input = new ${capitalizeFirstLetter(name)}Entity({
18
+ id: TestUtils.getMockUUID(),
17
19
  name: 'name'
18
20
  });
19
21
 
@@ -78,7 +80,7 @@ export const SwaggerResponse = {
78
80
  };
79
81
 
80
82
  export const SwaggerRequest = {
81
- createBody: Swagger.defaultRequestJSON({ ...input, id: undefined } as ${capitalizeFirstLetter(name)}Entity),
83
+ createBody: Swagger.defaultRequestJSON(input as ${capitalizeFirstLetter(name)}Entity),
82
84
  updateBody: Swagger.defaultRequestJSON(input as ${capitalizeFirstLetter(name)}Entity),
83
85
  listQuery: Swagger.defaultRequestListJSON()
84
86
  };
@@ -11,7 +11,7 @@ const ID = z.string().uuid();
11
11
  const Name = z.string().min(1).max(200).trim();
12
12
  const CreatedAt = z.date().nullish();
13
13
  const UpdatedAt = z.date().nullish();
14
- const DeletedAt = z.date().default(null).nullish();
14
+ const DeletedAt = z.date().nullish();
15
15
 
16
16
  export const ${capitalizeFirstLetter(name)}EntitySchema = z.object({
17
17
  id: ID,
@@ -44,7 +44,7 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
44
44
 
45
45
  const updated = await this.${name}Repository.findById(entity.id);
46
46
 
47
- return new ${capitalizeFirstLetter(name)}Entity(updated as ${capitalizeFirstLetter(name)});
47
+ return new ${capitalizeFirstLetter(name)}Entity(updated as ${capitalizeFirstLetter(name)}Entity);
48
48
  }
49
49
  }
50
50
  `
@@ -4,7 +4,7 @@ function capitalizeFirstLetter(string) {
4
4
  }
5
5
 
6
6
  const getModuleRepository = (name) => `import { Injectable } from '@nestjs/common';
7
- import { FindOptionsWhere, Repository } from 'typeorm';
7
+ import { FindOptionsOrder, FindOptionsWhere, Repository } from 'typeorm';
8
8
 
9
9
  import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
10
10
  import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
@@ -12,6 +12,7 @@ import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}
12
12
  import { ${capitalizeFirstLetter(name)}Schema } from '@/infra/database/postgres/schemas/${name}';
13
13
  import { TypeORMRepository } from '@/infra/repository/postgres/repository';
14
14
  import { ConvertTypeOrmFilter, SearchTypeEnum, ValidateDatabaseSortAllowed } from '@/utils/decorators';
15
+ import { IEntity } from '@/utils/entity';
15
16
  import { PaginationUtils } from '@/utils/pagination';
16
17
 
17
18
  type Model = ${capitalizeFirstLetter(name)}Schema & ${capitalizeFirstLetter(name)}Entity;
@@ -30,8 +31,8 @@ export class ${capitalizeFirstLetter(name)}Repository extends TypeORMRepository<
30
31
  const [docs, total] = await this.repository.findAndCount({
31
32
  take: input.limit,
32
33
  skip,
33
- order: input.sort,
34
- where: input.search as FindOptionsWhere<unknown>
34
+ order: input.sort as FindOptionsOrder<IEntity>,
35
+ where: input.search as FindOptionsWhere<IEntity>
35
36
  });
36
37
 
37
38
  return { docs, total, page: input.page, limit: input.limit };
@@ -12,8 +12,10 @@ import { ${capitalizeFirstLetter(name)}GetByIdOutput } from '@/core/${name}/use-
12
12
  import { ${capitalizeFirstLetter(name)}ListOutput } from '@/core/${name}/use-cases/${name}-list';
13
13
  import { ${capitalizeFirstLetter(name)}UpdateOutput } from '@/core/${name}/use-cases/${name}-update';
14
14
  import { Swagger } from '@/utils/docs/swagger';
15
+ import { TestUtils } from '@/utils/tests';
15
16
 
16
17
  const input = new ${capitalizeFirstLetter(name)}Entity({
18
+ id: TestUtils.getMockUUID(),
17
19
  name: 'name'
18
20
  });
19
21
 
@@ -78,7 +80,7 @@ export const SwaggerResponse = {
78
80
  };
79
81
 
80
82
  export const SwaggerRequest = {
81
- createBody: Swagger.defaultRequestJSON({ ...input, id: undefined } as ${capitalizeFirstLetter(name)}Entity),
83
+ createBody: Swagger.defaultRequestJSON(input as ${capitalizeFirstLetter(name)}Entity),
82
84
  updateBody: Swagger.defaultRequestJSON(input as ${capitalizeFirstLetter(name)}Entity),
83
85
  listQuery: Swagger.defaultRequestListJSON()
84
86
  };