Revalidate booking pages on updateProfile (#7941)

This commit is contained in:
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

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(