Skip to content

Commit 7e2c057

Browse files
Copilotsezanzeb
andauthored
Fix compiler errors in rating-service.ts checkPermission method
Agent-Logs-Url: https://github.com/hackaburg/tilt/sessions/8d471d1c-0a80-4209-ba56-9bb37b05ebf3 Co-authored-by: sezanzeb <28510156+sezanzeb@users.noreply.github.com>
1 parent e194e23 commit 7e2c057

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

backend/src/services/rating-service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export class RatingService implements IRatingService {
8383
*/
8484
public async bootstrap(): Promise<void> {
8585
this._ratings = this._database.getRepository(Rating);
86+
this._projects = this._database.getRepository(Project);
87+
this._teams = this._database.getRepository(Team);
8688
this._users = this._database.getRepository(User);
8789
}
8890

@@ -154,14 +156,20 @@ export class RatingService implements IRatingService {
154156
throw new ForbiddenError("Cannot create rating due to application settings")
155157
}
156158

157-
const project = await await this._projects.findOneBy({ id: data.id });
159+
const project = await this._projects.findOneBy({ id: rating.project.id });
160+
if (!project) {
161+
throw new ForbiddenError("Project not found");
162+
}
158163
if (!project.allowRating) {
159164
// TODO test
160165
throw new ForbiddenError("Creating a rating for this project is not allowed")
161166
}
162167

163-
const team = await this._teams.findOneById(project.teamId)
164-
if (team.users.inclues(user.id)) {
168+
const team = await this._teams.findOneBy({ id: project.team.id })
169+
if (!team) {
170+
throw new ForbiddenError("Team not found");
171+
}
172+
if (team.users.includes(user.id)) {
165173
// TODO test
166174
throw new ForbiddenError("You can't rate your own project")
167175
}

0 commit comments

Comments
 (0)