Skip to content

Commit

Permalink
Merge branch 'feature/homepage-redesign' of https://github.com/Northe…
Browse files Browse the repository at this point in the history
…astern-Electric-Racing/FinishLine into feature/homepage-redesign
  • Loading branch information
caiodasilva2005 committed Sep 11, 2024
2 parents 6489aaa + 592ea34 commit 00d98b8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/backend/src/utils/teams.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Prisma, User, Team } from '@prisma/client';
import { Prisma, User, Team, Project } from '@prisma/client';
import prisma from '../prisma/prisma';
import { UserWithSettings } from './auth.utils';
import { NotFoundException } from './errors.utils';

const teamQueryArgsMembersOnly = Prisma.validator<Prisma.TeamArgs>()({
include: {
Expand Down Expand Up @@ -88,3 +90,23 @@ export const removeUsersFromList = (currentUsers: UserWithId[], usersToRemove: U
const userIdsToRemove = usersToRemove.map((user) => user.userId);
return currentUsers.filter((user) => !userIdsToRemove.includes(user.userId));
};

/**
* Given a team id, produces all of the projects assigned to that team
* @param teamId the id of the team
* @returns array of projects currently assigned to the given team (errors if no team is found)
*/
export const getTeamProjects = async (teamId: string): Promise<Project[]> => {
const team = await prisma.team.findUnique({
where: {
teamId
},
include: {
projects: true
}
});
if (!team) {
throw new NotFoundException('Team', teamId);
}
return team.projects;
};

0 comments on commit 00d98b8

Please sign in to comment.