diff --git a/src/AppConfig/appconfig.schema.ts b/src/AppConfig/appconfig.schema.ts index 982e673..6d36ea4 100644 --- a/src/AppConfig/appconfig.schema.ts +++ b/src/AppConfig/appconfig.schema.ts @@ -64,7 +64,7 @@ export class AppConfigSchema extends PothosSchema { type: this.appConfig(), description: 'Get an app config by key', args: this.builder.generator.findUniqueArgs('Config'), - resolve: async (query, root, args) => { + resolve: async (query, _root, args) => { return await this.prisma.config.findUnique({ ...query, where: args.where ?? undefined, @@ -84,7 +84,7 @@ export class AppConfigSchema extends PothosSchema { required: true, }), }, - resolve: async (query, root, args) => { + resolve: async (query, _root, args) => { return await this.prisma.config.create({ ...query, data: args.input, @@ -100,7 +100,7 @@ export class AppConfigSchema extends PothosSchema { required: true, }), }, - resolve: async (query, root, args) => { + resolve: async (query, _root, args) => { return await this.prisma.config.createManyAndReturn({ ...query, data: args.input, diff --git a/src/AppConfig/appconfig.service.ts b/src/AppConfig/appconfig.service.ts index 2d36c9d..be95237 100644 --- a/src/AppConfig/appconfig.service.ts +++ b/src/AppConfig/appconfig.service.ts @@ -13,14 +13,16 @@ export class AppConfigService implements OnModuleInit { const configs = await this.prisma.config.findMany() if (configs.length === 0) { Object.entries(ConfigConstants).forEach(async ([_key, value]) => { - await this.prisma.config.create({ - data: { - name: value.name, - key: value.key, - value: value.value, - visible: value.visible, - }, - }) + try { + await this.prisma.config.create({ + data: { + name: value.name, + key: value.key, + value: value.value, + visible: value.visible, + }, + }) + } catch (_error) {} }) } } @@ -50,9 +52,20 @@ export class AppConfigService implements OnModuleInit { }) } - async deleteConfig(key: string) { - return await this.prisma.config.delete({ + async resetConfig(key: string) { + // reset config to default value + await this.prisma.config.update({ 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, + }) }) } } diff --git a/src/Center/center.schema.ts b/src/Center/center.schema.ts index a54cfef..1dd0844 100644 --- a/src/Center/center.schema.ts +++ b/src/Center/center.schema.ts @@ -282,7 +282,7 @@ export class CenterSchema extends PothosSchema { 'CenterRejected', { CENTER_NAME: center.name, - ADMIN_NOTE: args.adminNote, + ADMIN_NOTE: args.adminNote ?? '', }, ) } catch (error) { diff --git a/src/CenterMentor/centermentor.schema.ts b/src/CenterMentor/centermentor.schema.ts index 748e300..83680c1 100644 --- a/src/CenterMentor/centermentor.schema.ts +++ b/src/CenterMentor/centermentor.schema.ts @@ -163,7 +163,7 @@ export class CenterMentorSchema extends PothosSchema { // mail to user with params centerId, email await this.mailService.sendTemplateEmail( [args.email], - 'Invite to center', + `Thư mời làm việc tại trung tâm ${center.name}`, 'MentorInvitation', { center_name: center.name, @@ -220,10 +220,6 @@ export class CenterMentorSchema extends PothosSchema { throw new Error('Not allowed') } return this.prisma.$transaction(async (prisma) => { - // validate input - if (args.approved && !args.adminNote) { - throw new Error('Admin note is required') - } // get mentor info const mentor = await prisma.user.findUnique({ where: args.where, diff --git a/src/User/user.schema.ts b/src/User/user.schema.ts index a468b0a..5f4835f 100644 --- a/src/User/user.schema.ts +++ b/src/User/user.schema.ts @@ -135,7 +135,7 @@ export class UserSchema extends PothosSchema { me: t.prismaField({ description: 'Retrieve the current user in context.', type: this.user(), - resolve: async (query, root, args, ctx) => { + resolve: async (_query, _root, _args, ctx) => { if (ctx.isSubscription) { 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.', type: [this.user()], args: this.builder.generator.findManyArgs('User'), - resolve: async (query, root, args) => { + resolve: async (query, _root, args) => { return await this.prisma.user.findMany({ ...query, take: args.take ?? undefined, @@ -163,7 +163,7 @@ export class UserSchema extends PothosSchema { description: 'Retrieve a single user by their unique identifier.', type: this.user(), args: this.builder.generator.findUniqueArgs('User'), - resolve: async (query, root, args) => { + resolve: async (query, _root, args) => { return await this.prisma.user.findUniqueOrThrow({ ...query, where: args.where, @@ -176,7 +176,7 @@ export class UserSchema extends PothosSchema { args: { sessionId: t.arg({ type: 'String', required: true }), }, - resolve: async (query, root, args) => { + resolve: async (query, _root, args) => { // check if the token is valid const session = await clerkClient.sessions.getSession(args.sessionId) Logger.log(session, 'Session')