From 774848dd453e93274d74a4833b9379d510987142 Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Sun, 10 Jul 2022 23:43:28 +0200 Subject: [PATCH] promisify clean expired notes --- server/src/app.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/server/src/app.ts b/server/src/app.ts index d127dbd..f81a489 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -89,22 +89,25 @@ app.post("/api/note/", postLimiter, (req: Request, res: Response, next) => { }); // Clean up expired notes periodically -export async function cleanExpiredNotes(): Promise { - try { - logger.info("[Cleanup] Cleaning up expired notes..."); - const deleted = await prisma.encryptedNote.deleteMany({ +export async function cleanExpiredNotes(): Promise { + logger.info("[Cleanup] Cleaning up expired notes..."); + return prisma.encryptedNote + .deleteMany({ where: { expire_time: { 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 =