fix: duplicate event types (#14007)
* fix: duplicate event types * test: add test for duplicate event type * fix: type error * chore: pass error message --------- Co-authored-by: Erik <[email protected]>
This commit is contained in:
1 parent
5c8e0483b1
commit
7d497a621f
5 files changed
+31
-7
No files matched your search
@@ -86,17 +86,18 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore - descriptionAsSafeHTML is added on the fly using a prisma middleware it shouldn't be used to create event type. Such a property doesn't exist on schema
|
||||
descriptionAsSafeHTML: _descriptionAsSafeHTML,
|
||||
secondaryEmailId,
|
||||
...rest
|
||||
} = eventType;
|
||||
|
||||
const data: Prisma.EventTypeUncheckedCreateInput = {
|
||||
const data: Prisma.EventTypeCreateInput = {
|
||||
...rest,
|
||||
title: newEventTitle,
|
||||
slug: newSlug,
|
||||
description: newDescription,
|
||||
length: newLength,
|
||||
locations: locations ?? undefined,
|
||||
teamId: team ? team.id : undefined,
|
||||
team: team ? { connect: { id: team.id } } : undefined,
|
||||
users: users ? { connect: users.map((user) => ({ id: user.id })) } : undefined,
|
||||
recurringEvent: recurringEvent || undefined,
|
||||
bookingLimits: bookingLimits ?? undefined,
|
||||
@@ -105,6 +106,24 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
|
||||
bookingFields: eventType.bookingFields === null ? Prisma.DbNull : eventType.bookingFields,
|
||||
};
|
||||
|
||||
// Validate the secondary email
|
||||
if (!!secondaryEmailId) {
|
||||
const secondaryEmail = await prisma.secondaryEmail.findUnique({
|
||||
where: {
|
||||
id: secondaryEmailId,
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
});
|
||||
// Make sure the secondary email id belongs to the current user and its a verified one
|
||||
if (secondaryEmail && secondaryEmail.emailVerified) {
|
||||
data.secondaryEmail = {
|
||||
connect: {
|
||||
id: secondaryEmailId,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const newEventType = await EventTypeRepository.create(data);
|
||||
|
||||
// Create custom inputs
|
||||
@@ -156,6 +175,6 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
|
||||
eventType: newEventType,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR" });
|
||||
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: `Error duplicating event type ${error}` });
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user