Skip to content

Commit

Permalink
Merge pull request #3168 from Northeastern-Electric-Racing/Optimize-P…
Browse files Browse the repository at this point in the history
…rojects

Optimize Projects
  • Loading branch information
Peyton-McKee authored Jan 24, 2025
2 parents 7f01c90 + 2dac67d commit 9dee77d
Show file tree
Hide file tree
Showing 86 changed files with 1,247 additions and 1,717 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.17.1
node-version: 20.18.1
cache: 'yarn'
- name: Install modules
run: yarn install && yarn prisma:generate
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prettier-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.17.1
node-version: 20.18.1
cache: 'yarn'
- name: Install modules
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/production-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.17.1
node-version: 20.18.1
cache: 'yarn'
- name: Yarn Install
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.17.1
node-version: 20.18.1
cache: 'yarn'
- name: Add Env Variables
run: cd src/backend && echo "DATABASE_URL=\"postgresql://postgres:docker@localhost:5432/nerpm?schema=public\"" >> .env
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.17.1
node-version: 20.18.1
cache: 'yarn'
- name: Yarn Install
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tsc-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20.18.1

- name: Install dependencies
run: yarn install && yarn prisma:generate
Expand Down
9 changes: 4 additions & 5 deletions src/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"prisma:manual": "ts-node ./src/prisma/manual.ts"
},
"dependencies": {
"@prisma/client": "^5.7.1",
"@prisma/client": "^6.2.1",
"@slack/events-api": "^3.0.1",
"@slack/web-api": "^6.7.2",
"@slack/web-api": "^7.8.0",
"@types/concat-stream": "^2.0.0",
"@types/cookie-parser": "^1.4.3",
"@types/cors": "^2.8.12",
Expand Down Expand Up @@ -40,12 +40,11 @@
"@types/node": "^20.0.0",
"@types/supertest": "^2.0.12",
"nodemon": "^2.0.16",
"prisma": "^5.7.1",
"prisma": "^6.2.1",
"supertest": "^6.2.4",
"ts-jest": "^26.2.0",
"ts-node": "^8.10.1",
"typescript": "^5.7.3",
"vitest": "^2.1.8"
"vitest": "^3.0.0"
},
"main": "index.ts",
"prisma": {
Expand Down
44 changes: 42 additions & 2 deletions src/backend/src/controllers/projects.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Manufacturer, MaterialType, Project, validateWBS, WbsNumber, wbsPipe } from 'shared';
import { Manufacturer, MaterialType, Project, ProjectPreview, validateWBS, WbsNumber, wbsPipe } from 'shared';
import { NextFunction, Request, Response } from 'express';
import ProjectsService from '../services/projects.services';
import BillOfMaterialsService from '../services/boms.services';
Expand All @@ -7,7 +7,25 @@ export default class ProjectsController {
static async getAllProjects(req: Request, res: Response, next: NextFunction) {
try {
const includeDeleted = req.params.deleted === 'true';
const projects: Project[] = await ProjectsService.getAllProjects(req.organization, includeDeleted);
const projects: ProjectPreview[] = await ProjectsService.getAllProjects(req.organization, includeDeleted);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
}
}

static async getUsersTeamsProjects(req: Request, res: Response, next: NextFunction) {
try {
const projects: ProjectPreview[] = await ProjectsService.getUsersTeamsProjects(req.currentUser, req.organization);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
}
}

static async getUsersLeadingProjects(req: Request, res: Response, next: NextFunction) {
try {
const projects: ProjectPreview[] = await ProjectsService.getUsersLeadingProjects(req.currentUser, req.organization);
res.status(200).json(projects);
} catch (error: unknown) {
next(error);
Expand Down Expand Up @@ -400,4 +418,26 @@ export default class ProjectsController {
next(error);
}
}

static async getAssembliesForWbsElement(req: Request, res: Response, next: NextFunction) {
try {
const wbsNumber: WbsNumber = validateWBS(req.params.wbsNum);

const assemblies = await BillOfMaterialsService.getAssembliesForWbsElement(wbsNumber, req.organization);
res.status(200).json(assemblies);
} catch (error: unknown) {
next(error);
}
}

static async getMaterialsForWbsElement(req: Request, res: Response, next: NextFunction) {
try {
const wbsNumber: WbsNumber = validateWBS(req.params.wbsNum);

const assemblies = await BillOfMaterialsService.getMaterialsForWbsElement(wbsNumber, req.organization);
res.status(200).json(assemblies);
} catch (error: unknown) {
next(error);
}
}
}
5 changes: 1 addition & 4 deletions src/backend/src/prisma-query-args/cars.query-args.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Prisma } from '@prisma/client';
import { getAssemblyQueryArgs, getMaterialQueryArgs } from './bom.query-args';
import { getDescriptionBulletQueryArgs } from './description-bullets.query-args';
import { getLinkQueryArgs } from './links.query-args';
import { getUserQueryArgs } from './user.query-args';
Expand All @@ -18,9 +17,7 @@ export const getCarQueryArgs = (organizationId: string) =>
changes: {
where: { changeRequest: { dateDeleted: null } },
include: { implementer: getUserQueryArgs(organizationId) }
},
materials: getMaterialQueryArgs(organizationId),
assemblies: getAssemblyQueryArgs(organizationId)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { getUserQueryArgs, getUserWithSettingsQueryArgs } from './user.query-arg

