Fixing file name casing

This commit is contained in:
2024-10-12 23:15:06 +07:00
parent 5c40a2fd53
commit 0e3aa751ce
29 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { ServiceSchema } from './service.schema';
@Global()
@Module({
providers: [ServiceSchema],
exports: [ServiceSchema],
})
export class ServiceModule {}

View File

@@ -0,0 +1,125 @@
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';
@Injectable()
export class ServiceSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super();
}
@PothosRef()
service() {
return this.builder.prismaObject('Service', {
fields: (t) => ({
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: 'DateTime',
nullable: true,
}),
updatedAt: t.expose('updatedAt', {
type: 'DateTime',
nullable: true,
}),
}),
});
}
@Pothos()
init() {
this.builder.queryFields((t) => ({
services: t.prismaField({
type: [this.service()],
args: this.builder.generator.findManyArgs('Service'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.service.findMany({
...query,
where: args.filter ?? undefined,
orderBy: args.orderBy ?? undefined,
skip: args.skip ?? 0,
take: args.take ?? 10,
});
},
}),
service: t.prismaField({
type: this.service(),
args: {
input: t.arg({
type: this.builder.generator.getWhereUnique('Service'),
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.service.findUnique({
...query,
where: args.input,
});
},
}),
}));
// Mutation section
this.builder.mutationFields((t) => ({
createService: t.prismaField({
type: this.service(),
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('Service'),
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.service.create({ data: args.input });
},
}),
updateService: t.prismaField({
type: this.service(),
args: {
input: t.arg({
type: this.builder.generator.getUpdateInput('Service'),
required: true,
}),
where: t.arg({
type: this.builder.generator.getWhereUnique('Service'),
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.service.update({
...query,
where: args.where,
data: args.input,
});
},
}),
deleteService: t.prismaField({
type: this.service(),
args: {
where: t.arg({
type: this.builder.generator.getWhereUnique('Service'),
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.service.delete({
...query,
where: args.where,
});
},
}),
}));
}
}