feat: enhance user validation and center owner checks in CenterMentorSchema
- Updated the CenterMentorSchema to include user validation by fetching user information based on email. - Implemented error handling to throw an error if the user is not found. - Modified the logic to block center owners from being invited as mentors by checking against the user's ID instead of the email. - Improved overall error messaging for better clarity when invitation conditions are not met.
This commit is contained in:
@@ -147,9 +147,16 @@ export class CenterMentorSchema extends PothosSchema {
|
|||||||
if (!userId) {
|
if (!userId) {
|
||||||
throw new Error('User ID is required')
|
throw new Error('User ID is required')
|
||||||
}
|
}
|
||||||
// block invite center owner
|
// get user info
|
||||||
const centerOwner = await prisma.center.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { centerOwnerId: userId },
|
where: { email: args.email },
|
||||||
|
})
|
||||||
|
if (!user) {
|
||||||
|
throw new Error('User not found')
|
||||||
|
}
|
||||||
|
// block invite center owner from another center
|
||||||
|
const centerOwner = await prisma.center.findFirst({
|
||||||
|
where: { centerOwnerId: user.id },
|
||||||
})
|
})
|
||||||
if (centerOwner) {
|
if (centerOwner) {
|
||||||
throw new Error('Center owner cannot be invited as a mentor')
|
throw new Error('Center owner cannot be invited as a mentor')
|
||||||
|
|||||||
Reference in New Issue
Block a user