Skip to content

Commit 0bd1f79

Browse files
Copilotsezanzeb
andauthored
fix: correct _ratings→_projects, add NotFoundError, fix imports/types in project-controller
Agent-Logs-Url: https://github.com/hackaburg/tilt/sessions/b49199e5-4de9-427d-ab30-cee6555e2094 Co-authored-by: sezanzeb <28510156+sezanzeb@users.noreply.github.com>
1 parent 0c12819 commit 0bd1f79

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

backend/src/controllers/project-controller.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { Authorized, Delete, JsonController, NotFoundError } from "routing-controllers";
1+
import { Authorized, Delete, JsonController, NotFoundError, Put, Param, Body, CurrentUser } from "routing-controllers";
22
import { Inject } from "typedi";
33
import { UserRole } from "../entities/user-role";
44
import { 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

Comments
 (0)