1- import { Authorized , Delete , JsonController , NotFoundError } from "routing-controllers" ;
1+ import { Authorized , Delete , JsonController , NotFoundError , Put , Param , Body , CurrentUser } from "routing-controllers" ;
22import { Inject } from "typedi" ;
33import { UserRole } from "../entities/user-role" ;
44import { IProjectService , ProjectServiceToken } from "../services/project-service" ;
5+ import { ProjectDTO , convertBetweenEntityAndDTO } from "./dto" ;
6+ import { Project } from "../entities/project" ;
7+ import { User } from "../entities/user" ;
58
69// TODO for every team, add a new project automatically with the correct teamId
710
@@ -19,13 +22,17 @@ export class ProjectController {
1922 public async updateProject (
2023 @Param ( "id" ) projectId : number ,
2124 @Body ( ) { data : projectDTO } : { data : ProjectDTO } ,
22- ) : Promise < TeamDTO > {
25+ @CurrentUser ( ) user : User ,
26+ ) : Promise < ProjectDTO > {
2327 // TODO ProjectUpdateDTO?
24- const project = convertBetweenEntityAndDTO ( projectDTO , Project ) ;
28+ const existing = await this . _projects . getProjectByID ( projectId ) ;
2529
26- // TODO how to make actual not found errors for incorrect ids?
30+ if ( existing == null ) {
31+ throw new NotFoundError ( ) ;
32+ }
2733
28- const updateProject = await this . _ratings . updateProject ( project , user ) ;
29- return convertBetweenEntityAndDTO ( updateProject , ProjectDTO ) ;
34+ const project = convertBetweenEntityAndDTO ( projectDTO , Project ) ;
35+ const updatedProject = await this . _projects . updateProject ( project , user ) ;
36+ return convertBetweenEntityAndDTO ( updatedProject , ProjectDTO ) ;
3037 }
3138}
0 commit comments