Skip to content

Commit

Permalink
Merge pull request #166 from sparcs-kaist/issue/164/prevent-review-su…
Browse files Browse the repository at this point in the history
…bmission-for-drop-period

fix: replaced hardcoded values
  • Loading branch information
Bae-Jihoon authored Jan 16, 2025
2 parents e321f62 + f37f223 commit a29d37d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/modules/auth/command/isReviewProhibited.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { Reflector } from '@nestjs/core';
import { AuthCommand, AuthResult } from '../auth.command';
import { LecturesService } from '@src/modules/lectures/lectures.service';
import { Request } from 'express';
import { PrismaService } from '@src/prisma/prisma.service';

@Injectable()
export class IsReviewProhibitedCommand implements AuthCommand {
constructor(
private reflector: Reflector,
private lectureService: LecturesService,
private prismaService: PrismaService,
) {}

public async next(
Expand All @@ -22,6 +24,7 @@ export class IsReviewProhibitedCommand implements AuthCommand {
);

const request = context.switchToHttp().getRequest<Request>();
const requestTime = new Date();
const reviewsBody = request.body;

if (isReviewProhibited) {
Expand All @@ -32,10 +35,23 @@ export class IsReviewProhibitedCommand implements AuthCommand {
const lecture = await this.lectureService.getLectureById(
reviewsBody.lecture,
);
// TODO: implement logic to replace hardcoded values
if (lecture.year == 2025 && lecture.semester == 1) {

const semester = await this.prismaService.subject_semester.findFirst({
where: {
AND: [{ year: lecture.year }, { semester: lecture.semester }],
},
select: {
courseDropDeadline: true,
},
});
if (!semester || !semester.courseDropDeadline) {
throw new Error('semester info are not found from request');
}

if (requestTime < semester.courseDropDeadline) {
prevResult.authorization = false;
}

return Promise.resolve(prevResult);
} catch (e) {
console.log(e);
Expand Down

0 comments on commit a29d37d

Please sign in to comment.