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

100% Statements 10/10
100% Branches 6/6
100% Functions 1/1
100% Lines 10/10

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      47x       169x   169x   169x   827x 191x   8998x         358x                     169x   169x    
import { logger } from "server/utils/logger";
import { User } from "shared/types/models/user";
 
export const getGroupMembersWithCreatorLotterySignups = (
  groupCreators: readonly User[],
  users: readonly User[],
): readonly User[] => {
  logger.debug("Get group members");
 
  const selectedAttendeesWithSignups: User[] = [];
 
  for (const groupCreator of groupCreators) {
    // Skip individual users
    if (groupCreator.groupCode !== "0") {
      for (const user of users) {
        // User is in the group but is not the creator
        if (
          user.groupCode === groupCreator.groupCode &&
          user.username !== groupCreator.username
        ) {
          // Group member gets group creator's lottery signups
          selectedAttendeesWithSignups.push(
            Object.assign({
              ...user,
              lotterySignups: groupCreator.lotterySignups,
            }) as User,
          );
        }
      }
    }
  }
 
  logger.debug(`Found ${selectedAttendeesWithSignups.length} group members`);
 
  return selectedAttendeesWithSignups;
};