💕💕💕💕💕

This commit is contained in:
2024-10-12 17:26:43 +07:00
parent 4fac0a052b
commit ed694f4ab7
6 changed files with 142 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,64 @@
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 UploadedDocumentSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super();
}
@PothosRef()
uploadedDocument() {
return this.builder.prismaObject('UploadedDocument', {
fields: (t) => ({
id: t.exposeID('id'),
userId: t.exposeID('userId'),
documentName: t.exposeString('documentName'),
documentType: t.exposeString('documentType'),
status: t.exposeString('status'),
type: t.exposeString('type'),
documentUrl: t.exposeString('documentUrl'),
uploadedAt: t.expose('uploadedAt', { type: 'DateTime' as any }),
}),
});
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
uploadedDocument: t.prismaField({
type: this.uploadedDocument(),
args: this.builder.generator.findUniqueArgs('UploadedDocument'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.uploadedDocument.findUnique({
...query,
where: args.where,
});
},
}),
uploadedDocuments: t.prismaField({
type: [this.uploadedDocument()],
args: this.builder.generator.findManyArgs('UploadedDocument'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.uploadedDocument.findMany({
...query,
skip: args.skip ?? 0,
take: args.take ?? 10,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
},
}),
}));
}
}