MCPcopy Create free account
hub / github.com/RealDevSquad/website-backend / updateAllUserStatus

Function updateAllUserStatus

models/userStatus.js:291–377  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

289 nextState: futureState,
290 fallbackTimestamp: today,
291 });
292 if (lastOooUntilUpdate !== undefined) {
293 newStatusData.lastOooUntil = lastOooUntilUpdate;
294 }
295 toUpdate = !toUpdate;
296 summary.oooUsersAltered++;
297 } else {
298 summary.oooUsersUnaltered++;
299 }
300 } else {
301 // futureState is OOO
302 if (today > futureStatus.until) {
303 // the OOO period is over
304 delete newStatusData.futureStatus;
305 toUpdate = !toUpdate;
306 summary.nonOooUsersAltered++;
307 } else if (today <= doc.futureStatus.until && today >= doc.futureStatus.from) {
308 // the current date i.e today lies in between the from and until so we need to swap the status
309 let newCurrentStatus = {};
310 let newFutureStatus = {};
311 newCurrentStatus = { ...futureStatus, updatedAt: today };
312 if (currentStatus?.state) {
313 newFutureStatus = { ...currentStatus, from: futureStatus.until, updatedAt: today };
314 }
315 newStatusData.currentStatus = newCurrentStatus;
316 newStatusData.futureStatus = newFutureStatus;
317 newStatusData.lastOooUntil = null;
318 toUpdate = !toUpdate;
319 summary.nonOooUsersAltered++;
320 } else {
321 summary.nonOooUsersUnaltered++;
322 }
323 }
324 if (toUpdate) {
325 if (futureState === userState.IDLE && currentState !== userState.IDLE) {
326 await addGroupIdleRoleToDiscordUser(userId);
327 } else if (currentState === userState.IDLE && futureState !== userState.IDLE) {
328 await removeGroupIdleRoleFromDiscordUser(userId);
329 }
330 batch.set(docRef, newStatusData);
331 }
332 }
333 if (batch._ops.length > 100) {
334 logger.info(
335 `Warning: More than 100 User Status documents to update. The max limit permissible is 500. Refer https://github.com/Real-Dev-Squad/website-backend/issues/890 for more details.`,
336 );
337 }
338 await batch.commit();
339 return summary;
340 } catch (error) {
341 logger.error(`error in updating User Status Documents ${error}`);
342 return { status: 500, message: "User Status couldn't be updated Successfully." };
343 }
344};
345/**
346 * Updates the user status based on a new task assignment.
347 * @param {string} userId - The ID of the user.
348 * @returns {Promise<{

Callers

nothing calls this directly

Calls 4

resolveLastOooUntilFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected