update logic upload file and get centerstaff
This commit is contained in:
@@ -67,6 +67,24 @@ export class CenterSchema extends PothosSchema {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
// get current center of centerstaff by providing userId
|
||||||
|
centerByCenterStaff: t.prismaField({
|
||||||
|
type: this.center(),
|
||||||
|
args: {
|
||||||
|
userId: t.arg({ type: 'String', required: true }),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args, ctx, info) => {
|
||||||
|
return await this.prisma.center.findFirst({
|
||||||
|
where: {
|
||||||
|
CenterStaff: {
|
||||||
|
some: {
|
||||||
|
staffId: args.userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// mutation section
|
// mutation section
|
||||||
|
|||||||
@@ -41,10 +41,10 @@ export class MinioService {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteFile(fileName: string) {
|
async deleteFile(fileName: string, category: string) {
|
||||||
return await this.minioClient.removeObject(
|
return await this.minioClient.removeObject(
|
||||||
this.configService.get('BUCKET_NAME') ?? 'epess',
|
this.configService.get('BUCKET_NAME') ?? 'epess',
|
||||||
fileName,
|
`${category}/${fileName}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import { Builder } from '../Graphql/graphql.builder';
|
import { Builder } from '../Graphql/graphql.builder';
|
||||||
import { PrismaService } from '../Prisma/prisma.service';
|
import { PrismaService } from '../Prisma/prisma.service';
|
||||||
import { MinioService } from '../Minio/minio.service';
|
import { MinioService } from '../Minio/minio.service';
|
||||||
|
import { ResumeStatus } from '@prisma/client';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ResumeSchema extends PothosSchema {
|
export class ResumeSchema extends PothosSchema {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -179,6 +180,29 @@ export class ResumeSchema extends PothosSchema {
|
|||||||
return resume;
|
return resume;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
updateResumeStatus: t.prismaField({
|
||||||
|
type: this.resume(),
|
||||||
|
args: {
|
||||||
|
resumeId: t.arg({
|
||||||
|
type: 'String',
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
status: t.arg({
|
||||||
|
type: ResumeStatus,
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args) => {
|
||||||
|
const { resumeId, status } = args;
|
||||||
|
const resume = await this.prisma.resume.update({
|
||||||
|
...query,
|
||||||
|
where: { id: resumeId },
|
||||||
|
data: { status },
|
||||||
|
});
|
||||||
|
return resume;
|
||||||
|
},
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,124 @@ export class UploadedFileSchema extends PothosSchema {
|
|||||||
return uploadedFile;
|
return uploadedFile;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
multipleUpload: t.prismaField({
|
||||||
|
type: [this.uploadedFile()],
|
||||||
|
args: {
|
||||||
|
userId: t.arg({
|
||||||
|
type: 'String',
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
files: t.arg({
|
||||||
|
type: ['Upload'],
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
fileType: t.arg({
|
||||||
|
type: UploadedFileType,
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args) => {
|
||||||
|
const user = await this.prisma.user.findUnique({
|
||||||
|
where: {
|
||||||
|
id: args.userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!user) {
|
||||||
|
throw new Error('User not found');
|
||||||
|
}
|
||||||
|
const uploadedFiles = await Promise.all(
|
||||||
|
args.files.map((file) =>
|
||||||
|
this.minioService.uploadFile(file, 'files'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// get file urls
|
||||||
|
const fileUrls = await Promise.all(
|
||||||
|
uploadedFiles.map((file) =>
|
||||||
|
this.minioService.getFileUrl(file.filename, 'files'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// map uploadedFiles to db
|
||||||
|
const dbFiles = uploadedFiles.map((file, index) => ({
|
||||||
|
userId: user.id,
|
||||||
|
fileName: file.filename,
|
||||||
|
type: file.mimetype,
|
||||||
|
fileType: args.fileType,
|
||||||
|
fileUrl: fileUrls[index],
|
||||||
|
uploadedAt: new Date(),
|
||||||
|
}));
|
||||||
|
// create files in db
|
||||||
|
const createdFiles =
|
||||||
|
await this.prisma.uploadedFile.createManyAndReturn({
|
||||||
|
data: dbFiles,
|
||||||
|
});
|
||||||
|
return createdFiles;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
deleteUploadedFile: t.prismaField({
|
||||||
|
type: this.uploadedFile(),
|
||||||
|
args: {
|
||||||
|
id: t.arg({
|
||||||
|
type: 'String',
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args) => {
|
||||||
|
const file = await this.prisma.uploadedFile.findUnique({
|
||||||
|
where: {
|
||||||
|
id: args.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!file) {
|
||||||
|
throw new Error('File not found');
|
||||||
|
}
|
||||||
|
await this.minioService.deleteFile(file.fileName, 'files');
|
||||||
|
await this.prisma.uploadedFile.delete({
|
||||||
|
where: {
|
||||||
|
id: file.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return file;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
deleteUploadedFiles: t.prismaField({
|
||||||
|
type: [this.uploadedFile()],
|
||||||
|
args: {
|
||||||
|
ids: t.arg({
|
||||||
|
type: ['String'],
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
resolve: async (query, root, args) => {
|
||||||
|
const files = await this.prisma.uploadedFile.findMany({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
in: args.ids,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const fileUrls = await Promise.all(
|
||||||
|
files.map((file) =>
|
||||||
|
this.minioService.getFileUrl(file.fileName, 'files'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await this.prisma.uploadedFile.deleteMany({
|
||||||
|
where: {
|
||||||
|
id: {
|
||||||
|
in: args.ids,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await Promise.all(
|
||||||
|
files.map((file, index) =>
|
||||||
|
this.minioService.deleteFile(file.fileName, 'files'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return files;
|
||||||
|
},
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user