1- import { Manufacturer , MaterialType , Project , validateWBS , WbsNumber , wbsPipe } from 'shared' ;
1+ import { Manufacturer , MaterialType , Project , ProjectPreview , validateWBS , WbsNumber , wbsPipe } from 'shared' ;
22import { NextFunction , Request , Response } from 'express' ;
33import ProjectsService from '../services/projects.services' ;
44import BillOfMaterialsService from '../services/boms.services' ;
@@ -7,7 +7,25 @@ export default class ProjectsController {
77 static async getAllProjects ( req : Request , res : Response , next : NextFunction ) {
88 try {
99 const includeDeleted = req . params . deleted === 'true' ;
10- const projects : Project [ ] = await ProjectsService . getAllProjects ( req . organization , includeDeleted ) ;
10+ const projects : ProjectPreview [ ] = await ProjectsService . getAllProjects ( req . organization , includeDeleted ) ;
11+ res . status ( 200 ) . json ( projects ) ;
12+ } catch ( error : unknown ) {
13+ next ( error ) ;
14+ }
15+ }
16+
17+ static async getUsersTeamsProjects ( req : Request , res : Response , next : NextFunction ) {
18+ try {
19+ const projects : ProjectPreview [ ] = await ProjectsService . getUsersTeamsProjects ( req . currentUser , req . organization ) ;
20+ res . status ( 200 ) . json ( projects ) ;
21+ } catch ( error : unknown ) {
22+ next ( error ) ;
23+ }
24+ }
25+
26+ static async getUsersLeadingProjects ( req : Request , res : Response , next : NextFunction ) {
27+ try {
28+ const projects : ProjectPreview [ ] = await ProjectsService . getUsersLeadingProjects ( req . currentUser , req . organization ) ;
1129 res . status ( 200 ) . json ( projects ) ;
1230 } catch ( error : unknown ) {
1331 next ( error ) ;
@@ -109,27 +127,6 @@ export default class ProjectsController {
109127 }
110128 }
111129
112- static async setAbbreviation ( req : Request , res : Response , next : NextFunction ) {
113- try {
114- const { abbreviation } = req . body ;
115- const wbsNum : WbsNumber = validateWBS ( req . body . wbsNum ) ;
116- const updatedProject = await ProjectsService . setAbbreviation ( wbsNum , req . currentUser , req . organization , abbreviation ) ;
117- res . status ( 200 ) . json ( updatedProject ) ;
118- } catch ( error : unknown ) {
119- next ( error ) ;
120- }
121- }
122-
123- static async deleteAbbreviation ( req : Request , res : Response , next : NextFunction ) {
124- try {
125- const wbsNum : WbsNumber = validateWBS ( req . params . wbsNum ) ;
126- await ProjectsService . deleteAbbreviation ( wbsNum , req . currentUser , req . organization ) ;
127- res . status ( 200 ) . json ( { message : `Project ${ wbsPipe ( wbsNum ) } 's abbreviation was successfully deleted.` } ) ;
128- } catch ( error : unknown ) {
129- next ( error ) ;
130- }
131- }
132-
133130 static async getAllLinkTypes ( req : Request , res : Response , next : NextFunction ) {
134131 try {
135132 const linkTypes = await ProjectsService . getAllLinkTypes ( req . organization ) ;
@@ -421,4 +418,47 @@ export default class ProjectsController {
421418 next ( error ) ;
422419 }
423420 }
421+
422+ static async getAssembliesForWbsElement ( req : Request , res : Response , next : NextFunction ) {
423+ try {
424+ const wbsNumber : WbsNumber = validateWBS ( req . params . wbsNum ) ;
425+
426+ const assemblies = await BillOfMaterialsService . getAssembliesForWbsElement ( wbsNumber , req . organization ) ;
427+ res . status ( 200 ) . json ( assemblies ) ;
428+ } catch ( error : unknown ) {
429+ next ( error ) ;
430+ }
431+ }
432+
433+ static async getMaterialsForWbsElement ( req : Request , res : Response , next : NextFunction ) {
434+ try {
435+ const wbsNumber : WbsNumber = validateWBS ( req . params . wbsNum ) ;
436+
437+ const assemblies = await BillOfMaterialsService . getMaterialsForWbsElement ( wbsNumber , req . organization ) ;
438+ res . status ( 200 ) . json ( assemblies ) ;
439+ } catch ( error : unknown ) {
440+ next ( error ) ;
441+ }
442+ }
443+
444+ static async setAbbreviation ( req : Request , res : Response , next : NextFunction ) {
445+ try {
446+ const { abbreviation } = req . body ;
447+ const wbsNum : WbsNumber = validateWBS ( req . body . wbsNum ) ;
448+ const updatedProject = await ProjectsService . setAbbreviation ( wbsNum , req . currentUser , req . organization , abbreviation ) ;
449+ res . status ( 200 ) . json ( updatedProject ) ;
450+ } catch ( error : unknown ) {
451+ next ( error ) ;
452+ }
453+ }
454+
455+ static async deleteAbbreviation ( req : Request , res : Response , next : NextFunction ) {
456+ try {
457+ const wbsNum : WbsNumber = validateWBS ( req . params . wbsNum ) ;
458+ await ProjectsService . deleteAbbreviation ( wbsNum , req . currentUser , req . organization ) ;
459+ res . status ( 200 ) . json ( { message : `Project ${ wbsPipe ( wbsNum ) } 's abbreviation was successfully deleted.` } ) ;
460+ } catch ( error : unknown ) {
461+ next ( error ) ;
462+ }
463+ }
424464}
0 commit comments