Skip to content

Commit

Permalink
fix: fix display old duty message after rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
ematala committed Apr 30, 2023
1 parent 816b76f commit 8a9d8e9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
});
}
Expand Down

0 comments on commit 8a9d8e9

Please sign in to comment.