implement platform config

This commit is contained in:
2024-10-29 19:06:01 +07:00
parent 075610fb9b
commit e003bcd634
11 changed files with 213 additions and 82 deletions

View File

@@ -205,7 +205,7 @@ export class UserSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args) => {
resolve: async (query, _root, args) => {
return await this.prisma.user.update({
...query,
where: args.where,
@@ -214,22 +214,42 @@ export class UserSchema extends PothosSchema {
},
}),
sendEmailTest: t.field({
inviteModerator: t.field({
type: 'String',
args: {
to: t.arg({ type: 'String', required: true }),
email: t.arg({ type: 'String', required: true }),
},
resolve: async (_parent, args) => {
await this.mailService.sendTemplateEmail(
[args.to],
'Bạn đã được mời làm việc tại Trung tâm băng đĩa lậu hải ngoại',
'MentorInvitation',
{
center_name: 'băng đĩa lậu hải ngoại',
invite_url: 'https://epess.org',
},
)
return 'Email sent'
resolve: async (_parent, args, ctx) => {
return this.prisma.$transaction(async (tx) => {
// check context
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
// check context is admin
if (ctx.http.me.role !== 'ADMIN') {
throw new UnauthorizedException(`Only admin can invite moderator`)
}
let user
// perform update role
try {
user = await tx.user.update({
where: { email: args.email },
data: { role: 'MODERATOR' },
})
} catch (_error) {
throw new Error(`User ${args.email} not found`)
}
// send email
await this.mailService.sendTemplateEmail(
[args.email],
'Thông báo chọn lựa quản trị viên cho người điều hành',
'ModeratorInvitation',
{
USER_NAME: user.name,
},
)
return 'Invited'
})
},
}),
}))