refactor source code

This commit is contained in:
2024-10-29 17:42:54 +07:00
parent 3b23d9e0b7
commit 152bb50da8
83 changed files with 8473 additions and 7577 deletions

View File

@@ -1,5 +1,5 @@
import { Module } from '@nestjs/common';
import { ResumeSchema } from './resume.schema';
import { Module } from '@nestjs/common'
import { ResumeSchema } from './resume.schema'
@Module({
providers: [ResumeSchema],

View File

@@ -1,14 +1,14 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { Inject, Injectable, Logger } 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 '../Minio/minio.service';
import { ResumeStatus } from '@prisma/client';
} from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
import { MinioService } from '../Minio/minio.service'
import { ResumeStatus } from '@prisma/client'
@Injectable()
export class ResumeSchema extends PothosSchema {
constructor(
@@ -16,7 +16,7 @@ export class ResumeSchema extends PothosSchema {
private readonly prisma: PrismaService,
private readonly minioService: MinioService,
) {
super();
super()
}
@PothosRef()
@@ -55,7 +55,7 @@ export class ResumeSchema extends PothosSchema {
description: 'The resume file for the resume.',
}),
}),
});
})
}
@PothosRef()
@@ -92,7 +92,7 @@ export class ResumeSchema extends PothosSchema {
description: 'The resume for the resume file.',
}),
}),
});
})
}
@Pothos()
init(): void {
@@ -109,7 +109,7 @@ export class ResumeSchema extends PothosSchema {
resolve: async (query, root, args, ctx, info) => {
try {
if (ctx.isSubscription) {
throw new Error('Not allowed');
throw new Error('Not allowed')
}
const resumes = await this.prisma.resume.findMany({
...query,
@@ -117,11 +117,11 @@ export class ResumeSchema extends PothosSchema {
userId: ctx.http.me.id,
status: args.status ?? undefined,
},
});
return resumes;
})
return resumes
} catch (error) {
Logger.error(error, 'myResumes');
return [];
Logger.error(error, 'myResumes')
return []
}
},
}),
@@ -137,7 +137,7 @@ export class ResumeSchema extends PothosSchema {
take: args.take ?? undefined,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
})
},
}),
@@ -149,8 +149,8 @@ export class ResumeSchema extends PothosSchema {
const resume = await this.prisma.resume.findUnique({
...query,
where: args.where,
});
return resume;
})
return resume
},
}),
@@ -162,11 +162,11 @@ export class ResumeSchema extends PothosSchema {
const resumeFile = await this.prisma.resumeFile.findUnique({
...query,
where: args.where,
});
})
if (!resumeFile) {
return null;
return null
}
return resumeFile;
return resumeFile
},
}),
resumeFiles: t.prismaField({
@@ -181,11 +181,11 @@ export class ResumeSchema extends PothosSchema {
take: args.take ?? undefined,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
return resumeFiles;
})
return resumeFiles
},
}),
}));
}))
// Mutations section
this.builder.mutationFields((t) => ({
@@ -207,15 +207,15 @@ export class ResumeSchema extends PothosSchema {
}),
},
resolve: async (query, root, args) => {
const { resumeFile } = args;
const { mimetype } = await resumeFile;
const { resumeFile } = args
const { mimetype } = await resumeFile
const { filename, actualFileName } =
await this.minioService.uploadFile(resumeFile, 'resumes');
await this.minioService.uploadFile(resumeFile, 'resumes')
const fileUrl = await this.minioService.getFileUrl(
filename,
'resumes',
);
const { userId, centerId } = args;
)
const { userId, centerId } = args
const resume = await this.prisma.resume.upsert({
...query,
where: {
@@ -245,8 +245,8 @@ export class ResumeSchema extends PothosSchema {
},
status: ResumeStatus.REQUESTED,
},
});
return resume;
})
return resume
},
}),
@@ -264,13 +264,13 @@ export class ResumeSchema extends PothosSchema {
}),
},
resolve: async (query, root, args) => {
const { resumeId, status } = args;
const { resumeId, status } = args
const resume = await this.prisma.resume.update({
...query,
where: { id: resumeId },
data: { status },
});
return resume;
})
return resume
},
}),
@@ -284,14 +284,14 @@ export class ResumeSchema extends PothosSchema {
}),
},
resolve: async (query, root, args) => {
const { resumeFileId } = args;
const { resumeFileId } = args
const resumeFile = await this.prisma.resumeFile.delete({
...query,
where: { id: resumeFileId },
});
return resumeFile;
})
return resumeFile
},
}),
}));
}))
}
}