implement service query
This commit is contained in:
@@ -1,448 +0,0 @@
|
||||
// import { builder, prisma, SortOrder } from './graphql.builder';
|
||||
// import { Prisma } from '@prisma/client';
|
||||
|
||||
// builder.prismaObject('User', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// name: t.exposeString('name'),
|
||||
// email: t.exposeString('email'),
|
||||
// phoneNumber: t.exposeString('phoneNumber'),
|
||||
// role: t.exposeString('role'),
|
||||
// createdAt: t.expose('createdAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// updatedAt: t.expose('updatedAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// order: t.relation('orders'),
|
||||
// serviceFeedbacks: t.relation('serviceFeedbacks'),
|
||||
// documents: t.relation('documents'),
|
||||
// sendingMessage: t.relation('sendingMessage'),
|
||||
// Service: t.relation('Service'),
|
||||
// center: t.relation('center'),
|
||||
// customerChatRoom: t.relation('customerChatRoom'),
|
||||
// centerStaffChatRoom: t.relation('centerStaffChatRoom'),
|
||||
// CenterStaff: t.relation('CenterStaff'),
|
||||
// WorkshopSubscription: t.relation('WorkshopSubscription'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Order', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// paymentId: t.exposeString('paymentId'),
|
||||
// userId: t.exposeID('userId'),
|
||||
// serviceId: t.exposeID('serviceId'),
|
||||
// status: t.exposeString('status'),
|
||||
// total: t.expose('total', {
|
||||
// type: 'Int',
|
||||
// }),
|
||||
// createdAt: t.expose('createdAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// updatedAt: t.expose('updatedAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// user: t.relation('user'),
|
||||
// payment: t.relation('payment'),
|
||||
// service: t.relation('service'),
|
||||
// refundTicket: t.relation('refundTicket'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('ServiceFeedback', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// userId: t.exposeID('userId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('UploadedDocument', {
|
||||
// name: 'documents',
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// userId: t.exposeID('userId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Message', {
|
||||
// name: 'sendingMessage',
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// userId: t.exposeID('senderId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Payment', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// amount: t.expose('amount', {
|
||||
// type: 'Float',
|
||||
// }),
|
||||
// status: t.exposeString('status'),
|
||||
// createdAt: t.expose('createdAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// updatedAt: t.expose('updatedAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// order: t.relation('Order'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('RefundTicket', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// orderId: t.exposeID('orderId'),
|
||||
// amount: t.expose('amount', {
|
||||
// type: 'Float',
|
||||
// }),
|
||||
// status: t.exposeString('status'),
|
||||
// createdAt: t.expose('createdAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// updatedAt: t.expose('updatedAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// order: t.relation('order'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Service', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// name: t.exposeString('name'),
|
||||
// description: t.exposeString('description'),
|
||||
// centerId: t.exposeID('centerId'),
|
||||
// price: t.expose('price', {
|
||||
// type: 'Float',
|
||||
// }),
|
||||
// rating: t.expose('rating', {
|
||||
// type: 'Float',
|
||||
// }),
|
||||
// createdAt: t.expose('createdAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// updatedAt: t.expose('updatedAt', {
|
||||
// type: 'DateTime',
|
||||
// nullable: true,
|
||||
// }),
|
||||
// managedBy: t.relation('managedBy'),
|
||||
// feedbacks: t.relation('feedbacks'),
|
||||
// order: t.relation('order'),
|
||||
// workshop: t.relation('workshop'),
|
||||
// milestone: t.relation('milestone'),
|
||||
// schedule: t.relation('schedule'),
|
||||
// serviceAndCategory: t.relation('serviceAndCategory'),
|
||||
// workshopOrganization: t.relation('workshopOrganization'),
|
||||
// user: t.relation('user'),
|
||||
// userId: t.exposeID('userId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Milestone', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// serviceId: t.exposeID('serviceId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Schedule', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// serviceId: t.exposeID('serviceId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('ServiceAndCategory', {
|
||||
// fields: (t) => ({
|
||||
// serviceId: t.exposeID('serviceId'),
|
||||
// categoryId: t.exposeID('categoryId'),
|
||||
// service: t.relation('service'),
|
||||
// category: t.relation('category'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('WorkshopOrganization', {
|
||||
// fields: (t) => ({
|
||||
// serviceId: t.exposeID('serviceId'),
|
||||
// workshopId: t.exposeID('workshopId'),
|
||||
// service: t.relation('service'),
|
||||
// workshop: t.relation('workshop'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Category', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Center', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// userId: t.exposeID('centerOwnerId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('ChatRoom', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('CenterStaff', {
|
||||
// fields: (t) => ({
|
||||
// staffId: t.exposeID('staffId'),
|
||||
// staff: t.relation('staff'),
|
||||
// centerId: t.exposeID('centerId'),
|
||||
// serviceId: t.exposeID('serviceId'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('WorkshopSubscription', {
|
||||
// fields: (t) => ({
|
||||
// userId: t.exposeID('userId'),
|
||||
// workshopId: t.exposeID('workshopId'),
|
||||
// user: t.relation('user'),
|
||||
// workshop: t.relation('workshop'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// builder.prismaObject('Workshop', {
|
||||
// fields: (t) => ({
|
||||
// id: t.exposeID('id'),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// // Query section
|
||||
// builder.queryType({
|
||||
// fields: (t) => ({
|
||||
// users: t.prismaField({
|
||||
// type: ['User'], // Return type is a list of 'User'
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.user.findMany({
|
||||
// ...query,
|
||||
// // Include related posts in the query
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// user: t.prismaField({
|
||||
// type: 'User',
|
||||
// args: {
|
||||
// id: t.arg.string(),
|
||||
// },
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.user.findUnique({
|
||||
// where: {
|
||||
// id: args.id?.toString(),
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// orders: t.prismaField({
|
||||
// type: ['Order'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.order.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// serviceFeedbacks: t.prismaField({
|
||||
// type: ['ServiceFeedback'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.serviceFeedback.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// documents: t.prismaField({
|
||||
// type: ['UploadedDocument'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.uploadedDocument.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// messages: t.prismaField({
|
||||
// type: ['Message'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.message.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// services: t.prismaField({
|
||||
// type: ['Service'],
|
||||
// args: {
|
||||
// where: t.arg({
|
||||
// type: builder.inputType('ServiceWhereInput', {
|
||||
// fields: (t) => ({
|
||||
// // search by name contains
|
||||
// nameContain: t.string(),
|
||||
// // search by name starts with
|
||||
// nameStartsWith: t.string(),
|
||||
// // search by name ends with
|
||||
// nameEndsWith: t.string(),
|
||||
// }),
|
||||
// }),
|
||||
// }),
|
||||
// orderBy: t.arg({
|
||||
// type: builder.inputType('ServiceOrderByInput', {
|
||||
// fields: (t) => ({
|
||||
// rating: t.field({
|
||||
// type: SortOrder,
|
||||
// }),
|
||||
// price: t.field({
|
||||
// type: SortOrder,
|
||||
// }),
|
||||
// }),
|
||||
// }),
|
||||
// }),
|
||||
// cursor: t.arg({
|
||||
// type: builder.inputType('ServiceWhereUniqueInput', {
|
||||
// fields: (t) => ({
|
||||
// // Define fields to match your `ServiceWhereUniqueInput` structure.
|
||||
// name: t.string(),
|
||||
// }),
|
||||
// }),
|
||||
// }),
|
||||
// take: t.arg.int(),
|
||||
// skip: t.arg.int(),
|
||||
// },
|
||||
// resolve: async (query, root, args, ctx, info) => {
|
||||
// return prisma.service.findMany({
|
||||
// // handle where condition
|
||||
// where: {
|
||||
// name: {
|
||||
// contains: args.where?.nameContain as string | undefined,
|
||||
// startsWith: args.where?.nameStartsWith as string | undefined,
|
||||
// endsWith: args.where?.nameEndsWith as string | undefined,
|
||||
// },
|
||||
// },
|
||||
// // handle orderBy condition
|
||||
// orderBy: {
|
||||
// rating: args.orderBy?.rating as Prisma.SortOrder,
|
||||
// price: args.orderBy?.price as Prisma.SortOrder,
|
||||
// },
|
||||
// // handle pagination
|
||||
// cursor: args.cursor as Prisma.ServiceWhereUniqueInput | undefined,
|
||||
// take: args.take as number | undefined,
|
||||
// skip: args.skip as number | undefined,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// service: t.prismaField({
|
||||
// type: 'Service',
|
||||
// args: {
|
||||
// id: t.arg.string(),
|
||||
// },
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.service.findUnique({
|
||||
// where: {
|
||||
// id: args.id?.toString(),
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// centers: t.prismaField({
|
||||
// type: ['Center'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.center.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// chatRooms: t.prismaField({
|
||||
// type: ['ChatRoom'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.chatRoom.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// centerStaffs: t.prismaField({
|
||||
// type: ['CenterStaff'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.centerStaff.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// workshopSubscriptions: t.prismaField({
|
||||
// type: ['WorkshopSubscription'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.workshopSubscription.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// workshops: t.prismaField({
|
||||
// type: ['Workshop'],
|
||||
// resolve: (query, root, args, ctx, info) => {
|
||||
// return prisma.workshop.findMany({
|
||||
// ...query,
|
||||
// });
|
||||
// },
|
||||
// }),
|
||||
// }),
|
||||
// });
|
||||
|
||||
// // Mutation section
|
||||
// // builder.mutationType({
|
||||
// // fields: (t) => ({
|
||||
// // createUser: t.prismaField({
|
||||
// // type: 'User',
|
||||
// // args: {
|
||||
// // data: t.arg({
|
||||
// // type: builder.inputType('UserCreateInput', {
|
||||
// // fields: (t) => ({
|
||||
// // email: t.string({ required: true }),
|
||||
// // name: t.string(),
|
||||
// // // Include other fields as per your schema
|
||||
// // }),
|
||||
// // }),
|
||||
// // required: true, // Make the data argument required
|
||||
// // }),
|
||||
// // },
|
||||
// // resolve: (query, root, args, ctx, info) => {
|
||||
// // if (!args.data) {
|
||||
// // throw new Error('Data input is required');
|
||||
// // }
|
||||
|
||||
// // return prisma.user.create({
|
||||
// // ...query,
|
||||
// // data: args.data as Prisma.UserCreateInput, // Explicit type casting to match Prisma's expectation
|
||||
// // });
|
||||
// // },
|
||||
// // }),
|
||||
// // }),
|
||||
// // });
|
||||
|
||||
// // Subscription section
|
||||
// // builder.subscriptionType({
|
||||
// // fields: (t) => ({
|
||||
// // userCreated: t.prismaField({
|
||||
// // type: 'User',
|
||||
// // subscribe: (query, root, args, ctx, info) => {
|
||||
// // return prisma.$subscribe.user({
|
||||
// // mutation_in: ['CREATED'],
|
||||
// // });
|
||||
// // },
|
||||
// // resolve: (payload) => {
|
||||
// // return payload;
|
||||
// // },
|
||||
// // }),
|
||||
// // }),
|
||||
// // });
|
||||
|
||||
// export const schema = builder.toSchema();
|
||||
@@ -37,4 +37,23 @@ export class ResumeSchema extends PothosSchema {
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
resumeStatus() {
|
||||
return this.builder.enumType('ResumeStatus', {
|
||||
values: ['PENDING', 'APPROVED', 'REJECTED'],
|
||||
});
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
init() {
|
||||
this.builder.queryField('resumes', (t) =>
|
||||
t.field({
|
||||
type: [this.resume()],
|
||||
resolve: async () => {
|
||||
return await this.prisma.resume.findMany();
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,59 @@ export class ServiceSchema extends PothosSchema {
|
||||
id: t.exposeID('id'),
|
||||
name: t.exposeString('name'),
|
||||
description: t.exposeString('description'),
|
||||
price: t.exposeFloat('price'),
|
||||
rating: t.exposeFloat('rating'),
|
||||
createdAt: t.expose('createdAt', {
|
||||
type: 'Date',
|
||||
nullable: true,
|
||||
}),
|
||||
updatedAt: t.expose('updatedAt', {
|
||||
type: 'Date',
|
||||
nullable: true,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
init() {
|
||||
this.builder.queryFields((t) => ({
|
||||
services: t.prismaField({
|
||||
type: [this.service()],
|
||||
args: {
|
||||
skip: t.arg.int(),
|
||||
take: t.arg.int(),
|
||||
cursor: t.arg.string(),
|
||||
where: t.arg.string(),
|
||||
orderBy: t.arg.string(),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
const { skip, take, cursor, where, orderBy } = args;
|
||||
const services = await this.prisma.service.findMany({
|
||||
skip: skip || 0,
|
||||
take: take || 10,
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
where: where ? JSON.parse(where) : undefined,
|
||||
orderBy: orderBy ? JSON.parse(orderBy) : undefined,
|
||||
});
|
||||
return services;
|
||||
},
|
||||
}),
|
||||
service: t.prismaField({
|
||||
type: this.service(),
|
||||
args: {
|
||||
id: t.arg.string({
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
const { id } = args;
|
||||
const service = await this.prisma.service.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
return service;
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user