change to biome
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos';
|
||||
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';
|
||||
} from '@smatch-corp/nestjs-pothos'
|
||||
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'
|
||||
@Injectable()
|
||||
export class CenterMentorSchema extends PothosSchema {
|
||||
constructor(
|
||||
@@ -17,7 +17,7 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
private readonly mailService: MailService,
|
||||
private readonly jwtUtils: JwtUtils,
|
||||
) {
|
||||
super();
|
||||
super()
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
@@ -50,7 +50,7 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
description: 'The admin note of the center mentor.',
|
||||
}),
|
||||
}),
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
@@ -61,17 +61,17 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
'Retrieve a list of center mentors with optional filtering, ordering, and pagination.',
|
||||
type: [this.centerMentor()],
|
||||
args: this.builder.generator.findManyArgs('CenterMentor'),
|
||||
resolve: async (query, root, args) => {
|
||||
resolve: async (query, _root, args) => {
|
||||
return await this.prisma.centerMentor.findMany({
|
||||
...query,
|
||||
skip: args.skip ?? undefined,
|
||||
take: args.take ?? undefined,
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
where: args.filter ?? undefined,
|
||||
});
|
||||
})
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}))
|
||||
|
||||
// mutations
|
||||
this.builder.mutationFields((t) => ({
|
||||
@@ -84,11 +84,11 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args) => {
|
||||
resolve: async (query, _root, args) => {
|
||||
return await this.prisma.centerMentor.create({
|
||||
...query,
|
||||
data: args.data,
|
||||
});
|
||||
})
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -105,12 +105,12 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args) => {
|
||||
resolve: async (query, _root, args) => {
|
||||
return await this.prisma.centerMentor.update({
|
||||
...query,
|
||||
where: args.where,
|
||||
data: args.data,
|
||||
});
|
||||
})
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -123,11 +123,11 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args) => {
|
||||
resolve: async (query, _root, args) => {
|
||||
return await this.prisma.centerMentor.delete({
|
||||
...query,
|
||||
where: args.where,
|
||||
});
|
||||
})
|
||||
},
|
||||
}),
|
||||
inviteCenterMentor: t.prismaField({
|
||||
@@ -136,30 +136,30 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
args: {
|
||||
email: t.arg({ type: 'String', required: true }),
|
||||
},
|
||||
resolve: async (query, root, args, ctx) => {
|
||||
resolve: async (_query, _root, args, ctx) => {
|
||||
return this.prisma.$transaction(async (prisma) => {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed');
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
// get centerId by user id from context
|
||||
const userId = ctx.http.me.id;
|
||||
const userId = ctx.http.me.id
|
||||
if (!userId) {
|
||||
throw new Error('User ID is required');
|
||||
throw new Error('User ID is required')
|
||||
}
|
||||
// get centerId by user id
|
||||
const center = await prisma.center.findUnique({
|
||||
where: { centerOwnerId: userId },
|
||||
});
|
||||
})
|
||||
if (!center) {
|
||||
throw new Error('Center not found');
|
||||
throw new Error('Center not found')
|
||||
}
|
||||
// build signature
|
||||
const token = this.jwtUtils.signTokenRS256(
|
||||
{ centerId: center.id, email: args.email },
|
||||
'1d',
|
||||
);
|
||||
)
|
||||
// build invite url
|
||||
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`;
|
||||
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`
|
||||
// mail to user with params centerId, email
|
||||
await this.mailService.sendTemplateEmail(
|
||||
[args.email],
|
||||
@@ -169,9 +169,9 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
center_name: center.name,
|
||||
invite_url: inviteUrl,
|
||||
},
|
||||
);
|
||||
return null;
|
||||
});
|
||||
)
|
||||
return null
|
||||
})
|
||||
},
|
||||
}),
|
||||
testInviteCenterMentor: t.prismaField({
|
||||
@@ -181,15 +181,15 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
centerId: t.arg({ type: 'String', required: true }),
|
||||
},
|
||||
description: 'Test invite center mentor.',
|
||||
resolve: async (query, root, args) => {
|
||||
resolve: async (_query, _root, args) => {
|
||||
return this.prisma.$transaction(async () => {
|
||||
// sign token
|
||||
const token = this.jwtUtils.signTokenRS256(
|
||||
{ centerId: args.centerId, email: args.email },
|
||||
'1d',
|
||||
);
|
||||
)
|
||||
// build invite url
|
||||
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`;
|
||||
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`
|
||||
// mail to user with params centerId, email
|
||||
await this.mailService.sendTemplateEmail(
|
||||
[args.email],
|
||||
@@ -199,9 +199,9 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
center_name: args.centerId,
|
||||
invite_url: inviteUrl,
|
||||
},
|
||||
);
|
||||
return null;
|
||||
});
|
||||
)
|
||||
return null
|
||||
})
|
||||
},
|
||||
}),
|
||||
approveOrRejectCenterMentor: t.prismaField({
|
||||
@@ -215,43 +215,43 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
approved: t.arg({ type: 'Boolean', required: true }),
|
||||
adminNote: t.arg({ type: 'String', required: false }),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
resolve: async (_query, _root, args, ctx, _info) => {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed');
|
||||
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');
|
||||
throw new Error('Admin note is required')
|
||||
}
|
||||
// get mentor info
|
||||
const mentor = await prisma.user.findUnique({
|
||||
where: args.where,
|
||||
});
|
||||
})
|
||||
if (!mentor) {
|
||||
throw new Error('Mentor not found');
|
||||
throw new Error('Mentor not found')
|
||||
}
|
||||
// get centerMentor
|
||||
const centerMentor = await prisma.centerMentor.findUnique({
|
||||
where: { mentorId: mentor.id },
|
||||
});
|
||||
})
|
||||
if (!centerMentor) {
|
||||
throw new Error('Center mentor not found');
|
||||
throw new Error('Center mentor not found')
|
||||
}
|
||||
// get center
|
||||
const center = await prisma.center.findUnique({
|
||||
where: { id: centerMentor.centerId },
|
||||
});
|
||||
})
|
||||
if (!center) {
|
||||
throw new Error('Center not found');
|
||||
throw new Error('Center not found')
|
||||
}
|
||||
// get email
|
||||
const email = await prisma.user.findUnique({
|
||||
where: args.where,
|
||||
select: { email: true },
|
||||
});
|
||||
})
|
||||
if (!email) {
|
||||
throw new Error('Email is required');
|
||||
throw new Error('Email is required')
|
||||
}
|
||||
// if approved, update role to mentor
|
||||
if (args.approved) {
|
||||
@@ -264,7 +264,7 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
CENTER_NAME: center.name,
|
||||
USER_NAME: mentor.name,
|
||||
},
|
||||
);
|
||||
)
|
||||
// create adminNote
|
||||
const adminNote = await prisma.adminNote.create({
|
||||
data: {
|
||||
@@ -272,7 +272,7 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
mentorId: mentor.id,
|
||||
notedByUserId: ctx.http.me.id,
|
||||
},
|
||||
});
|
||||
})
|
||||
// update user role
|
||||
await prisma.user.update({
|
||||
where: args.where,
|
||||
@@ -280,7 +280,7 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
role: 'CENTER_MENTOR',
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
})
|
||||
// update centerMentor
|
||||
const updatedCenterMentor = await prisma.centerMentor.update({
|
||||
where: {
|
||||
@@ -292,8 +292,8 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
data: {
|
||||
adminNote: { connect: { id: adminNote.id } },
|
||||
},
|
||||
});
|
||||
return updatedCenterMentor;
|
||||
})
|
||||
return updatedCenterMentor
|
||||
}
|
||||
// if rejected, update adminNote
|
||||
await this.mailService.sendTemplateEmail(
|
||||
@@ -304,7 +304,7 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
CENTER_NAME: center.name,
|
||||
USER_NAME: mentor.name,
|
||||
},
|
||||
);
|
||||
)
|
||||
return await prisma.centerMentor.update({
|
||||
where: {
|
||||
mentorId_centerId: {
|
||||
@@ -321,10 +321,10 @@ export class CenterMentorSchema extends PothosSchema {
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user