@mikemajesty/microservice-crud 5.0.4 → 5.0.6
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 +2 -1
- package/src/templates/mongo/core/entity/entity.js +2 -2
- package/src/templates/mongo/core/repository/repository.js +0 -2
- package/src/templates/mongo/core/use-cases/__tests__/create.spec.js +3 -4
- package/src/templates/mongo/core/use-cases/__tests__/delete.spec.js +7 -7
- package/src/templates/mongo/core/use-cases/__tests__/get-by-id.spec.js +7 -7
- package/src/templates/mongo/core/use-cases/__tests__/list.spec.js +16 -14
- package/src/templates/mongo/core/use-cases/__tests__/update.spec.js +7 -7
- package/src/templates/mongo/core/use-cases/update.js +3 -3
- package/src/templates/mongo/modules/repository.js +1 -8
- package/src/templates/postgres/core/entity/entity.js +2 -2
- package/src/templates/postgres/core/use-cases/__tests__/create.spec.js +3 -4
- package/src/templates/postgres/core/use-cases/__tests__/delete.spec.js +8 -8
- package/src/templates/postgres/core/use-cases/__tests__/get-by-id.spec.js +8 -7
- package/src/templates/postgres/core/use-cases/__tests__/list.spec.js +16 -14
- package/src/templates/postgres/core/use-cases/__tests__/update.spec.js +8 -8
- package/src/templates/postgres/core/use-cases/create.js +1 -2
- package/src/templates/postgres/core/use-cases/delete.js +1 -2
- package/src/templates/postgres/core/use-cases/get-by-id.js +1 -2
- package/src/templates/postgres/core/use-cases/list.js +1 -1
- package/src/templates/postgres/core/use-cases/update.js +3 -4
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -359,7 +359,8 @@ export async function cli(args) {
|
|
|
359
359
|
|
|
360
360
|
try {
|
|
361
361
|
|
|
362
|
-
const dest = path.resolve(`${__dirname}/../../../../`)
|
|
362
|
+
// const dest = path.resolve(`${__dirname}/../../../../`)
|
|
363
|
+
const dest = '/home/mike/Documents/pessoal/nestjs-microservice-boilerplate-api'
|
|
363
364
|
|
|
364
365
|
const src = paths[0]
|
|
365
366
|
|
|
@@ -23,11 +23,11 @@ export const ${capitalizeFirstLetter(name)}EntitySchema = z.object({
|
|
|
23
23
|
|
|
24
24
|
type ${capitalizeFirstLetter(name)} = z.infer<typeof ${capitalizeFirstLetter(name)}EntitySchema>;
|
|
25
25
|
|
|
26
|
-
export class ${capitalizeFirstLetter(name)}Entity extends BaseEntity<${capitalizeFirstLetter(name)}Entity>(
|
|
26
|
+
export class ${capitalizeFirstLetter(name)}Entity extends BaseEntity<${capitalizeFirstLetter(name)}Entity>() {
|
|
27
27
|
name: string;
|
|
28
28
|
|
|
29
29
|
constructor(entity: ${capitalizeFirstLetter(name)}) {
|
|
30
|
-
super();
|
|
30
|
+
super(${capitalizeFirstLetter(name)}EntitySchema);
|
|
31
31
|
Object.assign(this, this.validate(entity));
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -4,14 +4,12 @@ function capitalizeFirstLetter(string) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
const getCoreRepository = (name) => `import { IRepository } from '@/infra/repository';
|
|
7
|
-
import { MongoRepositorySession } from '@/utils/database/mongoose';
|
|
8
7
|
|
|
9
8
|
import { ${capitalizeFirstLetter(name)}Entity } from '../entity/${name}';
|
|
10
9
|
import { ${capitalizeFirstLetter(name)}ListInput, ${capitalizeFirstLetter(name)}ListOutput } from '../use-cases/${name}-list';
|
|
11
10
|
|
|
12
11
|
export abstract class I${capitalizeFirstLetter(name)}Repository extends IRepository<${capitalizeFirstLetter(name)}Entity> {
|
|
13
12
|
abstract paginate(input: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput>;
|
|
14
|
-
abstract startSession(): Promise<MongoRepositorySession>;
|
|
15
13
|
}
|
|
16
14
|
`
|
|
17
15
|
|
|
@@ -58,12 +58,11 @@ describe(${capitalizeFirstLetter(name)}CreateUsecase.name, () => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
test('when ${name} created successfully, should expect a ${name}', async () => {
|
|
61
|
-
const
|
|
62
|
-
|
|
61
|
+
const output: ${capitalizeFirstLetter(name)}CreateOutput = { created: true, id: getMockUUID() };
|
|
63
62
|
repository.findOne = jest.fn().mockResolvedValue(null);
|
|
64
|
-
repository.create = jest.fn().mockResolvedValue(
|
|
63
|
+
repository.create = jest.fn().mockResolvedValue(output);
|
|
65
64
|
|
|
66
|
-
await expect(usecase.execute(input)).resolves.toEqual(
|
|
65
|
+
await expect(usecase.execute(input)).resolves.toEqual(output);
|
|
67
66
|
});
|
|
68
67
|
});
|
|
69
68
|
`
|
|
@@ -58,17 +58,17 @@ describe(${capitalizeFirstLetter(name)}DeleteUsecase.name, () => {
|
|
|
58
58
|
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
61
|
+
const ${name} = new ${capitalizeFirstLetter(name)}Entity({
|
|
62
|
+
id: getMockUUID(),
|
|
63
|
+
name: 'dummy'
|
|
64
|
+
});
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
test('when ${name} deleted successfully, should expect a ${name}', async () => {
|
|
67
|
+
repository.findById = jest.fn().mockResolvedValue(${name});
|
|
68
68
|
repository.updateOne = jest.fn();
|
|
69
69
|
|
|
70
70
|
await expect(usecase.execute(input)).resolves.toEqual({
|
|
71
|
-
|
|
71
|
+
...${name},
|
|
72
72
|
deletedAt: expect.any(Date)
|
|
73
73
|
});
|
|
74
74
|
});
|
|
@@ -58,15 +58,15 @@ describe(${capitalizeFirstLetter(name)}GetByIdUsecase.name, () => {
|
|
|
58
58
|
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
61
|
+
const ${name} = new ${capitalizeFirstLetter(name)}Entity({
|
|
62
|
+
id: '61cc35f3-03d9-4b7f-9c63-59f32b013ef5',
|
|
63
|
+
name: 'dummy'
|
|
64
|
+
});
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
test('when ${name} found, should expect a ${name}', async () => {
|
|
67
|
+
repository.findById = jest.fn().mockResolvedValue(${name});
|
|
68
68
|
|
|
69
|
-
await expect(usecase.execute(input)).resolves.toEqual(
|
|
69
|
+
await expect(usecase.execute(input)).resolves.toEqual(${name});
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
`
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
|
|
2
|
+
const pluralize = require('pluralize')
|
|
3
|
+
|
|
2
4
|
function capitalizeFirstLetter(string) {
|
|
3
5
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
6
|
}
|
|
@@ -49,20 +51,21 @@ describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
|
|
|
49
51
|
|
|
50
52
|
const input: ${capitalizeFirstLetter(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } };
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
54
|
+
const ${name} = new ${capitalizeFirstLetter(name)}Entity({
|
|
55
|
+
id: getMockUUID(),
|
|
56
|
+
name: 'dummy',
|
|
57
|
+
createdAt: new Date(),
|
|
58
|
+
updatedAt: new Date()
|
|
59
|
+
});
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
const ${pluralize(name)} = [${name}];
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
test('when ${name} are found, should expect an ${name} list', async () => {
|
|
64
|
+
const output: ${capitalizeFirstLetter(name)}ListOutput = { docs: ${pluralize(name)}, page: 1, limit: 1, total: 1 };
|
|
65
|
+
repository.paginate = jest.fn().mockResolvedValue(output);
|
|
63
66
|
|
|
64
67
|
await expect(usecase.execute(input)).resolves.toEqual({
|
|
65
|
-
docs:
|
|
68
|
+
docs: ${pluralize(name)},
|
|
66
69
|
page: 1,
|
|
67
70
|
limit: 1,
|
|
68
71
|
total: 1
|
|
@@ -70,11 +73,10 @@ describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
|
|
|
70
73
|
});
|
|
71
74
|
|
|
72
75
|
test('when ${name} not found, should expect an empty list', async () => {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
repository.paginate = jest.fn().mockResolvedValue(paginateOutput);
|
|
76
|
+
const output: ${capitalizeFirstLetter(name)}ListOutput = { docs: [], page: 1, limit: 1, total: 1 };
|
|
77
|
+
repository.paginate = jest.fn().mockResolvedValue(output);
|
|
76
78
|
|
|
77
|
-
await expect(usecase.execute(input)).resolves.toEqual(
|
|
79
|
+
await expect(usecase.execute(input)).resolves.toEqual(output);
|
|
78
80
|
});
|
|
79
81
|
});
|
|
80
82
|
`
|
|
@@ -59,16 +59,16 @@ describe(${capitalizeFirstLetter(name)}UpdateUsecase.name, () => {
|
|
|
59
59
|
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
62
|
+
const ${name}: ${capitalizeFirstLetter(name)}UpdateOutput = new ${capitalizeFirstLetter(name)}Entity({
|
|
63
|
+
id: getMockUUID(),
|
|
64
|
+
name: 'dummy'
|
|
65
|
+
});
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
test('when ${name} updated successfully, should expect an ${name}', async () => {
|
|
68
|
+
repository.findById = jest.fn().mockResolvedValue(${name});
|
|
69
69
|
repository.updateOne = jest.fn().mockResolvedValue(null);
|
|
70
70
|
|
|
71
|
-
await expect(usecase.execute(input)).resolves.toEqual(
|
|
71
|
+
await expect(usecase.execute(input)).resolves.toEqual(${name});
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
`
|
|
@@ -5,8 +5,8 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
9
8
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
9
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
10
10
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
11
11
|
import { IUsecase } from '@/utils/usecase';
|
|
12
12
|
|
|
@@ -31,9 +31,9 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
|
|
|
31
31
|
throw new ApiNotFoundException('${name}NotFound');
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const ${name}
|
|
34
|
+
const ${name}Found = new ${capitalizeFirstLetter(name)}Entity(${name});
|
|
35
35
|
|
|
36
|
-
const entity = new ${capitalizeFirstLetter(name)}Entity({ ...${name}
|
|
36
|
+
const entity = new ${capitalizeFirstLetter(name)}Entity({ ...${name}Found, ...input });
|
|
37
37
|
|
|
38
38
|
await this.${name}Repository.updateOne({ id: entity.id }, entity);
|
|
39
39
|
|
|
@@ -13,7 +13,7 @@ import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/reposi
|
|
|
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}';
|
|
15
15
|
import { MongoRepository } from '@/infra/repository';
|
|
16
|
-
import { MongoRepositoryModelSessionType
|
|
16
|
+
import { MongoRepositoryModelSessionType } from '@/utils/database/mongoose';
|
|
17
17
|
|
|
18
18
|
@Injectable()
|
|
19
19
|
export class ${capitalizeFirstLetter(name)}Repository extends MongoRepository<${capitalizeFirstLetter(name)}Document> implements I${capitalizeFirstLetter(name)}Repository {
|
|
@@ -21,13 +21,6 @@ export class ${capitalizeFirstLetter(name)}Repository extends MongoRepository<${
|
|
|
21
21
|
super(entity);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async startSession<TTransaction = MongoRepositorySession>(): Promise<TTransaction> {
|
|
25
|
-
const session = await this.entity.connection.startSession();
|
|
26
|
-
session.startTransaction();
|
|
27
|
-
|
|
28
|
-
return session as TTransaction;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
24
|
@ValidateMongooseFilter([{ name: 'name', type: SearchTypeEnum.like }])
|
|
32
25
|
@ValidateDatabaseSortAllowed('name', 'createdAt')
|
|
33
26
|
async paginate({ limit, page, sort, search }: ${capitalizeFirstLetter(name)}ListInput): Promise<${capitalizeFirstLetter(name)}ListOutput> {
|
|
@@ -23,11 +23,11 @@ export const ${capitalizeFirstLetter(name)}EntitySchema = z.object({
|
|
|
23
23
|
|
|
24
24
|
type ${capitalizeFirstLetter(name)} = z.infer<typeof ${capitalizeFirstLetter(name)}EntitySchema>;
|
|
25
25
|
|
|
26
|
-
export class ${capitalizeFirstLetter(name)}Entity extends BaseEntity<${capitalizeFirstLetter(name)}Entity>(
|
|
26
|
+
export class ${capitalizeFirstLetter(name)}Entity extends BaseEntity<${capitalizeFirstLetter(name)}Entity>() {
|
|
27
27
|
name: string;
|
|
28
28
|
|
|
29
29
|
constructor(entity: ${capitalizeFirstLetter(name)}) {
|
|
30
|
-
super();
|
|
30
|
+
super(${capitalizeFirstLetter(name)}EntitySchema);
|
|
31
31
|
Object.assign(this, ${capitalizeFirstLetter(name)}EntitySchema.parse(withID(entity)));
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -58,11 +58,10 @@ describe(${capitalizeFirstLetter(name)}CreateUsecase.name, () => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
test('when ${name} created successfully, should expect a ${name}', async () => {
|
|
61
|
-
const
|
|
61
|
+
const output: ${capitalizeFirstLetter(name)}CreateOutput = { created: true, id: getMockUUID() };
|
|
62
|
+
repository.create = jest.fn().mockResolvedValue(output);
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await expect(usecase.execute(input)).resolves.toEqual(createOutput);
|
|
64
|
+
await expect(usecase.execute(input)).resolves.toEqual(output);
|
|
66
65
|
});
|
|
67
66
|
});
|
|
68
67
|
`
|
|
@@ -5,7 +5,7 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseDeleteTest = (name) => `import { Test } from '@nestjs/testing';
|
|
7
7
|
|
|
8
|
-
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}
|
|
8
|
+
import { ${capitalizeFirstLetter(name)}DeleteInput, ${capitalizeFirstLetter(name)}DeleteUsecase } from '@/core/${name}/use-cases/${name}-delete';
|
|
9
9
|
import { I${capitalizeFirstLetter(name)}DeleteAdapter } from '@/modules/${name}/adapter';
|
|
10
10
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
11
11
|
import { expectZodError, getMockUUID } from '@/utils/tests';
|
|
@@ -57,17 +57,17 @@ describe(${capitalizeFirstLetter(name)}DeleteUsecase.name, () => {
|
|
|
57
57
|
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
60
|
+
const ${name} = new ${capitalizeFirstLetter(name)}Entity({
|
|
61
|
+
id: getMockUUID(),
|
|
62
|
+
name: 'dummy'
|
|
63
|
+
});
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
test('when ${name} deleted successfully, should expect a ${name}', async () => {
|
|
66
|
+
repository.findById = jest.fn().mockResolvedValue(${name});
|
|
67
67
|
repository.updateOne = jest.fn();
|
|
68
68
|
|
|
69
69
|
await expect(usecase.execute(input)).resolves.toEqual({
|
|
70
|
-
|
|
70
|
+
...${name},
|
|
71
71
|
deletedAt: expect.any(Date)
|
|
72
72
|
});
|
|
73
73
|
});
|
|
@@ -10,7 +10,7 @@ import { ApiNotFoundException } from '@/utils/exception';
|
|
|
10
10
|
import { expectZodError, getMockUUID } from '@/utils/tests';
|
|
11
11
|
|
|
12
12
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
13
|
-
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}
|
|
13
|
+
import { ${capitalizeFirstLetter(name)}GetByIdInput, ${capitalizeFirstLetter(name)}GetByIdUsecase } from '../${name}-get-by-id';
|
|
14
14
|
import { ${capitalizeFirstLetter(name)}Entity } from './../../entity/${name}';
|
|
15
15
|
|
|
16
16
|
describe(${capitalizeFirstLetter(name)}GetByIdUsecase.name, () => {
|
|
@@ -57,14 +57,15 @@ describe(${capitalizeFirstLetter(name)}GetByIdUsecase.name, () => {
|
|
|
57
57
|
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
+
const ${name} = new ${capitalizeFirstLetter(name)}Entity({
|
|
61
|
+
id: getMockUUID(),
|
|
62
|
+
name: 'dummy'
|
|
63
|
+
});
|
|
64
|
+
|
|
60
65
|
test('when ${name} found, should expect a ${name}', async () => {
|
|
61
|
-
|
|
62
|
-
id: getMockUUID(),
|
|
63
|
-
name: 'dummy'
|
|
64
|
-
});
|
|
65
|
-
repository.findById = jest.fn().mockResolvedValue(findByIdOutput);
|
|
66
|
+
repository.findById = jest.fn().mockResolvedValue(${name});
|
|
66
67
|
|
|
67
|
-
await expect(usecase.execute(input)).resolves.toEqual(
|
|
68
|
+
await expect(usecase.execute(input)).resolves.toEqual(${name});
|
|
68
69
|
});
|
|
69
70
|
});
|
|
70
71
|
`
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
|
|
2
|
+
const pluralize = require('pluralize')
|
|
3
|
+
|
|
2
4
|
function capitalizeFirstLetter(string) {
|
|
3
5
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
4
6
|
}
|
|
@@ -48,20 +50,21 @@ describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
|
|
|
48
50
|
|
|
49
51
|
const input: ${capitalizeFirstLetter(name)}ListInput = { limit: 1, page: 1, search: {}, sort: { createdAt: -1 } };
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
53
|
+
const ${name} = new ${capitalizeFirstLetter(name)}Entity({
|
|
54
|
+
id: getMockUUID(),
|
|
55
|
+
name: 'dummy',
|
|
56
|
+
createdAt: new Date(),
|
|
57
|
+
updatedAt: new Date()
|
|
58
|
+
});
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
const ${pluralize(name)} = [${name}];
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
test('when ${name} are found, should expect an ${name} list', async () => {
|
|
63
|
+
const output: ${capitalizeFirstLetter(name)}ListOutput = { docs: ${pluralize(name)}, page: 1, limit: 1, total: 1 };
|
|
64
|
+
repository.paginate = jest.fn().mockResolvedValue(output);
|
|
62
65
|
|
|
63
66
|
await expect(usecase.execute(input)).resolves.toEqual({
|
|
64
|
-
docs:
|
|
67
|
+
docs: ${pluralize(name)},
|
|
65
68
|
page: 1,
|
|
66
69
|
limit: 1,
|
|
67
70
|
total: 1
|
|
@@ -69,11 +72,10 @@ describe(${capitalizeFirstLetter(name)}ListUsecase.name, () => {
|
|
|
69
72
|
});
|
|
70
73
|
|
|
71
74
|
test('when ${name} not found, should expect an empty list', async () => {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
repository.paginate = jest.fn().mockResolvedValue(paginateOutput);
|
|
75
|
+
const output: ${capitalizeFirstLetter(name)}ListOutput = { docs: [], page: 1, limit: 1, total: 1 };
|
|
76
|
+
repository.paginate = jest.fn().mockResolvedValue(output);
|
|
75
77
|
|
|
76
|
-
await expect(usecase.execute(input)).resolves.toEqual(
|
|
78
|
+
await expect(usecase.execute(input)).resolves.toEqual(output);
|
|
77
79
|
});
|
|
78
80
|
});
|
|
79
81
|
`
|
|
@@ -11,7 +11,7 @@ import { ApiNotFoundException } from '@/utils/exception';
|
|
|
11
11
|
import { expectZodError, getMockUUID } from '@/utils/tests';
|
|
12
12
|
|
|
13
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../../repository/${name}';
|
|
14
|
-
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}
|
|
14
|
+
import { ${capitalizeFirstLetter(name)}UpdateInput, ${capitalizeFirstLetter(name)}UpdateUsecase } from '../${name}-update';
|
|
15
15
|
import { ${capitalizeFirstLetter(name)}Entity } from './../../entity/${name}';
|
|
16
16
|
|
|
17
17
|
describe(${capitalizeFirstLetter(name)}UpdateUsecase.name, () => {
|
|
@@ -64,16 +64,16 @@ describe(${capitalizeFirstLetter(name)}UpdateUsecase.name, () => {
|
|
|
64
64
|
await expect(usecase.execute(input)).rejects.toThrow(ApiNotFoundException);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
67
|
+
const ${name} = new ${capitalizeFirstLetter(name)}Entity({
|
|
68
|
+
id: getMockUUID(),
|
|
69
|
+
name: 'dummy'
|
|
70
|
+
});
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
test('when ${name} updated successfully, should expect an ${name}', async () => {
|
|
73
|
+
repository.findById = jest.fn().mockResolvedValue(${name});
|
|
74
74
|
repository.updateOne = jest.fn().mockResolvedValue(null);
|
|
75
75
|
|
|
76
|
-
await expect(usecase.execute(input)).resolves.toEqual(
|
|
76
|
+
await expect(usecase.execute(input)).resolves.toEqual(${name});
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
79
|
`
|
|
@@ -5,10 +5,9 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
9
8
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
10
9
|
import { CreatedModel } from '@/infra/repository';
|
|
11
|
-
;
|
|
10
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
12
11
|
import { IUsecase } from '@/utils/usecase';
|
|
13
12
|
|
|
14
13
|
import { I${capitalizeFirstLetter(name)}Repository } from '../repository/${name}';
|
|
@@ -5,9 +5,8 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
9
8
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
10
|
-
;
|
|
9
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
11
10
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
12
11
|
import { IUsecase } from '@/utils/usecase';
|
|
13
12
|
|
|
@@ -5,9 +5,8 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseGetById = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
9
8
|
import { ${capitalizeFirstLetter(name)}EntitySchema } from '@/core/${name}/entity/${name}';
|
|
10
|
-
;
|
|
9
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
11
10
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
12
11
|
import { IUsecase } from '@/utils/usecase';
|
|
13
12
|
|
|
@@ -5,8 +5,8 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseList = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
9
8
|
import { ${capitalizeFirstLetter(name)}Entity } from '@/core/${name}/entity/${name}';
|
|
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';
|
|
@@ -5,10 +5,9 @@ function capitalizeFirstLetter(string) {
|
|
|
5
5
|
|
|
6
6
|
const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
|
|
7
7
|
|
|
8
|
-
import { ValidateSchema } from '@/utils/decorators';
|
|
9
8
|
import { I${capitalizeFirstLetter(name)}Repository } from '@/core/${name}/repository/${name}';
|
|
10
9
|
import { ILoggerAdapter } from '@/infra/logger';
|
|
11
|
-
;
|
|
10
|
+
import { ValidateSchema } from '@/utils/decorators';
|
|
12
11
|
import { ApiNotFoundException } from '@/utils/exception';
|
|
13
12
|
import { IUsecase } from '@/utils/usecase';
|
|
14
13
|
|
|
@@ -32,9 +31,9 @@ export class ${capitalizeFirstLetter(name)}UpdateUsecase implements IUsecase {
|
|
|
32
31
|
throw new ApiNotFoundException('${name}NotFound');
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
const ${name}
|
|
34
|
+
const ${name}Found = new ${capitalizeFirstLetter(name)}Entity(${name});
|
|
36
35
|
|
|
37
|
-
const entity = new ${capitalizeFirstLetter(name)}Entity({ ...${name}
|
|
36
|
+
const entity = new ${capitalizeFirstLetter(name)}Entity({ ...${name}Found, ...input });
|
|
38
37
|
|
|
39
38
|
await this.${name}Repository.updateOne({ id: entity.id }, entity);
|
|
40
39
|
|