From 84bce6ed2e796d75e00cb2db1ef25757c99d9f08 Mon Sep 17 00:00:00 2001 From: FelipeCarillo Date: Sat, 8 Jun 2024 21:30:49 -0300 Subject: [PATCH] refactor: Update update_users_activity_status to use forEach instead of for loop --- .../database/repositories/ActivityRepo.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/repositories/database/repositories/ActivityRepo.ts b/src/core/repositories/database/repositories/ActivityRepo.ts index 9dec53d..f66ca49 100644 --- a/src/core/repositories/database/repositories/ActivityRepo.ts +++ b/src/core/repositories/database/repositories/ActivityRepo.ts @@ -439,20 +439,21 @@ export class ActivityRepo implements IActivityRepo { async update_users_activity_status(activity_id: string, users: { user_id: string, status: boolean }[]): Promise { let response = true; - for (const user of users) { - const [affectedCount] = await ActivityApplication.update({ + users.forEach(async user => { + const response_user = await ActivityApplication.update({ status: user.status }, { where: { - activity_id: activity_id, - user_id: user.user_id + [Op.and]: [ + { activity_id: activity_id }, + { user_id: user.user_id } + ] } }); - - if (affectedCount === 0) { + if (response_user[0] === 0) { response = false; } - } + }); return response; }