Files
epess-web-backend/src/ServiceMeetingRoom/servicemeetingroom.schema.ts
2024-10-28 02:56:36 +07:00

71 lines
2.2 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';
@Injectable()
export class ServiceMeetingRoomSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super();
}
@PothosRef()
serviceMeetingRoom() {
return this.builder.prismaObject('ServiceMeetingRoom', {
description: 'A service meeting room in the system.',
fields: (t) => ({
id: t.exposeID('id', {
description: 'The ID of the service meeting room.',
}),
chattingRoomId: t.exposeString('chattingRoomId', {
description: 'The ID of the chatting room.',
}),
chattingRoom: t.relation('chattingRoom', {
description: 'The chatting room.',
}),
}),
});
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
serviceMeetingRoom: t.prismaField({
type: this.serviceMeetingRoom(),
args: this.builder.generator.findUniqueArgs('ServiceMeetingRoom'),
description:
'Retrieve a single service meeting room by its unique identifier.',
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.serviceMeetingRoom.findUnique({
...query,
where: args.where,
});
},
}),
serviceMeetingRooms: t.prismaField({
type: [this.serviceMeetingRoom()],
args: this.builder.generator.findManyArgs('ServiceMeetingRoom'),
description:
'Retrieve a list of service meeting rooms with optional filtering, ordering, and pagination.',
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.serviceMeetingRoom.findMany({
...query,
skip: args.skip ?? undefined,
take: args.take ?? undefined,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
},
}),
}));
}
}