This repository has been archived on 2026-02-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
synthetic-consumer-data/utils/rateLimiter.ts

31 lines
663 B
TypeScript

import prisma from '@prisma';
export async function rateLimiter() {
if (!process.env.RATE_LIMIT) {
throw Error('Rate limit missing.');
}
const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000);
const count = await prisma.$transaction(async tx => {
const consumersCount = await tx.consumer.count({
where: {
createdAt: {
gt: yesterday
}
}
});
const purchaseListsCount = await tx.purchaseList.count({
where: {
createdAt: {
gt: yesterday
}
}
});
return consumersCount + purchaseListsCount;
});
return count > parseInt(process.env.RATE_LIMIT);
}