All files / server/src/features/assignment/utils getGroupCreators.ts

100% Statements 18/18
100% Branches 8/8
100% Functions 1/1
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48        47x       169x     169x   169x       7587x 2704x     7199x   7199x 1782x 47310x       827x 827x       1782x 827x 827x         169x       169x    
import { logger } from "server/utils/logger";
import { User } from "shared/types/models/user";
import { ProgramItem } from "shared/types/models/programItem";
 
export const getGroupCreators = (
  users: readonly User[],
  startingProgramItems: readonly ProgramItem[],
): User[] => {
  logger.debug("Get group creators");
 
  // Get users who have lottery signups for starting program items
  const selectedAttendees: User[] = [];
 
  for (const user of users) {
    // Only individuals and group creators carry lottery signups into the assignment.
    // A non-creator member's signups must not turn them into a group creator, which
    // would duplicate the group when its members are expanded
    if (user.groupCode !== "0" && !user.isGroupCreator) {
      continue;
    }
 
    let match = false;
    // eslint-disable-next-line @typescript-eslint/prefer-for-of
    for (let i = 0; i < user.lotterySignups.length; i += 1) {
      for (const startingProgramItem of startingProgramItems) {
        if (
          user.lotterySignups[i].programItemId ===
          startingProgramItem.programItemId
        ) {
          match = true;
          break;
        }
      }
      // User matched, break
      if (match) {
        selectedAttendees.push(user);
        break;
      }
    }
  }
 
  logger.debug(
    `Found ${selectedAttendees.length} group creators for this start time`,
  );
 
  return selectedAttendees;
};