-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from sparcs-kaist/issue/159/prohibit-review-a…
…fter-sync add: prevent review submission for 2025-1 lectures
- Loading branch information
Showing
6 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { SetMetadata } from '@nestjs/common'; | ||
|
||
export const IS_REVIEW_PROHIBITED_KEY = 'isReviewProhibited'; | ||
export const ReviewProhibited = () => | ||
SetMetadata(IS_REVIEW_PROHIBITED_KEY, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { IS_REVIEW_PROHIBITED_KEY } from '../../../common/decorators/prohibit-review.decorator'; | ||
import { Reflector } from '@nestjs/core'; | ||
import { AuthCommand, AuthResult } from '../auth.command'; | ||
import { LecturesService } from '@src/modules/lectures/lectures.service'; | ||
import { Request } from 'express'; | ||
|
||
@Injectable() | ||
export class IsReviewProhibitedCommand implements AuthCommand { | ||
constructor( | ||
private reflector: Reflector, | ||
private lectureService: LecturesService, | ||
) {} | ||
|
||
public async next( | ||
context: ExecutionContext, | ||
prevResult: AuthResult, | ||
): Promise<AuthResult> { | ||
const isReviewProhibited = this.reflector.getAllAndOverride<boolean>( | ||
IS_REVIEW_PROHIBITED_KEY, | ||
[context.getHandler()], | ||
); | ||
|
||
const request = context.switchToHttp().getRequest<Request>(); | ||
const reviewsBody = request.body; | ||
|
||
if (isReviewProhibited) { | ||
try { | ||
if (!reviewsBody || !reviewsBody.lecture) { | ||
throw new Error('lecture info are not found from request'); | ||
} | ||
const lecture = await this.lectureService.getLectureById( | ||
reviewsBody.lecture, | ||
); | ||
// TODO: implement logic to replace hardcoded values | ||
if (lecture.year == 2025 && lecture.semester == 1) { | ||
prevResult.authorization = false; | ||
} | ||
return Promise.resolve(prevResult); | ||
} catch (e) { | ||
console.log(e); | ||
return Promise.resolve(prevResult); | ||
} | ||
} | ||
|
||
return Promise.resolve(prevResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters