Revalidate booking pages on updateProfile (#7941)

pull/7931/merge
Efraín Rochín 2023-03-25 14:06:43 -07:00 committed by GitHub
parent a571d40958
commit 0365157638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import type { DestinationCalendar, Prisma } from "@prisma/client";
import { AppCategories, BookingStatus, IdentityProvider } from "@prisma/client";
import { cityMapping } from "city-timezones";
import { reverse } from "lodash";
import type { NextApiResponse } from "next";
import { authenticator } from "otplib";
import z from "zod";
@ -709,6 +710,25 @@ const loggedInViewerRouter = router({
},
});
}
// Revalidate booking pages
const res = ctx.res as NextApiResponse;
if (typeof res?.revalidate !== "undefined") {
const eventTypes = await prisma.eventType.findMany({
where: {
userId: user.id,
team: null,
hidden: false,
},
select: {
id: true,
slug: true,
},
});
// waiting for this isn't needed
Promise.all(eventTypes.map((eventType) => res?.revalidate(`/${ctx.user.username}/${eventType.slug}`)))
.then(() => console.info("Booking pages revalidated"))
.catch((e) => console.error(e));
}
}),
eventTypeOrder: authedProcedure
.input(