| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  | import { GetServerSidePropsContext } from "next"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-06 17:20:30 +00:00
										 |  |  | import { getDefaultEvent } from "@calcom/lib/defaultEvents"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 21:33:18 +00:00
										 |  |  | import { asStringOrUndefined } from "@lib/asStringOrNull"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import prisma from "@lib/prisma"; | 
					
						
							| 
									
										
										
										
											2021-06-09 18:28:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  | export default function Type() { | 
					
						
							|  |  |  |   // Just redirect to the schedule page to reschedule it.
 | 
					
						
							|  |  |  |   return null; | 
					
						
							| 
									
										
										
										
											2021-06-09 18:28:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  | export async function getServerSideProps(context: GetServerSidePropsContext) { | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |   const booking = await prisma.booking.findUnique({ | 
					
						
							| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  |     where: { | 
					
						
							| 
									
										
										
										
											2021-09-29 21:33:18 +00:00
										 |  |  |       uid: asStringOrUndefined(context.query.uid), | 
					
						
							| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  |     select: { | 
					
						
							|  |  |  |       id: true, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       eventType: { | 
					
						
							|  |  |  |         select: { | 
					
						
							|  |  |  |           users: { | 
					
						
							|  |  |  |             select: { | 
					
						
							|  |  |  |               username: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           slug: true, | 
					
						
							|  |  |  |           team: { | 
					
						
							|  |  |  |             select: { | 
					
						
							|  |  |  |               slug: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2022-04-06 17:20:30 +00:00
										 |  |  |       dynamicEventSlugRef: true, | 
					
						
							|  |  |  |       dynamicGroupSlugRef: true, | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       user: true, | 
					
						
							| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  |       title: true, | 
					
						
							|  |  |  |       description: true, | 
					
						
							|  |  |  |       startTime: true, | 
					
						
							|  |  |  |       endTime: true, | 
					
						
							|  |  |  |       attendees: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-04-06 17:20:30 +00:00
										 |  |  |   const dynamicEventSlugRef = booking?.dynamicEventSlugRef || ""; | 
					
						
							|  |  |  |   if (!booking?.eventType && !booking?.dynamicEventSlugRef) throw Error("This booking doesn't exists"); | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-06 17:20:30 +00:00
										 |  |  |   const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef); | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const eventPage = | 
					
						
							| 
									
										
										
										
											2021-10-20 15:42:40 +00:00
										 |  |  |     (eventType.team | 
					
						
							|  |  |  |       ? "team/" + eventType.team.slug | 
					
						
							| 
									
										
										
										
											2022-04-06 17:20:30 +00:00
										 |  |  |       : dynamicEventSlugRef | 
					
						
							|  |  |  |       ? booking.dynamicGroupSlugRef | 
					
						
							| 
									
										
										
										
											2021-10-20 15:42:40 +00:00
										 |  |  |       : booking.user?.username || "rick") /* This shouldn't happen */ + | 
					
						
							|  |  |  |     "/" + | 
					
						
							| 
									
										
										
										
											2022-04-06 17:20:30 +00:00
										 |  |  |     eventType?.slug; | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  |   return { | 
					
						
							|  |  |  |     redirect: { | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |       destination: "/" + eventPage + "?rescheduleUid=" + context.query.uid, | 
					
						
							| 
									
										
										
										
											2021-08-19 12:27:01 +00:00
										 |  |  |       permanent: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-06-09 18:28:39 +00:00
										 |  |  | } |