Skip to content

Commit 2c250fe

Browse files
committed
Restrict datasets field of User type
1 parent f6ef31b commit 2c250fe

18 files changed

+65
-58
lines changed

prisma/generated/type-graphql/enhance.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ const inputsInfo = {
8181
StringNullableFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "mode", "not"],
8282
ProjectRelationFilter: ["is", "isNot"],
8383
ProjectListRelationFilter: ["every", "some", "none"],
84-
StringWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "mode", "not", "_count", "_min", "_max"],
85-
DateTimeWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not", "_count", "_min", "_max"],
86-
BoolWithAggregatesFilter: ["equals", "not", "_count", "_min", "_max"],
87-
StringNullableWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "mode", "not", "_count", "_min", "_max"],
84+
StringWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "mode", "not", "count", "min", "max"],
85+
DateTimeWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not", "count", "min", "max"],
86+
BoolWithAggregatesFilter: ["equals", "not", "count", "min", "max"],
87+
StringNullableWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "mode", "not", "count", "min", "max"],
8888
StringNullableListFilter: ["equals", "has", "hasEvery", "hasSome", "isEmpty"],
8989
UserCreateNestedOneWithoutProjectsInput: ["create", "connectOrCreate", "connect"],
9090
ProjectCreateNestedOneWithoutChildrenInput: ["create", "connectOrCreate", "connect"],
@@ -105,11 +105,11 @@ const inputsInfo = {
105105
NestedDateTimeFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not"],
106106
NestedBoolFilter: ["equals", "not"],
107107
NestedStringNullableFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "not"],
108-
NestedStringWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "not", "_count", "_min", "_max"],
108+
NestedStringWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "not", "count", "min", "max"],
109109
NestedIntFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not"],
110-
NestedDateTimeWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not", "_count", "_min", "_max"],
111-
NestedBoolWithAggregatesFilter: ["equals", "not", "_count", "_min", "_max"],
112-
NestedStringNullableWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "not", "_count", "_min", "_max"],
110+
NestedDateTimeWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not", "count", "min", "max"],
111+
NestedBoolWithAggregatesFilter: ["equals", "not", "count", "min", "max"],
112+
NestedStringNullableWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "contains", "startsWith", "endsWith", "not", "count", "min", "max"],
113113
NestedIntNullableFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not"],
114114
UserCreateWithoutProjectsInput: ["id", "name", "bio", "url", "datasets"],
115115
UserCreateOrConnectWithoutProjectsInput: ["where", "create"],
@@ -138,10 +138,10 @@ const inputsInfo = {
138138
ProjectUpdateWithoutUserInput: ["id", "createdAt", "updatedAt", "name", "isPublic", "summary", "description", "projectJson", "parent", "children"]
139139
};
140140
const outputsInfo = {
141-
AggregateProject: ["_count", "_min", "_max"],
142-
ProjectGroupBy: ["id", "createdAt", "updatedAt", "userId", "name", "isPublic", "summary", "description", "projectJson", "parentId", "_count", "_min", "_max"],
143-
AggregateUser: ["_count", "_min", "_max"],
144-
UserGroupBy: ["id", "name", "bio", "url", "datasets", "_count", "_min", "_max"],
141+
AggregateProject: ["count", "min", "max"],
142+
ProjectGroupBy: ["id", "createdAt", "updatedAt", "userId", "name", "isPublic", "summary", "description", "projectJson", "parentId", "count", "min", "max"],
143+
AggregateUser: ["count", "min", "max"],
144+
UserGroupBy: ["id", "name", "bio", "url", "datasets", "count", "min", "max"],
145145
AffectedRowsOutput: ["count"],
146146
ProjectCountAggregate: ["id", "createdAt", "updatedAt", "userId", "name", "isPublic", "summary", "description", "projectJson", "parentId", "_all"],
147147
ProjectMinAggregate: ["id", "createdAt", "updatedAt", "userId", "name", "isPublic", "summary", "description", "projectJson", "parentId"],

prisma/generated/type-graphql/resolvers/crud/Project/GroupByProjectResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export class GroupByProjectResolver {
1212
nullable: false
1313
})
1414
async groupByProject(@TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo, @TypeGraphQL.Args() args: GroupByProjectArgs): Promise<ProjectGroupBy[]> {
15-
const { _count, _avg, _sum, _min, _max } = transformFields(
15+
const { count, avg, sum, min, max } = transformFields(
1616
graphqlFields(info as any)
1717
);
1818
return getPrismaFromContext(ctx).project.groupBy({
1919
...args,
2020
...Object.fromEntries(
21-
Object.entries({ _count, _avg, _sum, _min, _max }).filter(([_, v]) => v != null)
21+
Object.entries({ count, avg, sum, min, max }).filter(([_, v]) => v != null)
2222
),
2323
});
2424
}

prisma/generated/type-graphql/resolvers/crud/Project/ProjectCrudResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ export class ProjectCrudResolver {
165165
nullable: false
166166
})
167167
async groupByProject(@TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo, @TypeGraphQL.Args() args: GroupByProjectArgs): Promise<ProjectGroupBy[]> {
168-
const { _count, _avg, _sum, _min, _max } = transformFields(
168+
const { count, avg, sum, min, max } = transformFields(
169169
graphqlFields(info as any)
170170
);
171171
return getPrismaFromContext(ctx).project.groupBy({
172172
...args,
173173
...Object.fromEntries(
174-
Object.entries({ _count, _avg, _sum, _min, _max }).filter(([_, v]) => v != null)
174+
Object.entries({ count, avg, sum, min, max }).filter(([_, v]) => v != null)
175175
),
176176
});
177177
}

prisma/generated/type-graphql/resolvers/crud/User/GroupByUserResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export class GroupByUserResolver {
1212
nullable: false
1313
})
1414
async groupByUser(@TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo, @TypeGraphQL.Args() args: GroupByUserArgs): Promise<UserGroupBy[]> {
15-
const { _count, _avg, _sum, _min, _max } = transformFields(
15+
const { count, avg, sum, min, max } = transformFields(
1616
graphqlFields(info as any)
1717
);
1818
return getPrismaFromContext(ctx).user.groupBy({
1919
...args,
2020
...Object.fromEntries(
21-
Object.entries({ _count, _avg, _sum, _min, _max }).filter(([_, v]) => v != null)
21+
Object.entries({ count, avg, sum, min, max }).filter(([_, v]) => v != null)
2222
),
2323
});
2424
}

prisma/generated/type-graphql/resolvers/crud/User/UserCrudResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ export class UserCrudResolver {
165165
nullable: false
166166
})
167167
async groupByUser(@TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo, @TypeGraphQL.Args() args: GroupByUserArgs): Promise<UserGroupBy[]> {
168-
const { _count, _avg, _sum, _min, _max } = transformFields(
168+
const { count, avg, sum, min, max } = transformFields(
169169
graphqlFields(info as any)
170170
);
171171
return getPrismaFromContext(ctx).user.groupBy({
172172
...args,
173173
...Object.fromEntries(
174-
Object.entries({ _count, _avg, _sum, _min, _max }).filter(([_, v]) => v != null)
174+
Object.entries({ count, avg, sum, min, max }).filter(([_, v]) => v != null)
175175
),
176176
});
177177
}

prisma/generated/type-graphql/resolvers/inputs/BoolWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ export class BoolWithAggregatesFilter {
2323
@TypeGraphQL.Field(_type => NestedIntFilter, {
2424
nullable: true
2525
})
26-
_count?: NestedIntFilter | undefined;
26+
count?: NestedIntFilter | undefined;
2727

2828
@TypeGraphQL.Field(_type => NestedBoolFilter, {
2929
nullable: true
3030
})
31-
_min?: NestedBoolFilter | undefined;
31+
min?: NestedBoolFilter | undefined;
3232

3333
@TypeGraphQL.Field(_type => NestedBoolFilter, {
3434
nullable: true
3535
})
36-
_max?: NestedBoolFilter | undefined;
36+
max?: NestedBoolFilter | undefined;
3737
}

prisma/generated/type-graphql/resolvers/inputs/DateTimeWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ export class DateTimeWithAggregatesFilter {
5353
@TypeGraphQL.Field(_type => NestedIntFilter, {
5454
nullable: true
5555
})
56-
_count?: NestedIntFilter | undefined;
56+
count?: NestedIntFilter | undefined;
5757

5858
@TypeGraphQL.Field(_type => NestedDateTimeFilter, {
5959
nullable: true
6060
})
61-
_min?: NestedDateTimeFilter | undefined;
61+
min?: NestedDateTimeFilter | undefined;
6262

6363
@TypeGraphQL.Field(_type => NestedDateTimeFilter, {
6464
nullable: true
6565
})
66-
_max?: NestedDateTimeFilter | undefined;
66+
max?: NestedDateTimeFilter | undefined;
6767
}

prisma/generated/type-graphql/resolvers/inputs/NestedBoolWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export class NestedBoolWithAggregatesFilter {
2222
@TypeGraphQL.Field(_type => NestedIntFilter, {
2323
nullable: true
2424
})
25-
_count?: NestedIntFilter | undefined;
25+
count?: NestedIntFilter | undefined;
2626

2727
@TypeGraphQL.Field(_type => NestedBoolFilter, {
2828
nullable: true
2929
})
30-
_min?: NestedBoolFilter | undefined;
30+
min?: NestedBoolFilter | undefined;
3131

3232
@TypeGraphQL.Field(_type => NestedBoolFilter, {
3333
nullable: true
3434
})
35-
_max?: NestedBoolFilter | undefined;
35+
max?: NestedBoolFilter | undefined;
3636
}

prisma/generated/type-graphql/resolvers/inputs/NestedDateTimeWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ export class NestedDateTimeWithAggregatesFilter {
5252
@TypeGraphQL.Field(_type => NestedIntFilter, {
5353
nullable: true
5454
})
55-
_count?: NestedIntFilter | undefined;
55+
count?: NestedIntFilter | undefined;
5656

5757
@TypeGraphQL.Field(_type => NestedDateTimeFilter, {
5858
nullable: true
5959
})
60-
_min?: NestedDateTimeFilter | undefined;
60+
min?: NestedDateTimeFilter | undefined;
6161

6262
@TypeGraphQL.Field(_type => NestedDateTimeFilter, {
6363
nullable: true
6464
})
65-
_max?: NestedDateTimeFilter | undefined;
65+
max?: NestedDateTimeFilter | undefined;
6666
}

prisma/generated/type-graphql/resolvers/inputs/NestedStringNullableWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ export class NestedStringNullableWithAggregatesFilter {
6767
@TypeGraphQL.Field(_type => NestedIntNullableFilter, {
6868
nullable: true
6969
})
70-
_count?: NestedIntNullableFilter | undefined;
70+
count?: NestedIntNullableFilter | undefined;
7171

7272
@TypeGraphQL.Field(_type => NestedStringNullableFilter, {
7373
nullable: true
7474
})
75-
_min?: NestedStringNullableFilter | undefined;
75+
min?: NestedStringNullableFilter | undefined;
7676

7777
@TypeGraphQL.Field(_type => NestedStringNullableFilter, {
7878
nullable: true
7979
})
80-
_max?: NestedStringNullableFilter | undefined;
80+
max?: NestedStringNullableFilter | undefined;
8181
}

prisma/generated/type-graphql/resolvers/inputs/NestedStringWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ export class NestedStringWithAggregatesFilter {
6767
@TypeGraphQL.Field(_type => NestedIntFilter, {
6868
nullable: true
6969
})
70-
_count?: NestedIntFilter | undefined;
70+
count?: NestedIntFilter | undefined;
7171

7272
@TypeGraphQL.Field(_type => NestedStringFilter, {
7373
nullable: true
7474
})
75-
_min?: NestedStringFilter | undefined;
75+
min?: NestedStringFilter | undefined;
7676

7777
@TypeGraphQL.Field(_type => NestedStringFilter, {
7878
nullable: true
7979
})
80-
_max?: NestedStringFilter | undefined;
80+
max?: NestedStringFilter | undefined;
8181
}

prisma/generated/type-graphql/resolvers/inputs/StringNullableWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ export class StringNullableWithAggregatesFilter {
7474
@TypeGraphQL.Field(_type => NestedIntNullableFilter, {
7575
nullable: true
7676
})
77-
_count?: NestedIntNullableFilter | undefined;
77+
count?: NestedIntNullableFilter | undefined;
7878

7979
@TypeGraphQL.Field(_type => NestedStringNullableFilter, {
8080
nullable: true
8181
})
82-
_min?: NestedStringNullableFilter | undefined;
82+
min?: NestedStringNullableFilter | undefined;
8383

8484
@TypeGraphQL.Field(_type => NestedStringNullableFilter, {
8585
nullable: true
8686
})
87-
_max?: NestedStringNullableFilter | undefined;
87+
max?: NestedStringNullableFilter | undefined;
8888
}

prisma/generated/type-graphql/resolvers/inputs/StringWithAggregatesFilter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ export class StringWithAggregatesFilter {
7474
@TypeGraphQL.Field(_type => NestedIntFilter, {
7575
nullable: true
7676
})
77-
_count?: NestedIntFilter | undefined;
77+
count?: NestedIntFilter | undefined;
7878

7979
@TypeGraphQL.Field(_type => NestedStringFilter, {
8080
nullable: true
8181
})
82-
_min?: NestedStringFilter | undefined;
82+
min?: NestedStringFilter | undefined;
8383

8484
@TypeGraphQL.Field(_type => NestedStringFilter, {
8585
nullable: true
8686
})
87-
_max?: NestedStringFilter | undefined;
87+
max?: NestedStringFilter | undefined;
8888
}

prisma/generated/type-graphql/resolvers/outputs/AggregateProject.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export class AggregateProject {
1313
@TypeGraphQL.Field(_type => ProjectCountAggregate, {
1414
nullable: true
1515
})
16-
_count!: ProjectCountAggregate | null;
16+
count!: ProjectCountAggregate | null;
1717

1818
@TypeGraphQL.Field(_type => ProjectMinAggregate, {
1919
nullable: true
2020
})
21-
_min!: ProjectMinAggregate | null;
21+
min!: ProjectMinAggregate | null;
2222

2323
@TypeGraphQL.Field(_type => ProjectMaxAggregate, {
2424
nullable: true
2525
})
26-
_max!: ProjectMaxAggregate | null;
26+
max!: ProjectMaxAggregate | null;
2727
}

prisma/generated/type-graphql/resolvers/outputs/AggregateUser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export class AggregateUser {
1313
@TypeGraphQL.Field(_type => UserCountAggregate, {
1414
nullable: true
1515
})
16-
_count!: UserCountAggregate | null;
16+
count!: UserCountAggregate | null;
1717

1818
@TypeGraphQL.Field(_type => UserMinAggregate, {
1919
nullable: true
2020
})
21-
_min!: UserMinAggregate | null;
21+
min!: UserMinAggregate | null;
2222

2323
@TypeGraphQL.Field(_type => UserMaxAggregate, {
2424
nullable: true
2525
})
26-
_max!: UserMaxAggregate | null;
26+
max!: UserMaxAggregate | null;
2727
}

prisma/generated/type-graphql/resolvers/outputs/ProjectGroupBy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ export class ProjectGroupBy {
6363
@TypeGraphQL.Field(_type => ProjectCountAggregate, {
6464
nullable: true
6565
})
66-
_count!: ProjectCountAggregate | null;
66+
count!: ProjectCountAggregate | null;
6767

6868
@TypeGraphQL.Field(_type => ProjectMinAggregate, {
6969
nullable: true
7070
})
71-
_min!: ProjectMinAggregate | null;
71+
min!: ProjectMinAggregate | null;
7272

7373
@TypeGraphQL.Field(_type => ProjectMaxAggregate, {
7474
nullable: true
7575
})
76-
_max!: ProjectMaxAggregate | null;
76+
max!: ProjectMaxAggregate | null;
7777
}

prisma/generated/type-graphql/resolvers/outputs/UserGroupBy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ export class UserGroupBy {
3131
url!: string | null;
3232

3333
@TypeGraphQL.Field(_type => [String], {
34-
nullable: true
34+
nullable: false
3535
})
36-
datasets!: string[] | null;
36+
datasets!: string[];
3737

3838
@TypeGraphQL.Field(_type => UserCountAggregate, {
3939
nullable: true
4040
})
41-
_count!: UserCountAggregate | null;
41+
count!: UserCountAggregate | null;
4242

4343
@TypeGraphQL.Field(_type => UserMinAggregate, {
4444
nullable: true
4545
})
46-
_min!: UserMinAggregate | null;
46+
min!: UserMinAggregate | null;
4747

4848
@TypeGraphQL.Field(_type => UserMaxAggregate, {
4949
nullable: true
5050
})
51-
_max!: UserMaxAggregate | null;
51+
max!: UserMaxAggregate | null;
5252
}

src/resolvers/UserRelationsResolver.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Args, Ctx, FieldResolver, Resolver, Root } from "type-graphql"
33
import { Inject, Service } from "typedi"
44
import { Project, User } from "../../prisma/generated/type-graphql"
55
import { Context } from "../app"
6+
import { NotAuthorizedError } from "../errors"
67
import { ProjectsUserFilter } from "../ProjectTypes"
78

89
export const projectsUserFilterToFindManyArgs = (filter: ProjectsUserFilter, context: Context, additionalWhere: Prisma.ProjectWhereInput): Prisma.ProjectFindManyArgs => (
@@ -47,4 +48,10 @@ export default class UserRelationsResolver {
4748
async projects(@Root() user: User, @Args() filter: ProjectsUserFilter, @Ctx() context: Context) {
4849
return await this.p.project.findMany(projectsUserFilterToFindManyArgs(filter, context, { userId: user.id }));
4950
}
51+
52+
@FieldResolver(returns => [String], { nullable: true })
53+
async datasets(@Root() user: User, @Ctx() context: Context) {
54+
if(user.id !== context.user?.uid) throw new NotAuthorizedError("you can only access your own datasets");
55+
return user.datasets;
56+
}
5057
}

0 commit comments

Comments
 (0)