Skip to content

Commit 05d9538

Browse files
committed
Feat: Update plop template file
1 parent b0d7e25 commit 05d9538

File tree

4 files changed

+46
-41
lines changed

4 files changed

+46
-41
lines changed

generator/templates/resolver.hbs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,39 @@ import { UseAuthGuard } from 'src/common/decorators/auth-guard.decorator';
22
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'
33
import { {{pascalCase tableName}}Service } from './{{tableName}}.service'
44
import { GetManyInput, GetOneInput } from 'src/common/graphql/custom.input'
5-
import { CurrentQuery } from 'src/common/decorators/query.decorator'
65
import GraphQLJSON from 'graphql-type-json';
76

7+
import { GetInfoFromQueryProps } from 'src/common/graphql/utils/types';
8+
import { GraphQLQueryToOption } from 'src/common/decorators/option.decorator';
9+
import { UseRepositoryInterceptor } from 'src/common/decorators/repository-interceptor.decorator';
10+
811
import { Get{{pascalCase tableName}}Type, {{pascalCase tableName}} } from './entities/{{tableName}}.entity';
912
import { Create{{pascalCase tableName}}Input, Update{{pascalCase tableName}}Input } from './inputs/{{tableName}}.input';
1013

1114
@Resolver()
1215
export class {{pascalCase tableName}}Resolver {
1316
constructor(private readonly {{tableName}}Service: {{pascalCase tableName}}Service) {}
17+
1418
@Query(() => Get{{pascalCase tableName}}Type)
1519
@UseAuthGuard('admin')
20+
@UseRepositoryInterceptor({{pascalCase tableName}})
1621
getMany{{pascalCase tableName}}List(
17-
@Args({ name: 'input', nullable: true }) qs: GetManyInput<{{pascalCase tableName}}>,
18-
@CurrentQuery() gqlQuery: string,
22+
@Args({ name: 'input', nullable: true }) condition: GetManyInput<{{pascalCase tableName}}>,
23+
@GraphQLQueryToOption<{{pascalCase tableName}}>(true)
24+
option: GetInfoFromQueryProps<{{pascalCase tableName}}>,
1925
) {
20-
return this.{{tableName}}Service.getMany(qs, gqlQuery);
26+
return this.{{tableName}}Service.getMany({ ...condition, ...option });
2127
}
2228

2329
@Query(() => {{pascalCase tableName}})
2430
@UseAuthGuard('admin')
31+
@UseRepositoryInterceptor({{pascalCase tableName}})
2532
getOne{{pascalCase tableName}}(
26-
@Args({ name: 'input' }) qs: GetOneInput<{{pascalCase tableName}}>,
27-
@CurrentQuery() gqlQuery: string,
33+
@Args({ name: 'input' }) condition: GetOneInput<{{pascalCase tableName}}>,
34+
@GraphQLQueryToOption<{{pascalCase tableName}}>()
35+
option: GetInfoFromQueryProps<{{pascalCase tableName}}>,
2836
) {
29-
return this.{{tableName}}Service.getOne(qs, gqlQuery);
37+
return this.{{tableName}}Service.getOne({ ...condition, ...option });
3038
}
3139

3240
@Mutation(() => {{pascalCase tableName}})

generator/templates/resolver.spec.hbs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { GetManyInput, GetOneInput } from 'src/common/graphql/custom.input'
99
import { {{pascalCase tableName}} } from './entities/{{tableName}}.entity'
1010
import { UtilModule } from 'src/common/shared/services/util.module';
1111
import { UtilService } from 'src/common/shared/services/util.service';
12+
import { DataSource } from 'typeorm';
1213

1314
import { Create{{pascalCase tableName}}Input, Update{{pascalCase tableName}}Input } from './inputs/{{tableName}}.input'
1415

@@ -26,6 +27,10 @@ describe('{{pascalCase tableName}}Resolver', () => {
2627
provide: {{pascalCase tableName}}Service,
2728
useFactory: MockServiceFactory.getMockService({{pascalCase tableName}}Service),
2829
},
30+
{
31+
provide: DataSource,
32+
useValue: undefined,
33+
},
2934
],
3035
}).compile()
3136

@@ -39,7 +44,7 @@ describe('{{pascalCase tableName}}Resolver', () => {
3944
})
4045

