96af17d8d7
* feat-profile-forwarding * fix for promises of handling * fix badge success color * clean up * fix suggested changes * Changed design on booking-forward pages and moar test * taking care of suggested changes, trpc errors and code cleaning * improve text * fix conflicting data-testid * fix unique data-testid * fix error css-global, email button styles, error conditional * rename files to match functionality, remove away ui * Add translations and migration * remove log * small fixes + improvements * fix styles to match new design * merge fixes * Fix styles dark mode * Solving merge conflicts from earlier * Fix/change test to match new elements * use trash icon button insted of dots (design issues) * only send email if toUserId is set * Fix date picker dark mode * merge with remote * removed status field from table and email its now for notify * small text improvement in email * check for team plan not paid plan * fixes and clean up due to removing status * fix old send request name to new behaviour * more naming improvements and text * remove status from handle-type * code clean up * fix type error --------- Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com>
72 lines
1.5 KiB
TypeScript
72 lines
1.5 KiB
TypeScript
import prisma from "@calcom/prisma";
|
|
|
|
interface HandleTypeRedirectionProps {
|
|
userId: number;
|
|
slug: string;
|
|
username: string;
|
|
}
|
|
|
|
export const handleTypeRedirection = async (props: HandleTypeRedirectionProps) => {
|
|
const { userId, slug, username } = props;
|
|
const outOfOfficeEntryActive = await prisma.outOfOfficeEntry.findFirst({
|
|
select: {
|
|
userId: true,
|
|
start: true,
|
|
end: true,
|
|
toUserId: true,
|
|
toUser: {
|
|
select: {
|
|
id: true,
|
|
username: true,
|
|
},
|
|
},
|
|
},
|
|
where: {
|
|
userId: userId,
|
|
start: {
|
|
lte: new Date(),
|
|
},
|
|
end: {
|
|
gte: new Date(),
|
|
},
|
|
},
|
|
});
|
|
|
|
let redirectToSameEventSlug = false;
|
|
|
|
// @TODO: Should I validate if new user has same type as slug?
|
|
if (outOfOfficeEntryActive) {
|
|
if (outOfOfficeEntryActive.toUserId === null) {
|
|
return {
|
|
outOfOffice: true,
|
|
};
|
|
}
|
|
if (outOfOfficeEntryActive?.toUser) {
|
|
const eventType = await prisma.eventType.findFirst({
|
|
select: {
|
|
slug: true,
|
|
userId: true,
|
|
},
|
|
where: {
|
|
slug,
|
|
userId: outOfOfficeEntryActive.toUserId,
|
|
},
|
|
});
|
|
|
|
if (eventType) {
|
|
redirectToSameEventSlug = true;
|
|
}
|
|
|
|
return {
|
|
redirect: {
|
|
destination: `/${outOfOfficeEntryActive.toUser.username}${
|
|
redirectToSameEventSlug ? `/${slug}` : ""
|
|
}?redirected=true&username=${username}`,
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
}
|
|
return {};
|
|
};
|