Files
stats/apps/worker/src/jobs/cron.salt.ts
Carl-Gerhard Lindesvärd 5e225b7ae6 batching events
2024-07-17 17:27:19 +02:00

23 lines
485 B
TypeScript

import { generateSalt } from '@openpanel/common';
import { db, getCurrentSalt } from '@openpanel/db';
export async function salt() {
const oldSalt = await getCurrentSalt().catch(() => null);
const newSalt = await db.salt.create({
data: {
salt: generateSalt(),
},
});
// Delete rest of the salts
await db.salt.deleteMany({
where: {
salt: {
notIn: oldSalt ? [newSalt.salt, oldSalt] : [newSalt.salt],
},
},
});
return newSalt;
}