Repository: thenewboston-developers/Website
File: src/utils/data.ts (TypeScript)

Code before:
};

export const getOpenings = (): Opening[] => {
  return openings as Opening[];
};

export const getTasks = (): TaskDict => {
  const results: any = {};

  Object.entries(tasks).forEach(([githubUsername, taskList]) => {
    results[githubUsername] = (taskList as RawTask[]).map(
      (task: RawTask): Task => ({
        ...task,
        completed_date: parse(task.completed_date, 'L/d/yy', new Date()),
      }),
    );
  });

  return results;
};

export const getTeamMembers = (): TeamMember[] => {
  const members: any = {};
  teams.forEach((team) => {
    const {title: teamTitle, contributors: teamContributors} = team;
    teamContributors.forEach((teamMember: any) => {
      const {title: userTitle, isLead, payPerDay, createdDate, contributor} = teamMember;
      const {contributorId, ...otherProps} = contributor;
      if (!members[contributorId]) {
        members[contributorId] = {
          contributorId,
          createdDate,
          isLead,
          payPerDay,
          teams: [{isLead, title: teamTitle}],
          titles: [userTitle],
          ...otherProps,
        };
      } else {
        const member = members[contributorId];
        const {teams: addedTeams, titles, isLead: isLeadForAddedTeams} = member;
        const teamNameExists =
          addedTeams.findIndex(({title}: {title: string}) => title.toLowerCase() === teamTitle.toLowerCase()) !== -1;
        const titleExists = titles.findIndex((title: string) => title.toLowerCase() === userTitle.toLowerCase()) !== -1;
        members[contributorId] = {
          ...member,
          isLead: isLeadForAddedTeams || isLead,
          teams: teamNameExists ? addedTeams : addedTeams.concat([{isLead, title: teamTitle}]),
          titles: titleExists ? titles : titles.concat([userTitle]),
        };
      }

Review comment (suggestion):
not sure why typescript is complaining when not placed `any`

Code after:
};

export const getOpenings = (): Opening[] => {
  return openings as Opening[];
};

export const getTasks = (): TaskDict => {
  const results: any = {};

  Object.entries(tasks).forEach(([githubUsername, taskList]) => {
    results[githubUsername] = (taskList as RawTask[]).map(
      (task: RawTask): Task => ({
        ...task,
        completed_date: parse(task.completed_date, 'L/d/yy', new Date()),
      }),
    );
  });

  return results;
};

export const getTeamMembers = (): TeamMember[] => {
  const members: any = {};
  teams.forEach((team) => {
    team.contributors.forEach((teamMember: any) => {
      const {title: userTitle, isLead, payPerDay, createdDate, contributor} = teamMember;
      const {contributorId, ...otherProps} = contributor;
      if (!members[contributorId]) {
        members[contributorId] = {
          contributorId,
          createdDate,
          isLead,
          payPerDay,
          teams: [{isLead, title: team.title}],
          titles: [userTitle],
          ...otherProps,
        };
      } else {
        const member = members[contributorId];
        const {teams: addedTeams, titles, isLead: isLeadForAddedTeams} = member;
        const teamNameExists =
          addedTeams.findIndex(({title}: {title: string}) => title.toLowerCase() === team.title.toLowerCase()) !== -1;
        const titleExists = titles.findIndex((title: string) => title.toLowerCase() === userTitle.toLowerCase()) !== -1;
        members[contributorId] = {
          ...member,
          isLead: isLeadForAddedTeams || isLead,
          teams: teamNameExists ? addedTeams : addedTeams.concat([{isLead, title: team.title}]),
          titles: titleExists ? titles : titles.concat([userTitle]),
        };
      }
    });