|
1 | | -import { ForbiddenError } from "routing-controller"; |
| 1 | +import { ForbiddenError } from "routing-controllers"; |
2 | 2 | import { Inject, Service, Token } from "typedi"; |
3 | 3 | import { Repository } from "typeorm"; |
4 | 4 | import { IService } from "."; |
|
9 | 9 | convertBetweenEntityAndDTO, |
10 | 10 | } from "../controllers/dto"; |
11 | 11 | import { User } from "../entities/user"; |
| 12 | +import { Team } from "../entities/team"; |
| 13 | +import { Project } from "../entities/project"; |
12 | 14 | import { Criteria } from "../entities/criteria"; |
13 | 15 | import { Rating } from "../entities/rating"; |
14 | 16 |
|
@@ -68,6 +70,8 @@ export const RatingServiceToken = new Token<IRatingService>(); |
68 | 70 | @Service(RatingServiceToken) |
69 | 71 | export class RatingService implements IRatingService { |
70 | 72 | private _ratings!: Repository<Rating>; |
| 73 | + private _projects!: Repository<Project>; |
| 74 | + private _teams!: Repository<Team>; |
71 | 75 | private _users!: Repository<User>; |
72 | 76 |
|
73 | 77 | public constructor( |
@@ -150,13 +154,13 @@ export class RatingService implements IRatingService { |
150 | 154 | throw new ForbiddenError("Cannot create rating due to application settings") |
151 | 155 | } |
152 | 156 |
|
153 | | - const project = await this._projects.getProject(data.id); |
| 157 | + const project = await await this._projects.findOneBy({ id: data.id }); |
154 | 158 | if (!project.allowRating) { |
155 | 159 | // TODO test |
156 | 160 | throw new ForbiddenError("Creating a rating for this project is not allowed") |
157 | 161 | } |
158 | 162 |
|
159 | | - const team = await this._teams.getTeamById(project.teamId) |
| 163 | + const team = await this._teams.findOneById(project.teamId) |
160 | 164 | if (team.users.inclues(user.id)) { |
161 | 165 | // TODO test |
162 | 166 | throw new ForbiddenError("You can't rate your own project") |
|
0 commit comments