Fixing file name casing
This commit is contained in:
8
src/User/user.module.ts
Normal file
8
src/User/user.module.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { UserSchema } from './user.schema';
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [UserSchema],
|
||||
exports: [UserSchema],
|
||||
})
|
||||
export class UserModule {}
|
||||
107
src/User/user.schema.ts
Normal file
107
src/User/user.schema.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos';
|
||||
import { Builder } from '../Graphql/graphql.builder';
|
||||
import { PrismaService } from '../Prisma/prisma.service';
|
||||
import { clerkClient } from '@clerk/clerk-sdk-node';
|
||||
|
||||
@Injectable()
|
||||
export class UserSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
// Types section
|
||||
@PothosRef()
|
||||
user() {
|
||||
return this.builder.prismaObject('User', {
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id'),
|
||||
name: t.exposeString('name'),
|
||||
email: t.exposeString('email'),
|
||||
phoneNumber: t.exposeString('phoneNumber'),
|
||||
oauthToken: t.exposeString('oauthToken', { nullable: true }),
|
||||
role: t.exposeString('role'),
|
||||
createdAt: t.expose('createdAt', { type: 'DateTime' }),
|
||||
updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
|
||||
center: t.relation('center'),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
// Query section
|
||||
@Pothos()
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
users: t.prismaField({
|
||||
type: [this.user()],
|
||||
args: this.builder.generator.findManyArgs('User'),
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.user.findMany({
|
||||
...query,
|
||||
take: args.take ?? 10,
|
||||
skip: args.skip ?? 0,
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
where: args.filter ?? undefined,
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
user: t.prismaField({
|
||||
type: this.user(),
|
||||
args: this.builder.generator.findUniqueArgs('User'),
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.user.findUnique({
|
||||
...query,
|
||||
where: args.where,
|
||||
});
|
||||
},
|
||||
}),
|
||||
// userByToken: t.prismaField({
|
||||
// type: this.user(),
|
||||
// args: this.builder.args({
|
||||
// oauthToken: t.arg.string({ required: true }),
|
||||
// }),
|
||||
// resolve: async (query, root, args, ctx, info) => {
|
||||
// // check if the token is valid
|
||||
// const { user } = await clerkClient.verifyToken
|
||||
// return await this.prisma.user.findFirst({
|
||||
// ...query,
|
||||
// where: args.where,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
}));
|
||||
|
||||
// Mutation section
|
||||
this.builder.mutationFields((t) => ({
|
||||
updateUser: t.prismaField({
|
||||
type: this.user(),
|
||||
args: {
|
||||
input: t.arg({
|
||||
type: this.builder.generator.getUpdateInput('User'),
|
||||
required: true,
|
||||
}),
|
||||
where: t.arg({
|
||||
type: this.builder.generator.getWhereUnique('User'),
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.user.update({
|
||||
...query,
|
||||
where: args.where,
|
||||
data: args.input,
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user