28 lines
572 B
TypeScript
28 lines
572 B
TypeScript
import prisma from '../prisma/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 consumersCount = await prisma.consumer.count({
|
|
where: {
|
|
createdAt: {
|
|
gt: yesterday
|
|
}
|
|
}
|
|
});
|
|
|
|
const purchaseListsCount = await prisma.purchaseList.count({
|
|
where: {
|
|
createdAt: {
|
|
gt: yesterday
|
|
}
|
|
}
|
|
});
|
|
|
|
return consumersCount + purchaseListsCount > parseInt(process.env.RATE_LIMIT);
|
|
}
|