@@ -7,12 +7,18 @@ import {
77 LinkCreateArgs ,
88 LinkType ,
99 Project ,
10+ ProjectOverview ,
11+ ProjectGantt ,
1012 ProjectPreview ,
1113 WbsNumber ,
1214 wbsPipe
1315} from 'shared' ;
1416import prisma from '../prisma/prisma' ;
15- import projectTransformer , { projectPreviewTransformer } from '../transformers/projects.transformer' ;
17+ import projectTransformer , {
18+ projectOverviewTransformer ,
19+ projectGanttTransformer ,
20+ projectPreviewTransformer
21+ } from '../transformers/projects.transformer' ;
1622import { validateChangeRequestAccepted } from '../utils/change-requests.utils' ;
1723import {
1824 AccessDeniedAdminOnlyException ,
@@ -28,33 +34,52 @@ import { wbsNumOf } from '../utils/utils';
2834import WorkPackagesService from './work-packages.services' ;
2935import { linkTypeTransformer } from '../transformers/links.transformer' ;
3036import { userHasPermission } from '../utils/users.utils' ;
31- import { getProjectManyQueryArgs , getProjectQueryArgs } from '../prisma-query-args/projects.query-args' ;
37+ import {
38+ getProjectGanttQueryArgs ,
39+ getProjectOverviewQueryArgs ,
40+ getProjectPreviewQueryArgs ,
41+ getProjectQueryArgs
42+ } from '../prisma-query-args/projects.query-args' ;
3243import { getLinkQueryArgs } from '../prisma-query-args/links.query-args' ;
3344import { getDescriptionBulletQueryArgs } from '../prisma-query-args/description-bullets.query-args' ;
3445import { getLinkTypeQueryArgs } from '../prisma-query-args/link-types.query-args' ;
3546
3647export default class ProjectsService {
3748 /**
38- * Get all the non deleted projects in the database for the given organization.
39- * @param organizationId the id of the organization the user is currently in
40- * @param includeDeleted whether or not to include deleted projects
41- * @returns all the projects
49+ * Get all the non deleted projects in the database for the given organization
50+ * @param organization the organization the user is currently in
51+ * @returns all the projects with query args for use in the gantt chart
4252 */
43- static async getAllProjects ( organization : Organization , includeDeleted : boolean ) : Promise < ProjectPreview [ ] > {
44- const projects = includeDeleted
45- ? await prisma . project . findMany ( {
46- where : { wbsElement : { organizationId : organization . organizationId } } ,
47- ...getProjectManyQueryArgs ( organization . organizationId )
48- } )
49- : await prisma . project . findMany ( {
50- where : { wbsElement : { dateDeleted : null , organizationId : organization . organizationId } } ,
51- ...getProjectManyQueryArgs ( organization . organizationId )
52- } ) ;
53+ static async getAllProjectsGantt ( organization : Organization ) : Promise < ProjectGantt [ ] > {
54+ const projects = await prisma . project . findMany ( {
55+ where : { wbsElement : { dateDeleted : null , organizationId : organization . organizationId } } ,
56+ ...getProjectGanttQueryArgs ( organization . organizationId )
57+ } ) ;
58+
59+ return projects . map ( projectGanttTransformer ) ;
60+ }
61+
62+ /**
63+ * Get all projects for given organization
64+ * @param organization the organization the user is in
65+ * @returns all the projects with preview query args
66+ */
67+ static async getAllProjects ( organization : Organization ) : Promise < ProjectPreview [ ] > {
68+ const projects = await prisma . project . findMany ( {
69+ where : { wbsElement : { dateDeleted : null , organizationId : organization . organizationId } } ,
70+ ...getProjectPreviewQueryArgs ( organization . organizationId )
71+ } ) ;
5372
5473 return projects . map ( projectPreviewTransformer ) ;
5574 }
5675
57- static async getUsersLeadingProjects ( user : User , organization : Organization ) : Promise < ProjectPreview [ ] > {
76+ /**
77+ * Get all projects that the user is the lead or manager of
78+ * @param user the user making the request
79+ * @param organization the oranization the user is in
80+ * @returns the projects the user is a lead or manager of with preview query args
81+ */
82+ static async getUsersLeadingProjects ( user : User , organization : Organization ) : Promise < ProjectOverview [ ] > {
5883 const projects = await prisma . project . findMany ( {
5984 where : {
6085 wbsElement : {
@@ -63,13 +88,19 @@ export default class ProjectsService {
6388 OR : [ { leadId : user . userId } , { managerId : user . userId } ]
6489 }
6590 } ,
66- ...getProjectManyQueryArgs ( organization . organizationId )
91+ ...getProjectOverviewQueryArgs ( organization . organizationId )
6792 } ) ;
6893
69- return projects . map ( projectPreviewTransformer ) ;
94+ return projects . map ( projectOverviewTransformer ) ;
7095 }
7196
72- static async getUsersTeamsProjects ( user : User , organization : Organization ) : Promise < ProjectPreview [ ] > {
97+ /**
98+ * Get all projects related to teams the user is on
99+ * @param user the user making the request
100+ * @param organization the organization the user is in
101+ * @returns all projects associated with teams the user is on with overview card query args
102+ */
103+ static async getUsersTeamsProjects ( user : User , organization : Organization ) : Promise < ProjectOverview [ ] > {
73104 const projects = await prisma . project . findMany ( {
74105 where : {
75106 wbsElement : {
@@ -100,12 +131,18 @@ export default class ProjectsService {
100131 }
101132 }
102133 } ,
103- ...getProjectManyQueryArgs ( organization . organizationId )
134+ ...getProjectOverviewQueryArgs ( organization . organizationId )
104135 } ) ;
105136
106- return projects . map ( projectPreviewTransformer ) ;
137+ return projects . map ( projectOverviewTransformer ) ;
107138 }
108139
140+ /**
141+ * Get the projects for a given team
142+ * @param organization
143+ * @param teamId
144+ * @returns all the projects for the given team with full project query args
145+ */
109146 static async getTeamsProjects ( organization : Organization , teamId : string ) : Promise < Project [ ] > {
110147 const projects = await prisma . project . findMany ( {
111148 where : {
0 commit comments