Skip to content

Commit

Permalink
Adds pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
zomars committed Mar 28, 2023
1 parent cee905b commit 3a08eb3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/web/pages/api/cron/downgradeUsers.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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({
Expand Down

0 comments on commit 3a08eb3

Please sign in to comment.