fix admin note is required in mentor
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -13,14 +13,16 @@ 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]) => {
|
||||||
await this.prisma.config.create({
|
try {
|
||||||
data: {
|
await this.prisma.config.create({
|
||||||
name: value.name,
|
data: {
|
||||||
key: value.key,
|
name: value.name,
|
||||||
value: value.value,
|
key: value.key,
|
||||||
visible: value.visible,
|
value: value.value,
|
||||||
},
|
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,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|||||||
Reference in New Issue
Block a user