Skip to content

Commit 66239bb

Browse files
committed
feat: Generate aggregate input types
1 parent 472c640 commit 66239bb

17 files changed

+210
-27
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"get-relative-path": "^1.0.2",
5353
"pupa": "^2.0.1",
5454
"to-kebab": "^1.0.7",
55-
"ts-morph": "^8.0.0",
55+
"ts-morph": "^8.1.0",
5656
"typescript-equals": "^1.0.0"
5757
},
5858
"peerDependencies": {
@@ -61,26 +61,26 @@
6161
"devDependencies": {
6262
"@commitlint/cli": "^9.1.2",
6363
"@commitlint/config-conventional": "^9.1.2",
64-
"@nestjs/common": "^7.4.2",
65-
"@nestjs/core": "^7.4.2",
64+
"@nestjs/common": "^7.4.3",
65+
"@nestjs/core": "^7.4.3",
6666
"@nestjs/graphql": "^7.6.0",
67-
"@nestjs/platform-express": "^7.4.2",
67+
"@nestjs/platform-express": "^7.4.3",
6868
"@paljs/plugins": "^1.2.6",
6969
"@prisma/cli": "^2.5.1",
7070
"@prisma/client": "^2.5.1",
7171
"@semantic-release/changelog": "^5.0.1",
7272
"@semantic-release/git": "^9.0.0",
7373
"@types/mocha": "^8.0.3",
74-
"@types/node": "^14.6.0",
75-
"@typescript-eslint/eslint-plugin": "^3.9.1",
76-
"@typescript-eslint/parser": "^3.9.1",
77-
"apollo-server-express": "^2.16.1",
74+
"@types/node": "^14.6.2",
75+
"@typescript-eslint/eslint-plugin": "^3.10.1",
76+
"@typescript-eslint/parser": "^3.10.1",
77+
"apollo-server-express": "^2.17.0",
7878
"c8": "^7.3.0",
7979
"class-transformer": "^0.3.1",
8080
"class-validator": "^0.12.2",
8181
"eslint": "^7.7.0",
8282
"eslint-import-resolver-node": "^0.3.4",
83-
"eslint-plugin-etc": "0.0.1-beta.43",
83+
"eslint-plugin-etc": "0.0.1-beta.44",
8484
"eslint-plugin-import": "^2.22.0",
8585
"eslint-plugin-only-warn": "^1.0.2",
8686
"eslint-plugin-prettier": "^3.1.4",
@@ -97,9 +97,9 @@
9797
"graphql": "^15.3.0",
9898
"graphql-type-json": "^0.3.2",
9999
"husky": "^4.2.5",
100-
"mocha": "^8.1.1",
100+
"mocha": "^8.1.3",
101101
"precise-commits": "^1.0.2",
102-
"prettier": "^2.0.5",
102+
"prettier": "^2.1.1",
103103
"reflect-metadata": "^0.1.13",
104104
"rxjs": "^6.6.2",
105105
"semantic-release": "^17.1.1",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class ArticleAvgAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
favoritesCount?: true;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class ArticleMaxAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
favoritesCount?: true;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class ArticleMinAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
favoritesCount?: true;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class ArticleSumAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
favoritesCount?: true;
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class UserAvgAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
countComments?: true | null;
10+
11+
@Field(() => Boolean, {
12+
nullable: true,
13+
description: undefined,
14+
})
15+
rating?: true | null;
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class UserMaxAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
countComments?: true | null;
10+
11+
@Field(() => Boolean, {
12+
nullable: true,
13+
description: undefined,
14+
})
15+
rating?: true | null;
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class UserMinAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
countComments?: true | null;
10+
11+
@Field(() => Boolean, {
12+
nullable: true,
13+
description: undefined,
14+
})
15+
rating?: true | null;
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
3+
@InputType({})
4+
export class UserSumAggregateInput {
5+
@Field(() => Boolean, {
6+
nullable: true,
7+
description: undefined,
8+
})
9+
countComments?: true | null;
10+
11+
@Field(() => Boolean, {
12+
nullable: true,
13+
description: undefined,
14+
})
15+
rating?: true | null;
16+
}

src/generate-file-name.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ const splitKeywords = [
2424
'UpsertWithout',
2525
'WhereInput',
2626
'WhereUniqueInput',
27+
'AvgAggregate',
28+
'SumAggregate',
29+
'MinAggregate',
30+
'MaxAggregate',
2731
].sort((a, b) => b.length - a.length);
2832

33+
const endsWithKeywords = ['Aggregate'];
34+
2935
type GenerateFileNameArgs = {
3036
type: FileType;
3137
name: string;
@@ -68,7 +74,14 @@ export function getFeatureName(args: GetFeatureNameArgs) {
6874
const [test] = name.split(keyword, 1);
6975
if (models.includes(test)) {
7076
result = test;
71-
break;
77+
return result;
78+
}
79+
}
80+
for (const keyword of endsWithKeywords) {
81+
const [test] = name.split(keyword).slice(-1);
82+
if (models.includes(test)) {
83+
result = test;
84+
return result;
7285
}
7386
}
7487
return result;

0 commit comments

Comments
 (0)