Skip to content

Commit

Permalink
fix: replaced hardcoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
Bae-Jihoon committed Jan 14, 2025
1 parent 8c319ca commit 14a7019
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 14a7019

Please sign in to comment.