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); }