Skip to content

Commit

Permalink
Merge branch 'dev' into feat/scholar-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
doxylee committed Oct 25, 2024
2 parents 98437fb + 2dbd500 commit 65153ab
Show file tree
Hide file tree
Showing 25 changed files with 769 additions and 231 deletions.
117 changes: 116 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.6",
"csurf": "^1.10.0",
"date-fns": "^3.6.0",
"dotenv": "^16.0.3",
"dotenv": "^16.4.5",
"dotenv-cli": "^7.2.1",
"enquirer": "^2.4.1",
"express-session": "^1.17.3",
Expand All @@ -84,6 +85,7 @@
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/bcrypt": "^5.0.0",
"@types/csurf": "^1.11.5",
"@types/express": "^4.17.13",
"@types/inquirer": "^9.0.7",
"@types/jest": "28.1.4",
Expand Down
16 changes: 16 additions & 0 deletions src/bootstrap/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ValidationPipe, VersioningType } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import cookieParser from 'cookie-parser';
import csrf from 'csurf';
import session from 'express-session';
import { AppModule } from '../app.module';
import settings from '../settings';
Expand Down Expand Up @@ -29,6 +30,21 @@ async function bootstrap() {
}),
);
app.use(cookieParser());
app.use(
'/',
csrf({
cookie: { key: 'csrftoken' },
ignoreMethods: [
'GET',
'HEAD',
'OPTIONS',
'DELETE',
'PATCH',
'PUT',
'POST',
],
}),
);
// Logs requests
// app.use(
// morgan(':method :url OS/:req[client-os] Ver/:req[client-api-version]', {
Expand Down
11 changes: 9 additions & 2 deletions src/common/entities/EPlanners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export namespace EPlanners {

export namespace Taken {
export const Basic =
Prisma.validator<Prisma.planner_takenplanneritemArgs>()({});
export type Basic = Prisma.planner_futureplanneritemGetPayload<
Prisma.validator<Prisma.planner_takenplanneritemDefaultArgs>()({});
export type Basic = Prisma.planner_takenplanneritemGetPayload<
typeof Basic
>;

Expand Down Expand Up @@ -67,6 +67,13 @@ export namespace EPlanners {
>;
}
export namespace Arbitrary {
export const CreateInput =
Prisma.validator<Prisma.planner_arbitraryplanneritemUncheckedCreateInput>()(
{},
);
export type CreateInput =
Prisma.planner_arbitraryplanneritemUncheckedCreateInput;

export const Basic =
Prisma.validator<Prisma.planner_arbitraryplanneritemArgs>()({});
export type Basic = Prisma.planner_arbitraryplanneritemGetPayload<
Expand Down
28 changes: 28 additions & 0 deletions src/common/interfaces/IPlanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,32 @@ export namespace IPlanner {
@Type(() => Number)
credit_au!: number;
}

export class UpdateBodyDto {
// @Todo start_year cannot be greater than end_year, also start_year cannot be greater than now
@IsInt()
@Type(() => Number)
start_year!: number;

@IsInt()
@Type(() => Number)
end_year!: number;

@IsInt()
@Type(() => Number)
general_track!: number;

@IsInt()
@Type(() => Number)
major_track!: number;

@Transform(({ value }) => (typeof value === 'number' ? [value] : value))
@IsArray()
@IsInt({ each: true })
additional_tracks!: number[];

@IsOptional()
@IsBoolean()
should_update_taken_semesters?: boolean;
}
}
22 changes: 11 additions & 11 deletions src/common/interfaces/serializer/course.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export function toJsonFeedBasic(course: subject_course): ICourse.FeedBasic {
title: course.title,
title_en: course.title_en,
summary: course.summury,
grade_sum: course.grade_sum,
load_sum: course.load_sum,
speech_sum: course.speech_sum,
review_total_weight: course.review_total_weight,
grade: course.grade,
load: course.load,
speech: course.speech,
grade_sum: course.grade_sum + 0.00001,
load_sum: course.load_sum + 0.00001,
speech_sum: course.speech_sum + 0.000001,
review_total_weight: course.review_total_weight + 0.000001,
grade: course.grade + 0.000001,
load: course.load + 0.00001,
speech: course.speech + 0.00001,
title_en_no_space: course.title_en_no_space,
title_no_space: course.title_no_space,
};
Expand All @@ -53,7 +53,7 @@ export function toJsonCourseBasic(
title: course.title,
title_en: course.title_en,
summary: course.summury, // Todo: fix summury typo in db.
review_total_weight: course.review_total_weight,
review_total_weight: course.review_total_weight + 0.000001,
credit: lecture.credit ?? 0,
credit_au: lecture.credit_au ?? 0,
num_classes: lecture.num_classes ?? 0,
Expand All @@ -74,9 +74,9 @@ export function toJsonCourseDetail(
related_courses_prior: [],
related_courses_posterior: [],
professors: professorSorted,
grade: course.grade,
load: course.load,
speech: course.speech,
grade: course.grade + 0.000001,
load: course.load + 0.000001,
speech: course.speech + 0.000001,
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/interfaces/serializer/lecture.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function toJsonLectureBasic(lecture: ELecture.Extended): ILecture.Basic {
common_title_en: lecture.common_title_en ?? '',
class_title: lecture.class_title ?? '',
class_title_en: lecture.class_title_en ?? '',
review_total_weight: lecture.review_total_weight,
review_total_weight: lecture.review_total_weight + 0.000001,
professors: toJsonProfessors(ordered_professors),
};
}
Expand All @@ -50,9 +50,9 @@ export function toJsonLectureDetail(
throw new Error("Lecture is not of type 'ELecture.Details'");

return Object.assign(basic, {
grade: lecture.grade,
load: lecture.load,
speech: lecture.speech,
grade: lecture.grade + 0.000001,
load: lecture.load + 0.000001,
speech: lecture.speech + 0.000001,
classtimes: lecture.subject_classtime.map((classtime) =>
toJsonClasstime(classtime),
),
Expand Down
2 changes: 1 addition & 1 deletion src/common/interfaces/serializer/professor.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const toJsonProfessors = (
name: professor.professor_name,
name_en: professor.professor_name_en ?? '',
professor_id: professor.professor_id,
review_total_weight: professor.review_total_weight,
review_total_weight: professor.review_total_weight + 0.000001,
};
});

Expand Down
10 changes: 5 additions & 5 deletions src/common/interfaces/serializer/review.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export const toJsonReview = (
content: review.is_deleted
? '관리자에 의해 삭제된 코멘트입니다.'
: review.content,
like: review.like,
is_deleted: review.is_deleted,
grade: review.grade,
load: review.load,
speech: review.speech,
like: Math.round(review.like),
is_deleted: Math.round(review.is_deleted),
grade: Math.round(review.grade),
load: Math.round(review.load),
speech: Math.round(review.speech),
userspecific_is_liked: isLiked,
};
return result;
Expand Down
29 changes: 29 additions & 0 deletions src/common/pipe/planner.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
BadRequestException,
Injectable,
PipeTransform,
ArgumentMetadata,
} from '@nestjs/common';
import { PrismaService } from '@src/prisma/prisma.service';

@Injectable()
export class PlannerPipe implements PipeTransform {
constructor(private prismaService: PrismaService) {}

async transform(value: any, metadata: ArgumentMetadata): Promise<number> {
const plannerId = parseInt(value, 10);
if (isNaN(plannerId)) {
throw new BadRequestException('Invalid planner ID');
}

const planner = await this.prismaService.planner_planner.findUnique({
where: { id: plannerId },
});

if (!planner) {
throw new BadRequestException('Planner not found');
}

return plannerId;
}
}
Loading

0 comments on commit 65153ab

Please sign in to comment.