export type DesignReviewQueryArgs = ReturnType<typeof getDesignReviewQueryArgs>;

export type DesignReviewPreviewQueryArgs = ReturnType<typeof getDesignReviewPreviewQueryArgs>;

export const getDesignReviewQueryArgs = (organizationId: string) =>
Prisma.validator<Prisma.Design_ReviewDefaultArgs>()({
include: {
Expand All @@ -18,3 +20,10 @@ export const getDesignReviewQueryArgs = (organizationId: string) =>
notificationSlackThreads: true
}
});

export const getDesignReviewPreviewQueryArgs = (organizationId: string) =>
Prisma.validator<Prisma.Design_ReviewDefaultArgs>()({
include: {
userCreated: getUserWithSettingsQueryArgs(organizationId)
}
});
71 changes: 37 additions & 34 deletions src/backend/src/prisma-query-args/projects.query-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Prisma } from '@prisma/client';
import { getLinkQueryArgs } from './links.query-args';
import { getUserQueryArgs } from './user.query-args';
import { getDescriptionBulletQueryArgs } from './description-bullets.query-args';
import { getTeamQueryArgs } from './teams.query-args';
import { getMaterialQueryArgs, getAssemblyQueryArgs } from './bom.query-args';
import { getTeamPreviewQueryArgs } from './teams.query-args';
import { getTaskQueryArgs } from './tasks.query-args';
import { getDesignReviewQueryArgs } from './design-reviews.query-args';
import { getWorkPackageQueryArgs } from './work-packages.query-args';

export type ProjectQueryArgs = ReturnType<typeof getProjectQueryArgs>;

export type ProjectManyQueryArgs = ReturnType<typeof getProjectManyQueryArgs>;

export const getProjectQueryArgs = (organizationId: string) =>
Prisma.validator<Prisma.ProjectDefaultArgs>()({
include: {
Expand All @@ -23,50 +24,52 @@ export const getProjectQueryArgs = (organizationId: string) =>
where: { changeRequest: { dateDeleted: null } },
include: { implementer: getUserQueryArgs(organizationId) }
},
materials: {
where: { dateDeleted: null },
...getMaterialQueryArgs(organizationId)
},
assemblies: {
where: { dateDeleted: null },
...getAssemblyQueryArgs(organizationId)
},
organization: true
}
},
teams: getTeamQueryArgs(organizationId),
teams: getTeamPreviewQueryArgs(organizationId),
workPackages: {
where: {
wbsElement: {
dateDeleted: null
}
},
...getWorkPackageQueryArgs(organizationId)
},
favoritedBy: getUserQueryArgs(organizationId)
}
});

