165 lines
5.1 KiB
TypeScript
165 lines
5.1 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 AdminNoteSchema extends PothosSchema {
|
|
constructor(
|
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
|
private readonly prisma: PrismaService,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
@PothosRef()
|
|
adminNote() {
|
|
return this.builder.prismaObject('AdminNote', {
|
|
description: 'An admin note.',
|
|
fields: (t) => ({
|
|
id: t.exposeID('id', {
|
|
description: 'The ID of the admin note.',
|
|
}),
|
|
content: t.exposeString('content', {
|
|
description: 'The content of the admin note.',
|
|
}),
|
|
notedByUserId: t.exposeString('notedByUserId', {
|
|
description: 'The ID of the user who created the admin note.',
|
|
}),
|
|
notedBy: t.relation('notedBy', {
|
|
description: 'The user who created the admin note.',
|
|
}),
|
|
createdAt: t.expose('createdAt', {
|
|
type: 'DateTime',
|
|
description: 'The date and time the admin note was created.',
|
|
}),
|
|
updatedAt: t.expose('updatedAt', {
|
|
type: 'DateTime',
|
|
description: 'The date and time the admin note was last updated.',
|
|
}),
|
|
centerId: t.exposeString('centerId', {
|
|
description:
|
|
'The ID of the center the admin note is associated with.',
|
|
}),
|
|
serviceId: t.exposeString('serviceId', {
|
|
description:
|
|
'The ID of the service the admin note is associated with.',
|
|
}),
|
|
mentorId: t.exposeString('mentorId', {
|
|
description:
|
|
'The ID of the mentor the admin note is associated with.',
|
|
}),
|
|
resumeId: t.exposeString('resumeId', {
|
|
description:
|
|
'The ID of the resume the admin note is associated with.',
|
|
}),
|
|
mentor: t.relation('mentor', {
|
|
description: 'The mentor the admin note is associated with.',
|
|
}),
|
|
center: t.relation('center', {
|
|
description: 'The center the admin note is associated with.',
|
|
}),
|
|
service: t.relation('service', {
|
|
description: 'The service the admin note is associated with.',
|
|
}),
|
|
resume: t.relation('resume', {
|
|
description: 'The resume the admin note is associated with.',
|
|
}),
|
|
}),
|
|
})
|
|
}
|
|
|
|
@Pothos()
|
|
init(): void {
|
|
this.builder.queryFields((t) => ({
|
|
adminNote: t.prismaField({
|
|
type: this.adminNote(),
|
|
args: this.builder.generator.findUniqueArgs('AdminNote'),
|
|
description: 'Retrieve a single admin note by its unique identifier.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.adminNote.findUnique({
|
|
...query,
|
|
where: args.where,
|
|
})
|
|
},
|
|
}),
|
|
adminNotes: t.prismaField({
|
|
type: [this.adminNote()],
|
|
args: this.builder.generator.findManyArgs('AdminNote'),
|
|
description: 'Retrieve a list of admin notes.',
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.adminNote.findMany({
|
|
...query,
|
|
where: args.filter ?? undefined,
|
|
orderBy: args.orderBy ?? undefined,
|
|
cursor: args.cursor ?? undefined,
|
|
skip: args.skip ?? undefined,
|
|
take: args.take ?? undefined,
|
|
})
|
|
},
|
|
}),
|
|
}))
|
|
|
|
// Mutations
|
|
this.builder.mutationFields((t) => ({
|
|
createAdminNote: t.prismaField({
|
|
type: this.adminNote(),
|
|
args: {
|
|
input: t.arg({
|
|
type: this.builder.generator.getCreateInput('AdminNote'),
|
|
required: true,
|
|
}),
|
|
},
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.adminNote.create({
|
|
...query,
|
|
data: args.input,
|
|
})
|
|
},
|
|
}),
|
|
|
|
updateAdminNote: t.prismaField({
|
|
type: this.adminNote(),
|
|
args: {
|
|
where: t.arg({
|
|
type: this.builder.generator.getWhereUnique('AdminNote'),
|
|
required: true,
|
|
}),
|
|
data: t.arg({
|
|
type: this.builder.generator.getUpdateInput('AdminNote'),
|
|
required: true,
|
|
}),
|
|
},
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.adminNote.update({
|
|
...query,
|
|
where: args.where,
|
|
data: args.data,
|
|
})
|
|
},
|
|
}),
|
|
|
|
deleteAdminNote: t.prismaField({
|
|
type: this.adminNote(),
|
|
args: {
|
|
where: t.arg({
|
|
type: this.builder.generator.getWhereUnique('AdminNote'),
|
|
required: true,
|
|
}),
|
|
},
|
|
resolve: async (query, _root, args, _ctx, _info) => {
|
|
return await this.prisma.adminNote.delete({
|
|
...query,
|
|
where: args.where,
|
|
})
|
|
},
|
|
}),
|
|
}))
|
|
}
|
|
}
|