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

Function getTaskBasedUsersStatus

models/userStatus.js:621–672  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

619
620 return {
621 totalUsers,
622 totalIdleUsers,
623 totalActiveUsers,
624 totalUnprocessedUsers: 0,
625 unprocessedUsers: [],
626 users,
627 };
628};
629
630/**
631 * Cancels the Out-of-Office (OOO) status for a user.
632 * @param {string} userId - The ID of the user.
633 * @returns {Promise<object>} - A promise that resolves to an object with cancellation details.
634 * @throws {Error} - If there is an error fetching the user status document or updating the status.
635 */
636
637const cancelOooStatus = async (userId) => {
638 try {
639 let userStatusDoc;
640 let isActive;
641 try {
642 userStatusDoc = await userStatusModel.where("userId", "==", userId).get();
643 } catch (error) {
644 logger.error(`Unable to fetch user status document from the firestore : ${error.message}`);
645 throw error;
646 }
647 if (!userStatusDoc.size) {
648 throw new NotFound("No User status document found");
649 }
650 const [userStatusDocument] = userStatusDoc.docs;
651 const docId = userStatusDocument.id;
652 const { futureStatus, ...docData } = userStatusDocument.data();
653 if (docData.currentStatus.state !== userState.OOO) {
654 throw new Forbidden(
655 `The ${userState.OOO} Status cannot be canceled because the current status is ${docData.currentStatus.state}.`
656 );
657 }
658 try {
659 isActive = await checkIfUserHasLiveTasks(userId, tasksModel);
660 } catch (error) {
661 logger.error(`Unable to fetch user status based on the task : ${error.message}`);
662 throw error;
663 }
664 const updatedStatus = generateNewStatus(isActive);
665 const newStatusData = { ...docData, ...updatedStatus };
666 const lastOooUntilUpdate = resolveLastOooUntil({
667 previousState: docData.currentStatus?.state,
668 previousUntil: docData.currentStatus?.until,
669 nextState: updatedStatus.currentStatus?.state,
670 fallbackTimestamp: Date.now(),
671 });
672 if (lastOooUntilUpdate !== undefined) {
673 newStatusData.lastOooUntil = lastOooUntilUpdate;
674 }
675 if (futureStatus?.state) {

Callers 1

Calls 1

getMethod · 0.80

Tested by

no test coverage detected