Skip to content

Commit

Permalink
Merge pull request #324 from wafflestudio/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Hank-Choi authored Aug 28, 2023
2 parents 5309105 + 86d8024 commit b0a484e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/timetable/TimetableLectureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export async function partialModifyUserLecture(userId: string, tableId: string,
throw new TimetableNotFoundError();
}

if (lecture.course_title === "") throw new InvalidLectureUpdateRequestError(lecture);

if (lecture.course_number || lecture.lecture_number) {
throw new InvalidLectureUpdateRequestError(lecture);
}
Expand Down
12 changes: 10 additions & 2 deletions src/core/timetable/TimetableRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let userLectureSchema = new mongoose.Schema({
classification: String, // 교과 구분
department: String, // 학부
academic_year: String, // 학년
course_title: {type: String, required: true}, // 과목명
course_title: {type: String, required: true, default: ""}, // 과목명
credit: Number, // 학점
class_time: String,
real_class_time: String,
Expand Down Expand Up @@ -47,6 +47,7 @@ let TimetableSchema = new mongoose.Schema({
title: {type: String, required: true},
lecture_list: [userLectureSchema],
updated_at: Date,
is_primary: Boolean,
theme: {type: Number, required: true, default: 0, min: 0, max:NUMBER_OF_THEME-1}
});

Expand Down Expand Up @@ -74,6 +75,11 @@ export async function findByUserIdAndMongooseId(userId: string, mongooseId: stri
return fromMongoose(doc);
}

export async function existsByUseridAndSemester(userId: string, year: number, semester: number): Promise<Boolean> {
let doc = await mongooseModel.findOne({'user_id': userId, 'year': year, 'semester': semester}).exec();
return fromMongoose(doc) != null;
}

export async function findByUserIdAndSemester(userId: string, year: number, semester: number): Promise<Timetable[]> {
let docs = await mongooseModel.find({'user_id': userId, 'year': year, 'semester': semester}).exec();
return docs.map(fromMongoose);
Expand Down Expand Up @@ -243,6 +249,7 @@ export async function insert(table: Timetable): Promise<Timetable> {
title: table.title,
theme: table.theme,
lecture_list: table.lecture_list,
is_primary: table.is_primary,
updated_at: table.updated_at
});
await doc.save();
Expand Down Expand Up @@ -283,7 +290,8 @@ function fromMongoose(mongooseDoc): Timetable {
title: mongooseDoc.title,
lecture_list: lecture_list,
theme: mongooseDoc.theme,
updated_at: mongooseDoc.updated_at
updated_at: mongooseDoc.updated_at,
is_primary: mongooseDoc.is_primary,
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/timetable/TimetableService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AbstractTimetable from './model/AbstractTimetable';
import TimetableNotEnoughParamError from './error/TimetableNotEnoughParamError';
import ThemeTypeEnum from "@app/core/timetable/model/ThemeTypeEnum";
import SnuttevLectureKey from "@app/core/lecture/model/SnuttevLectureKey";
import {existsByUseridAndSemester} from "@app/core/timetable/TimetableRepository";

//deprecated
export async function copy(timetable: Timetable): Promise<void> {
Expand Down Expand Up @@ -93,6 +94,7 @@ export async function addCopyFromSourceId(user, sourceId): Promise<Timetable> {
title: newTitle,
theme : source.theme,
lecture_list: source.lecture_list,
is_primary: source.is_primary,
updated_at: Date.now()
};
await validateTimetable(newTimetable)
Expand All @@ -108,13 +110,17 @@ export async function addCopyFromSourceId(user, sourceId): Promise<Timetable> {
}

export async function addFromParam(params): Promise<Timetable> {
let isFirstTimeTableOfTheSemester =
!await TimetableRepository.existsByUseridAndSemester(params.user_id, params.year, params.semester)

let newTimetable: Timetable = {
user_id : params.user_id,
year : params.year,
semester : params.semester,
title : params.title,
theme : ThemeTypeEnum.SNUTT,
lecture_list : [],
is_primary: isFirstTimeTableOfTheSemester,
updated_at: Date.now()
};

Expand Down
1 change: 1 addition & 0 deletions src/core/timetable/model/Timetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default interface Timetable {
title: string;
lecture_list: UserLecture[];
theme: number;
is_primary: boolean;
updated_at: number;
};

0 comments on commit b0a484e

Please sign in to comment.