add approve or reject mentor
This commit is contained in:
@@ -9,6 +9,7 @@ import { Builder } from '../Graphql/graphql.builder';
|
||||
import { PrismaService } from '../Prisma/prisma.service';
|
||||
import { MailService } from '../Mail/mail.service';
|
||||
import { JwtUtils } from '../common/utils/jwt.utils';
|
||||
import { UserSchema } from 'src/User/user.schema';
|
||||
@Injectable()
|
||||
export class CenterMentorSchema extends PothosSchema {
|
||||
constructor(
|
||||
@@ -16,6 +17,7 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly mailService: MailService,
|
||||
private readonly jwtUtils: JwtUtils,
|
||||
private readonly userSchema: UserSchema,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -198,6 +200,46 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
});
|
||||
},
|
||||
}),
|
||||
approveOrRejectCenterMentor: t.prismaField({
|
||||
type: this.userSchema.user(),
|
||||
description: 'Approve or reject a center mentor.',
|
||||
args: {
|
||||
where: t.arg({
|
||||
type: this.builder.generator.getWhereUnique('User'),
|
||||
required: true,
|
||||
}),
|
||||
approved: t.arg({ type: 'Boolean', required: true }),
|
||||
adminNote: t.arg({ type: 'String', required: false }),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return this.prisma.$transaction(async (prisma) => {
|
||||
// if approved, update role to mentor
|
||||
if (args.approved) {
|
||||
return await prisma.user.update({
|
||||
where: args.where,
|
||||
data: {
|
||||
role: 'CENTER_MENTOR',
|
||||
updatedAt: new Date(),
|
||||
adminNote: {
|
||||
create: {
|
||||
content: args.adminNote ?? '',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
// if rejected, update adminNote
|
||||
return await prisma.user.update({
|
||||
where: args.where,
|
||||
data: {
|
||||
adminNote: {
|
||||
create: { content: args.adminNote ?? '' },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user