Skip to content

Commit ca0c84a

Browse files
committed
docs and rename getallprojectpreviews
1 parent 5f13ce6 commit ca0c84a

12 files changed

Lines changed: 40 additions & 35 deletions

File tree

src/backend/src/controllers/projects.controllers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export default class ProjectsController {
2323
}
2424
}
2525

26-
static async getAllProjectPreviews(req: Request, res: Response, next: NextFunction) {
26+
static async getAllProjects(req: Request, res: Response, next: NextFunction) {
2727
try {
28-
const projects: ProjectPreview[] = await ProjectsService.getAllProjectPreviews(req.organization);
28+
const projects: ProjectPreview[] = await ProjectsService.getAllProjects(req.organization);
2929
res.status(200).json(projects);
3030
} catch (error: unknown) {
3131
next(error);

src/backend/src/routes/projects.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ProjectsController from '../controllers/projects.controllers';
1212
const projectRouter = express.Router();
1313

1414
projectRouter.get('/all-gantt', ProjectsController.getAllProjectsGantt);
15-
projectRouter.get('/all-previews', ProjectsController.getAllProjectPreviews);
15+
projectRouter.get('/all-previews', ProjectsController.getAllProjects);
1616
projectRouter.get('/users-teams', ProjectsController.getUsersTeamsProjects);
1717
projectRouter.get('/leading', ProjectsController.getUsersLeadingProjects);
1818
projectRouter.get('/teams-projects/:teamId', ProjectsController.getTeamsProjects);

src/backend/src/services/projects.services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class ProjectsService {
6464
* @param organization the organization the user is in
6565
* @returns all the projects with preview query args
6666
*/
67-
static async getAllProjectPreviews(organization: Organization): Promise<ProjectPreview[]> {
67+
static async getAllProjects(organization: Organization): Promise<ProjectPreview[]> {
6868
const projects = await prisma.project.findMany({
6969
where: { wbsElement: { dateDeleted: null, organizationId: organization.organizationId } },
7070
...getProjectPreviewQueryArgs(organization.organizationId)
@@ -141,7 +141,7 @@ export default class ProjectsService {
141141
* Get the projects for a given team
142142
* @param organization
143143
* @param teamId
144-
* @returns
144+
* @returns all the projects for the given team with full project query args
145145
*/
146146
static async getTeamsProjects(organization: Organization, teamId: string): Promise<Project[]> {
147147
const projects = await prisma.project.findMany({

src/frontend/src/apis/projects.api.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ import {
2828
import { CreateSingleProjectPayload, EditSingleProjectPayload } from '../utils/types';
2929

3030
/**
31-
* Fetches all projects.
31+
* Fetches all projects with querry args needed for Gantt chart
3232
*/
3333
export const getAllProjectsGantt = () => {
3434
return axios.get<ProjectGantt[]>(apiUrls.allProjectsGantt(), {
3535
transformResponse: (data) => JSON.parse(data).map(projectGanttTransformer)
3636
});
3737
};
3838

39-
export const getAllProjectPreviews = () => {
39+
/**
40+
* Fetches all projects with preview querry args
41+
*/
42+
export const getAllProjects = () => {
4043
return axios.get<ProjectPreview[]>(apiUrls.allProjectPreviews(), {
4144
transformResponse: (data) => JSON.parse(data).map(projectPreviewTransformer)
4245
});

src/frontend/src/hooks/projects.hooks.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ import {
3535
setAbbreviation,
3636
deleteAbbreviation,
3737
getTeamsProjects,
38-
getAllProjectPreviews
38+
getAllProjects
3939
} from '../apis/projects.api';
4040
import { CreateSingleProjectPayload, EditSingleProjectPayload } from '../utils/types';
4141
import { useCurrentUser } from './users.hooks';
4242

4343
/**
44-
* Custom React Hook to supply all projects.
44+
* Custom React Hook to supply all projects with Gantt querry args
4545
*/
4646
export const useAllProjectsGantt = () => {
4747
return useQuery<ProjectGantt[], Error>(['projects'], async () => {
@@ -50,27 +50,39 @@ export const useAllProjectsGantt = () => {
5050
});
5151
};
5252

53-
export const useAllProjectsPreviews = () => {
53+
/**
54+
* Custom React Hook to supply all projects
55+
*/
56+
export const useAllProjects = () => {
5457
return useQuery<ProjectPreview[], Error>(['projects', 'previews'], async () => {
55-
const { data } = await getAllProjectPreviews();
58+
const { data } = await getAllProjects();
5659
return data;
5760
});
5861
};
5962

63+
/**
64+
* Custom React Hook to supply all of the projects that are on the users teams
65+
*/
6066
export const useGetUsersTeamsProjects = () => {
6167
return useQuery<ProjectOverview[], Error>(['projects', 'teams'], async () => {
6268
const { data } = await getUsersTeamsProjects();
6369
return data;
6470
});
6571
};
6672

73+
/**
74+
* Custom React Hook to supply all of the projects that the user is the manager or lead of
75+
*/
6776
export const useGetUsersLeadingProjects = () => {
6877
return useQuery<ProjectOverview[], Error>(['projects', 'leading'], async () => {
6978
const { data } = await getUsersLeadingProjects();
7079
return data;
7180
});
7281
};
7382

83+
/**
84+
* Custom React Hook to supply all of the projects for a given team
85+
*/
7486
export const useGetTeamsProjects = (teamId: string) => {
7587
return useQuery<Project[], Error>(['projects', 'teams'], async () => {
7688
const { data } = await getTeamsProjects(teamId);

src/frontend/src/pages/AdminToolsPage/EditGuestView/EditFeaturedProjectsDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Autocomplete, Chip, TextField } from '@mui/material';
33
import { ProjectPreview } from 'shared';
44
import { projectWbsNamePipe } from '../../../utils/pipes';
5-
import { useAllProjectsPreviews } from '../../../hooks/projects.hooks';
5+
import { useAllProjects } from '../../../hooks/projects.hooks';
66
import LoadingIndicator from '../../../components/LoadingIndicator';
77
import ErrorPage from '../../ErrorPage';
88

@@ -12,7 +12,7 @@ interface EditFeatureProjectsDropdownProps {
1212
}
1313

1414
const EditFeaturedProjectsDropdown: React.FC<EditFeatureProjectsDropdownProps> = ({ onChange, value }) => {
15-
const { data: allProjects, isLoading, isError, error } = useAllProjectsPreviews();
15+
const { data: allProjects, isLoading, isError, error } = useAllProjects();
1616

1717
if (isLoading || !allProjects) return <LoadingIndicator />;
1818
if (isError) return <ErrorPage message={error.message} />;

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/AbbreviationsTable.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Box, IconButton, TableCell, TableRow, Typography } from '@mui/material';
22
import AdminToolTable from '../AdminToolTable';
33
import { NERButton } from '../../../components/NERButton';
4-
import { useAllProjectsPreviews, useDeleteProjectAbbreviation } from '../../../hooks/projects.hooks';
4+
import { useAllProjects, useDeleteProjectAbbreviation } from '../../../hooks/projects.hooks';
55
import LoadingIndicator from '../../../components/LoadingIndicator';
66
import ErrorPage from '../../ErrorPage';
77
import SetAbbreviationModal from './SetAbbreviationModal';
@@ -11,12 +11,7 @@ import { Delete } from '@mui/icons-material';
1111
import NERModal from '../../../components/NERModal';
1212

1313
const AbbreviationsTable: React.FC = () => {
14-
const {
15-
data: projects,
16-
isLoading: projectsIsLoading,
17-
isError: projectsIsError,
18-
error: projectsError
19-
} = useAllProjectsPreviews();
14+
const { data: projects, isLoading: projectsIsLoading, isError: projectsIsError, error: projectsError } = useAllProjects();
2015
const { mutateAsync } = useDeleteProjectAbbreviation();
2116
const [openModal, setOpenModal] = useState(false);
2217
const [abbreviationToDelete, setAbbreviationToDelete] = useState<ProjectPreview>();

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/SetAbbreviationModal.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ReactHookTextField from '../../../components/ReactHookTextField';
55
import * as yup from 'yup';
66
import { yupResolver } from '@hookform/resolvers/yup';
77
import { wbsPipe } from 'shared';
8-
import { useAllProjectsPreviews, useSetProjectAbbreviation } from '../../../hooks/projects.hooks';
8+
import { useAllProjects, useSetProjectAbbreviation } from '../../../hooks/projects.hooks';
99
import LoadingIndicator from '../../../components/LoadingIndicator';
1010
import ErrorPage from '../../ErrorPage';
1111

@@ -20,12 +20,7 @@ interface SetAbbreviation {
2020
}
2121

2222
const SetAbbreviationModal: React.FC<SetAbbreviation> = ({ open, handleClose }) => {
23-
const {
24-
data: projects,
25-
isLoading: projectsIsLoading,
26-
isError: projectsIsError,
27-
error: projectsError
28-
} = useAllProjectsPreviews();
23+
const { data: projects, isLoading: projectsIsLoading, isError: projectsIsError, error: projectsError } = useAllProjects();
2924
const { mutateAsync } = useSetProjectAbbreviation();
3025

3126
const onFormSubmit = async (data: { wbsNum: string; abbreviation: string }) => {

src/frontend/src/pages/CreateChangeRequestPage/CreateChangeRequestView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
Select
3333
} from '@mui/material';
3434
import NERAutocomplete from '../../components/NERAutocomplete';
35-
import { useAllProjectsPreviews } from '../../hooks/projects.hooks';
35+
import { useAllProjects } from '../../hooks/projects.hooks';
3636
import ErrorPage from '../ErrorPage';
3737
import LoadingIndicator from '../../components/LoadingIndicator';
3838
import NERFailButton from '../../components/NERFailButton';
@@ -91,7 +91,7 @@ const CreateChangeRequestsView: React.FC<CreateChangeRequestViewProps> = ({
9191

9292
const { fields: whys, append: appendWhy, remove: removeWhy } = useFieldArray({ control, name: 'why' });
9393

94-
const { isLoading, isError, error, data: projects } = useAllProjectsPreviews();
94+
const { isLoading, isError, error, data: projects } = useAllProjects();
9595

9696
const permittedTypes = Object.values(ChangeRequestType).filter(
9797
(t) => t !== ChangeRequestType.Activation && t !== ChangeRequestType.StageGate && t !== ChangeRequestType.Budget

src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementRequestForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import CreateReimbursementRequestFormView from './ReimbursementFormView';
2121
import { useHistory, useLocation } from 'react-router-dom';
2222
import { routes } from '../../../utils/routes';
2323
import { useCurrentUserSecureSettings } from '../../../hooks/users.hooks';
24-
import { useAllProjectsPreviews } from '../../../hooks/projects.hooks';
24+
import { useAllProjects } from '../../../hooks/projects.hooks';
2525

2626
export interface ReimbursementRequestInformation {
2727
vendorId: string;
@@ -190,7 +190,7 @@ const ReimbursementRequestForm: React.FC<ReimbursementRequestFormProps> = ({
190190
isError: allProjectsIsError,
191191
error: allProjectsError,
192192
data: allProjects
193-
} = useAllProjectsPreviews();
193+
} = useAllProjects();
194194

195195
// checking the data here instead of using isError since function doesn't ever return an error
196196
const { data: userSecureSettings, isLoading: checkSecureSettingsIsLoading } = useCurrentUserSecureSettings();

0 commit comments

Comments
 (0)