4146
it('Calling "Get many {{tableName}} list" method', () => {
42-
const qs: GetManyInput<{{pascalCase tableName}}> = {
47+
const condition: GetManyInput<{{pascalCase tableName}}> = {
4348
where: {
4449
{{#if (is "increment" idType)}}
4550
id: utilService.getRandomNumber(0,999999)
@@ -49,22 +54,17 @@ describe('{{pascalCase tableName}}Resolver', () => {
4954
},
5055
}
5156

52-
const gqlQuery = `
53-
query GetMany{{pascalCase tableName}}List {
54-
getMany{{pascalCase tableName}}List {
55-
data {
56-
id
57-
}
58-
}
59-
}
60-
`
61-
62-
expect(resolver.getMany{{pascalCase tableName}}List(qs, gqlQuery)).not.toEqual(null)
63-
expect(mockedService.getMany).toHaveBeenCalledWith(qs, gqlQuery)
57+
const option = { relations: undefined, select: undefined };
58+
59+
expect(resolver.getMany{{pascalCase tableName}}List(condition, option)).not.toEqual(null)
60+
expect(mockedService.getMany).toHaveBeenCalledWith({
61+
...condition,
62+
...option,
63+
})
6464
})
6565

6666
it('Calling "Get one {{tableName}} list" method', () => {
67-
const qs: GetOneInput<{{pascalCase tableName}}> = {
67+
const condition: GetOneInput<{{pascalCase tableName}}> = {
6868
where: {
6969
{{#if (is "increment" idType)}}
7070
id: utilService.getRandomNumber(0,999999)
@@ -74,18 +74,13 @@ describe('{{pascalCase tableName}}Resolver', () => {
7474
},
7575
}
7676

77-
const gqlQuery = `
78-
query GetOne{{pascalCase tableName}} {
79-
getOne{{pascalCase tableName}} {
80-
data {
81-
id
82-
}
83-
}
84-
}
85-
`
86-
87-
expect(resolver.getOne{{pascalCase tableName}}(qs, gqlQuery)).not.toEqual(null)
88-
expect(mockedService.getOne).toHaveBeenCalledWith(qs, gqlQuery)
77+
const option = { relations: undefined, select: undefined };
78+
79+
expect(resolver.getOne{{pascalCase tableName}}(condition, option)).not.toEqual(null)
80+
expect(mockedService.getOne).toHaveBeenCalledWith({
81+
...condition,
82+
...option,
83+
})
8984
})
9085

9186
it('Calling "Create {{tableName}}" method', () => {

generator/templates/service.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { Injectable } from '@nestjs/common'
2+
23
import { OneRepoQuery, RepoQuery } from 'src/common/graphql/types'
4+
35
import { {{pascalCase tableName}}Repository } from './{{tableName}}.repository'
46
import { {{pascalCase tableName}} } from './entities/{{tableName}}.entity';
57
import { Create{{pascalCase tableName}}Input, Update{{pascalCase tableName}}Input } from './inputs/{{tableName}}.input';
68

79
@Injectable()
810
export class {{pascalCase tableName}}Service {
911
constructor(private readonly {{tableName}}Repository: {{pascalCase tableName}}Repository) {}
10-
getMany(qs: RepoQuery<{{pascalCase tableName}}> = {}, gqlQuery?: string) {
11-
return this.{{tableName}}Repository.getMany(qs, gqlQuery);
12+
getMany(option?: RepoQuery<{{pascalCase tableName}}>) {
13+
return this.{{tableName}}Repository.getMany(option);
1214
}
1315

14-
getOne(qs: OneRepoQuery<{{pascalCase tableName}}>, gqlQuery?: string) {
15-
return this.{{tableName}}Repository.getOne(qs, gqlQuery);
16+
getOne(option: OneRepoQuery<{{pascalCase tableName}}>) {
17+
return this.{{tableName}}Repository.getOne(option);
1618
}
1719

1820
create(input: Create{{pascalCase tableName}}Input) {

generator/templates/service.spec.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('{{pascalCase tableName}}Service', () => {
4242
})
4343

4444
it('Calling "Get many" method', () => {
45-
const qs: RepoQuery<{{pascalCase tableName}}> = {
45+
const option: RepoQuery<{{pascalCase tableName}}> = {
4646
where: {
4747
{{#if (is "increment" idType)}}
4848
id: utilService.getRandomNumber(0,999999)
@@ -52,12 +52,12 @@ describe('{{pascalCase tableName}}Service', () => {
5252
},
5353
}
5454

55-
expect(service.getMany(qs)).not.toEqual(null)
55+
expect(service.getMany(option)).not.toEqual(null)
5656
expect(mockedRepository.getMany).toHaveBeenCalled()
5757
})
5858

5959
it('Calling "Get one" method', () => {
60-
const qs: OneRepoQuery<{{pascalCase tableName}}> = {
60+
const option: OneRepoQuery<{{pascalCase tableName}}> = {
6161
where: {
6262
{{#if (is "increment" idType)}}
6363
id: utilService.getRandomNumber(0,999999)
@@ -67,7 +67,7 @@ describe('{{pascalCase tableName}}Service', () => {
6767
},
6868
}
6969

70-
expect(service.getOne(qs)).not.toEqual(null)
70+
expect(service.getOne(option)).not.toEqual(null)
7171
expect(mockedRepository.getOne).toHaveBeenCalled()
7272
})
7373

0 commit comments

Comments
 (0)