promisify clean expired notes

This commit is contained in:
Maxime Cannoodt 2022-07-10 23:43:28 +02:00
parent c64633ecd0
commit 774848dd45

View File

@ -89,22 +89,25 @@ app.post("/api/note/", postLimiter, (req: Request, res: Response, next) => {
}); });
// Clean up expired notes periodically // Clean up expired notes periodically
export async function cleanExpiredNotes(): Promise<number | undefined> { export async function cleanExpiredNotes(): Promise<number> {
try { logger.info("[Cleanup] Cleaning up expired notes...");
logger.info("[Cleanup] Cleaning up expired notes..."); return prisma.encryptedNote
const deleted = await prisma.encryptedNote.deleteMany({ .deleteMany({
where: { where: {
expire_time: { expire_time: {
lte: new Date(), lte: new Date(),
}, },
}, },
})
.then((deleted) => {
logger.info(`[Cleanup] Deleted ${deleted.count} expired notes.`);
return deleted.count;
})
.catch((err) => {
logger.error(`[Cleanup] Error cleaning expired notes:`);
logger.error(err);
return -1;
}); });
logger.info(`[Cleanup] Deleted ${deleted.count} expired notes.`);
return deleted.count;
} catch (err) {
logger.error(`[Cleanup] Error cleaning expired notes:`);
logger.error(err);
}
} }
const interval = const interval =