158 lines
4.9 KiB
TypeScript
158 lines
4.9 KiB
TypeScript
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 { MinioService } from 'src/Minio/minio.service'
|
|
|
|
@Injectable()
|
|
export class WorkshopSchema extends PothosSchema {
|
|
constructor(
|
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
|
private readonly prisma: PrismaService,
|
|
private readonly minioService: MinioService,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
@PothosRef()
|
|
workshop() {
|
|
return this.builder.prismaObject('Workshop', {
|
|
description: 'A workshop in the system.',
|
|
fields: (t) => ({
|
|
id: t.exposeID('id', {
|
|
description: 'The ID of the workshop.',
|
|
}),
|
|
title: t.exposeString('title', {
|
|
description: 'The title of the workshop.',
|
|
}),
|
|
description: t.exposeString('description', {
|
|
description: 'The description of the workshop.',
|
|
}),
|
|
mentorId: t.exposeID('mentorId', {
|
|
description: 'The ID of the mentor who is leading the workshop.',
|
|
}),
|
|
serviceId: t.exposeID('serviceId', {
|
|
description: 'The ID of the service that the workshop is for.',
|
|
}),
|
|
imageFile: t.relation('imageFile', {
|
|
nullable: true,
|
|
}),
|
|
imageFileId: t.exposeID('imageFileId', {
|
|
description: 'The ID of the image file for the workshop.',
|
|
}),
|
|
date: t.expose('date', {
|
|
type: 'DateTime',
|
|
nullable: true,
|
|
description: 'The date and time the workshop is scheduled.',
|
|
}),
|
|
createdAt: t.expose('createdAt', {
|
|
type: 'DateTime',
|
|
nullable: true,
|
|
description: 'The date and time the workshop was created.',
|
|
}),
|
|
updatedAt: t.expose('updatedAt', {
|
|
type: 'DateTime',
|
|
nullable: true,
|
|
description: 'The date and time the workshop was updated.',
|
|
}),
|
|
service: t.relation('service', {
|
|
description: 'The service that the workshop is for.',
|
|
}),
|
|
organization: t.relation('organization', {
|
|
description: 'The organization that the workshop is for.',
|
|
}),
|
|
subscription: t.relation('subscription', {
|
|
description: 'The subscription that the workshop is for.',
|
|
}),
|
|
mentor: t.relation('mentor', {
|
|
description: 'The mentor who is leading the workshop.',
|
|
}),
|
|
meetingRoom: t.relation('workshopMeetingRoom', {
|
|
nullable: true,
|
|
description: 'The meeting room that the workshop is for.',
|
|
}),
|
|
}),
|
|
})
|
|
}
|
|
|
|
@Pothos()
|
|
init(): void {
|
|
this.builder.queryFields((t) => ({
|
|
workshop: t.prismaField({
|
|
type: this.workshop(),
|
|
args: this.builder.generator.findUniqueArgs('Workshop'),
|
|
description: 'Retrieve a single workshop by its unique identifier.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.workshop.findUnique({
|
|
...query,
|
|
where: args.where,
|
|
})
|
|
},
|
|
}),
|
|
|
|
workshops: t.prismaField({
|
|
type: [this.workshop()],
|
|
args: this.builder.generator.findManyArgs('Workshop'),
|
|
description:
|
|
'Retrieve a list of workshops with optional filtering, ordering, and pagination.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.workshop.findMany({
|
|
...query,
|
|
skip: args.skip ?? undefined,
|
|
take: args.take ?? undefined,
|
|
orderBy: args.orderBy ?? undefined,
|
|
where: args.filter ?? undefined,
|
|
})
|
|
},
|
|
}),
|
|
}))
|
|
|
|
// Mutations section
|
|
this.builder.mutationFields((t) => ({
|
|
createWorkshop: t.prismaField({
|
|
type: this.workshop(),
|
|
args: {
|
|
input: t.arg({
|
|
type: this.builder.generator.getCreateInput('Workshop'),
|
|
required: true,
|
|
}),
|
|
},
|
|
description: 'Create a new workshop.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.workshop.create({
|
|
...query,
|
|
data: args.input,
|
|
})
|
|
},
|
|
}),
|
|
|
|
updateWorkshop: t.prismaField({
|
|
type: this.workshop(),
|
|
args: {
|
|
input: t.arg({
|
|
type: this.builder.generator.getUpdateInput('Workshop'),
|
|
required: true,
|
|
}),
|
|
where: t.arg({
|
|
type: this.builder.generator.getWhereUnique('Workshop'),
|
|
required: true,
|
|
}),
|
|
},
|
|
description: 'Update an existing workshop.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.workshop.update({
|
|
...query,
|
|
where: args.where,
|
|
data: args.input,
|
|
})
|
|
},
|
|
}),
|
|
}))
|
|
}
|
|
}
|