Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/backend/src/controllers/projects.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import BillOfMaterialsService from '../services/boms.services.js';
export default class ProjectsController {
static async getAllProjectsGantt(req: Request, res: Response, next: NextFunction) {
try {
const projects: ProjectGantt[] = await ProjectsService.getAllProjectsGantt(req.organization);
const { carId } = req.query;
const projects: ProjectGantt[] = await ProjectsService.getAllProjectsGantt(
req.organization,
carId as string | undefined
);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
Expand All @@ -25,7 +29,8 @@ export default class ProjectsController {

static async getAllProjects(req: Request, res: Response, next: NextFunction) {
try {
const projects: ProjectPreview[] = await ProjectsService.getAllProjects(req.organization);
const { carId } = req.query;
const projects: ProjectPreview[] = await ProjectsService.getAllProjects(req.organization, carId as string | undefined);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
Expand All @@ -34,7 +39,12 @@ export default class ProjectsController {

static async getUsersTeamsProjects(req: Request, res: Response, next: NextFunction) {
try {
const projects: ProjectOverview[] = await ProjectsService.getUsersTeamsProjects(req.currentUser, req.organization);
const { carId } = req.query;
const projects: ProjectOverview[] = await ProjectsService.getUsersTeamsProjects(
req.currentUser,
req.organization,
carId as string | undefined
);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
Expand All @@ -43,7 +53,12 @@ export default class ProjectsController {

static async getUsersLeadingProjects(req: Request, res: Response, next: NextFunction) {
try {
const projects: ProjectOverview[] = await ProjectsService.getUsersLeadingProjects(req.currentUser, req.organization);
const { carId } = req.query;
const projects: ProjectOverview[] = await ProjectsService.getUsersLeadingProjects(
req.currentUser,
req.organization,
carId as string | undefined
);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
Expand All @@ -53,7 +68,12 @@ export default class ProjectsController {
static async getTeamsProjects(req: Request, res: Response, next: NextFunction) {
try {
const { teamId } = req.params as Record<string, string>;
const projects: Project[] = await ProjectsService.getTeamsProjects(req.organization, teamId);
const { carId } = req.query;
const projects: Project[] = await ProjectsService.getTeamsProjects(
req.organization,
teamId,
carId as string | undefined
);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
Expand Down
28 changes: 18 additions & 10 deletions src/backend/src/services/projects.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ export default class ProjectsService {
/**
* Get all the non deleted projects in the database for the given organization
* @param organization the organization the user is currently in
* @param carId optional car id to filter projects by
* @returns all the projects with query args for use in the gantt chart
*/
static async getAllProjectsGantt(organization: Organization): Promise<ProjectGantt[]> {
static async getAllProjectsGantt(organization: Organization, carId?: string): Promise<ProjectGantt[]> {
const projects = await prisma.project.findMany({
where: { wbsElement: { dateDeleted: null, organizationId: organization.organizationId } },
where: { wbsElement: { dateDeleted: null, organizationId: organization.organizationId }, ...(carId && { carId }) },
...getProjectGanttQueryArgs(organization.organizationId)
});

Expand All @@ -61,11 +62,12 @@ export default class ProjectsService {
/**
* Get all projects for given organization
* @param organization the organization the user is in
* @param carId optional car id to filter projects by
* @returns all the projects with preview query args
*/
static async getAllProjects(organization: Organization): Promise<ProjectPreview[]> {
static async getAllProjects(organization: Organization, carId?: string): Promise<ProjectPreview[]> {
const projects = await prisma.project.findMany({
where: { wbsElement: { dateDeleted: null, organizationId: organization.organizationId } },
where: { wbsElement: { dateDeleted: null, organizationId: organization.organizationId }, ...(carId && { carId }) },
...getProjectPreviewQueryArgs(organization.organizationId)
});

Expand All @@ -76,16 +78,18 @@ export default class ProjectsService {
* Get all projects that the user is the lead or manager of
* @param user the user making the request
* @param organization the oranization the user is in
* @param carId optional car id to filter projects by
* @returns the projects the user is a lead or manager of with preview query args
*/
static async getUsersLeadingProjects(user: User, organization: Organization): Promise<ProjectOverview[]> {
static async getUsersLeadingProjects(user: User, organization: Organization, carId?: string): Promise<ProjectOverview[]> {
const projects = await prisma.project.findMany({
where: {
wbsElement: {
organizationId: organization.organizationId,
dateDeleted: null,
OR: [{ leadId: user.userId }, { managerId: user.userId }]
}
},
...(carId && { carId })
},
...getProjectOverviewQueryArgs(organization.organizationId)
});
Expand All @@ -97,9 +101,10 @@ export default class ProjectsService {
* Get all projects related to teams the user is on
* @param user the user making the request
* @param organization the organization the user is in
* @param carId optional car id to filter projects by
* @returns all projects associated with teams the user is on with overview card query args
*/
static async getUsersTeamsProjects(user: User, organization: Organization): Promise<ProjectOverview[]> {
static async getUsersTeamsProjects(user: User, organization: Organization, carId?: string): Promise<ProjectOverview[]> {
const projects = await prisma.project.findMany({
where: {
wbsElement: {
Expand Down Expand Up @@ -128,7 +133,8 @@ export default class ProjectsService {
}
]
}
}
},
...(carId && { carId })
},
...getProjectOverviewQueryArgs(organization.organizationId)
});
Expand All @@ -140,9 +146,10 @@ export default class ProjectsService {
* Get the projects for a given team
* @param organization
* @param teamId
* @param carId optional car id to filter projects by
* @returns all the projects for the given team with full project query args
*/
static async getTeamsProjects(organization: Organization, teamId: string): Promise<Project[]> {
static async getTeamsProjects(organization: Organization, teamId: string, carId?: string): Promise<Project[]> {
const projects = await prisma.project.findMany({
where: {
wbsElement: {
Expand All @@ -153,7 +160,8 @@ export default class ProjectsService {
some: {
teamId
}
}
},
...(carId && { carId })
},
...getProjectQueryArgs(organization.organizationId)
});
Expand Down
12 changes: 8 additions & 4 deletions src/frontend/src/apis/projects.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,39 @@ import { CreateSingleProjectPayload, EditSingleProjectPayload } from '../utils/t
/**
* Fetches all projects with querry args needed for Gantt chart
*/
export const getAllProjectsGantt = () => {
export const getAllProjectsGantt = (carId?: string) => {
return axios.get<ProjectGantt[]>(apiUrls.allProjectsGantt(), {
params: { carId },
transformResponse: (data) => JSON.parse(data).map(projectGanttTransformer)
});
};

/**
* Fetches all projects with preview querry args
*/
export const getAllProjects = () => {
export const getAllProjects = (carId?: string) => {
return axios.get<ProjectPreview[]>(apiUrls.allProjectPreviews(), {
params: { carId },
transformResponse: (data) => JSON.parse(data).map(projectPreviewTransformer)
});
};

/**
* Fetches all the projects that are on the users teams
*/
export const getUsersTeamsProjects = () => {
export const getUsersTeamsProjects = (carId?: string) => {
return axios.get<ProjectOverview[]>(apiUrls.usersTeamsProjects(), {
params: { carId },
transformResponse: (data) => JSON.parse(data).map(projectOverviewTransformer)
});
};

/**
* Fetches all projects that the user is the manager or lead of.
*/
export const getUsersLeadingProjects = () => {
export const getUsersLeadingProjects = (carId?: string) => {
return axios.get<ProjectOverview[]>(apiUrls.usersLeadingProjects(), {
params: { carId },
transformResponse: (data) => JSON.parse(data).map(projectOverviewTransformer)
});
};
Expand Down