File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments