From 8a9d8e905611e7b749f7e3410d6552e98200917b Mon Sep 17 00:00:00 2001 From: Eric Matala de Mazza Date: Sun, 30 Apr 2023 04:50:06 +0200 Subject: [PATCH] fix: fix display old duty message after rotate --- src/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4bffa59..bb27c6f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -136,22 +136,23 @@ bot.command("remind", async (ctx) => { const rotate = async () => { try { const roomies = await prisma.roomie.findMany({ include: { duty: true } }); - const n = await prisma.duty.count(); + const duties = await prisma.duty.findMany(); if (!roomies.every(({ duty, done }) => duty && done)) remind(); else { roomies .filter(({ duty }) => duty) - .forEach(async ({ id, duty, dutyId }) => { + .forEach(async ({ id, duty }) => { + const newDuty = duties.at(duty?.id! % duties.length)!; await prisma.roomie.update({ where: { id }, data: { done: false, - dutyId: (dutyId! % n) + 1, + dutyId: newDuty.id, }, }); bot.telegram.sendMessage( id, - getDutiesRotatedMessage(duty!.title, duty!.description) + getDutiesRotatedMessage(newDuty.title, newDuty.description) ); }); }