From 3a08eb3dca922309ccb5ff5357a9a991e406e9e3 Mon Sep 17 00:00:00 2001 From: zomars Date: Tue, 28 Mar 2023 14:55:43 -0700 Subject: [PATCH] Adds pagination --- apps/web/pages/api/cron/downgradeUsers.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/web/pages/api/cron/downgradeUsers.ts b/apps/web/pages/api/cron/downgradeUsers.ts index a0a7995176..5ea1329ecb 100644 --- a/apps/web/pages/api/cron/downgradeUsers.ts +++ b/apps/web/pages/api/cron/downgradeUsers.ts @@ -1,8 +1,13 @@ import type { NextApiRequest, NextApiResponse } from "next"; +import { z } from "zod"; import { updateQuantitySubscriptionFromStripe } from "@calcom/features/ee/teams/lib/payments"; import prisma from "@calcom/prisma"; +const querySchema = z.object({ + page: z.coerce.number().min(0).optional().default(0), +}); + export default async function handler(req: NextApiRequest, res: NextApiResponse) { const apiKey = req.headers.authorization || req.query.apiKey; if (process.env.CRON_API_KEY !== apiKey) { @@ -16,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); const pageSize = 90; // Adjust this value based on the total number of teams and the available processing time - let pageNumber = 0; + let { page: pageNumber } = querySchema.parse(req.query); while (true) { const teams = await prisma.team.findMany({