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

100% Statements 11/11
75% Branches 3/4
100% Functions 2/2
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      45x     434x   69x 69x 130x 130x   57x 254x     73x         69x    
import { groupBy } from "remeda";
import { User } from "shared/types/models/user";
 
export const getAttendeeGroups = (
  attendees: readonly User[],
): readonly User[][] => {
  const groupedUsers = groupBy(attendees, (attendee) => attendee.groupCode);
 
  const attendeesArray: User[][] = [];
  for (const [groupCode, users] of Object.entries(groupedUsers)) {
    Eif (Array.isArray(users)) {
      if (groupCode === "0") {
        // Loop array and add attendees individually
        for (const user of users) {
          attendeesArray.push([user]);
        }
      } else {
        attendeesArray.push(users);
      }
    }
  }
 
  return attendeesArray;
};