export const getProjectManyQueryArgs = (organizationId: string) =>
Prisma.validator<Prisma.ProjectDefaultArgs>()({
include: {
wbsElement: {
include: {
wbsElement: {
include: {
lead: getUserQueryArgs(organizationId),
descriptionBullets: { where: { dateDeleted: null }, ...getDescriptionBulletQueryArgs(organizationId) },
manager: getUserQueryArgs(organizationId),
links: { where: { dateDeleted: null }, ...getLinkQueryArgs(organizationId) },
changes: {
where: { changeRequest: { dateDeleted: null } },
include: { implementer: getUserQueryArgs(organizationId) }
},
materials: {
where: { dateDeleted: null },
...getMaterialQueryArgs(organizationId)
},
assemblies: {
where: { dateDeleted: null },
...getAssemblyQueryArgs(organizationId)
},
blocking: { where: { wbsElement: { dateDeleted: null } }, include: { wbsElement: true } },
designReviews: { where: { dateDeleted: null }, ...getDesignReviewQueryArgs(organizationId) }
}
lead: getUserQueryArgs(organizationId),
manager: getUserQueryArgs(organizationId),
tasks: {
where: {
dateDeleted: null
},
...getTaskQueryArgs(organizationId)
},
blockedBy: { where: { dateDeleted: null } }
links: {
where: {
dateDeleted: null
},
...getLinkQueryArgs(organizationId)
}
}
},
teams: getTeamPreviewQueryArgs(organizationId),
workPackages: {
where: {
wbsElement: {
dateDeleted: null
}
},
...getWorkPackageQueryArgs(organizationId)
},
favoritedBy: getUserQueryArgs(organizationId)
}
});
18 changes: 13 additions & 5 deletions src/backend/src/prisma-query-args/teams.query-args.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Prisma } from '@prisma/client';
import { getUserQueryArgs } from './user.query-args';
import { getWorkPackageQueryArgs } from './work-packages.query-args';
import { getProjectManyQueryArgs } from './projects.query-args';

export type TeamQueryArgs = ReturnType<typeof getTeamQueryArgs>;

export type TeamPreviewQueryArgs = ReturnType<typeof getTeamPreviewQueryArgs>;

export const getTeamQueryArgs = (organizationId: string) =>
Prisma.validator<Prisma.TeamDefaultArgs>()({
include: {
Expand All @@ -18,10 +20,16 @@ export const getTeamQueryArgs = (organizationId: string) =>
dateDeleted: null
}
},
include: {
wbsElement: true,
workPackages: getWorkPackageQueryArgs(organizationId)
}
...getProjectManyQueryArgs(organizationId)
}
}
});

export const getTeamPreviewQueryArgs = (organizationId: string) =>
Prisma.validator<Prisma.TeamDefaultArgs>()({
include: {
members: getUserQueryArgs(organizationId),
head: getUserQueryArgs(organizationId),
leads: getUserQueryArgs(organizationId)
}
});
6 changes: 2 additions & 4 deletions src/backend/src/prisma-query-args/work-packages.query-args.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Prisma } from '@prisma/client';
import { getUserQueryArgs } from './user.query-args';
import { getTaskQueryArgs } from './tasks.query-args';
import { getDescriptionBulletQueryArgs } from './description-bullets.query-args';
import { getDesignReviewQueryArgs } from './design-reviews.query-args';
import { getDesignReviewPreviewQueryArgs } from './design-reviews.query-args';

export type WorkPackageQueryArgs = ReturnType<typeof getWorkPackageQueryArgs>;

Expand All @@ -29,9 +28,8 @@ export const getWorkPackageQueryArgs = (organizationId: string) =>
orderBy: { dateImplemented: 'asc' }
},
blocking: { where: { wbsElement: { dateDeleted: null } }, include: { wbsElement: true } },
tasks: { where: { dateDeleted: null }, ...getTaskQueryArgs(organizationId) },
descriptionBullets: { where: { dateDeleted: null }, ...getDescriptionBulletQueryArgs(organizationId) },
designReviews: { where: { dateDeleted: null }, ...getDesignReviewQueryArgs(organizationId) }
designReviews: { where: { dateDeleted: null }, ...getDesignReviewPreviewQueryArgs(organizationId) }
}
},
blockedBy: { where: { dateDeleted: null } }
Expand Down
Loading

0 comments on commit 9dee77d

Please sign in to comment.