fix admin note is required in mentor

This commit is contained in:
2024-10-29 19:49:22 +07:00
parent e003bcd634
commit 8631bd935d
5 changed files with 32 additions and 23 deletions

View File

@@ -64,7 +64,7 @@ export class AppConfigSchema extends PothosSchema {
type: this.appConfig(), type: this.appConfig(),
description: 'Get an app config by key', description: 'Get an app config by key',
args: this.builder.generator.findUniqueArgs('Config'), args: this.builder.generator.findUniqueArgs('Config'),
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.config.findUnique({ return await this.prisma.config.findUnique({
...query, ...query,
where: args.where ?? undefined, where: args.where ?? undefined,
@@ -84,7 +84,7 @@ export class AppConfigSchema extends PothosSchema {
required: true, required: true,
}), }),
}, },
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.config.create({ return await this.prisma.config.create({
...query, ...query,
data: args.input, data: args.input,
@@ -100,7 +100,7 @@ export class AppConfigSchema extends PothosSchema {
required: true, required: true,
}), }),
}, },
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.config.createManyAndReturn({ return await this.prisma.config.createManyAndReturn({
...query, ...query,
data: args.input, data: args.input,

View File

@@ -13,6 +13,7 @@ export class AppConfigService implements OnModuleInit {
const configs = await this.prisma.config.findMany() const configs = await this.prisma.config.findMany()
if (configs.length === 0) { if (configs.length === 0) {
Object.entries(ConfigConstants).forEach(async ([_key, value]) => { Object.entries(ConfigConstants).forEach(async ([_key, value]) => {
try {
await this.prisma.config.create({ await this.prisma.config.create({
data: { data: {
name: value.name, name: value.name,
@@ -21,6 +22,7 @@ export class AppConfigService implements OnModuleInit {
visible: value.visible, visible: value.visible,
}, },
}) })
} catch (_error) {}
}) })
} }
} }
@@ -50,9 +52,20 @@ export class AppConfigService implements OnModuleInit {
}) })
} }
async deleteConfig(key: string) { async resetConfig(key: string) {
return await this.prisma.config.delete({ // reset config to default value
await this.prisma.config.update({
where: { key }, where: { key },
data: ConfigConstants[key],
})
}
async resetAllConfigs() {
// reset all configs to default values
Object.entries(ConfigConstants).forEach(async ([_key, value]) => {
await this.prisma.config.create({
data: value,
})
}) })
} }
} }

View File

@@ -282,7 +282,7 @@ export class CenterSchema extends PothosSchema {
'CenterRejected', 'CenterRejected',
{ {
CENTER_NAME: center.name, CENTER_NAME: center.name,
ADMIN_NOTE: args.adminNote, ADMIN_NOTE: args.adminNote ?? '',
}, },
) )
} catch (error) { } catch (error) {

View File

@@ -163,7 +163,7 @@ export class CenterMentorSchema extends PothosSchema {
// mail to user with params centerId, email // mail to user with params centerId, email
await this.mailService.sendTemplateEmail( await this.mailService.sendTemplateEmail(
[args.email], [args.email],
'Invite to center', `Thư mời làm việc tại trung tâm ${center.name}`,
'MentorInvitation', 'MentorInvitation',
{ {
center_name: center.name, center_name: center.name,
@@ -220,10 +220,6 @@ export class CenterMentorSchema extends PothosSchema {
throw new Error('Not allowed') throw new Error('Not allowed')
} }
return this.prisma.$transaction(async (prisma) => { return this.prisma.$transaction(async (prisma) => {
// validate input
if (args.approved && !args.adminNote) {
throw new Error('Admin note is required')
}
// get mentor info // get mentor info
const mentor = await prisma.user.findUnique({ const mentor = await prisma.user.findUnique({
where: args.where, where: args.where,

View File

@@ -135,7 +135,7 @@ export class UserSchema extends PothosSchema {
me: t.prismaField({ me: t.prismaField({
description: 'Retrieve the current user in context.', description: 'Retrieve the current user in context.',
type: this.user(), type: this.user(),
resolve: async (query, root, args, ctx) => { resolve: async (_query, _root, _args, ctx) => {
if (ctx.isSubscription) { if (ctx.isSubscription) {
throw new Error('Not allowed') throw new Error('Not allowed')
} }
@@ -148,7 +148,7 @@ export class UserSchema extends PothosSchema {
'Retrieve a list of users with optional filtering, ordering, and pagination.', 'Retrieve a list of users with optional filtering, ordering, and pagination.',
type: [this.user()], type: [this.user()],
args: this.builder.generator.findManyArgs('User'), args: this.builder.generator.findManyArgs('User'),
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.user.findMany({ return await this.prisma.user.findMany({
...query, ...query,
take: args.take ?? undefined, take: args.take ?? undefined,
@@ -163,7 +163,7 @@ export class UserSchema extends PothosSchema {
description: 'Retrieve a single user by their unique identifier.', description: 'Retrieve a single user by their unique identifier.',
type: this.user(), type: this.user(),
args: this.builder.generator.findUniqueArgs('User'), args: this.builder.generator.findUniqueArgs('User'),
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
return await this.prisma.user.findUniqueOrThrow({ return await this.prisma.user.findUniqueOrThrow({
...query, ...query,
where: args.where, where: args.where,
@@ -176,7 +176,7 @@ export class UserSchema extends PothosSchema {
args: { args: {
sessionId: t.arg({ type: 'String', required: true }), sessionId: t.arg({ type: 'String', required: true }),
}, },
resolve: async (query, root, args) => { resolve: async (query, _root, args) => {
// check if the token is valid // check if the token is valid
const session = await clerkClient.sessions.getSession(args.sessionId) const session = await clerkClient.sessions.getSession(args.sessionId)
Logger.log(session, 'Session') Logger.log(session, 'Session')