Skip to content

Commit

Permalink
refactor: removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphajax committed Oct 27, 2023
1 parent e5de929 commit a4f0ac0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 85 deletions.
2 changes: 0 additions & 2 deletions server/src/routes/course/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ import {
updateStudentStatus,
} from './student';
import * as tasks from './tasks';
import { postCopyCourse } from './template';

export function courseRoute(logger: ILogger) {
const router = new Router<any, any>({ prefix: '/course/:courseId' });

router.post('/certificates', courseManagerGuard, postCertificates(logger));
router.post('/repositories', courseManagerGuard, createRepositories(logger));
router.put('/repositories', courseManagerGuard, updateRepositories(logger));
router.post('/copy', adminGuard, postCopyCourse(logger));

addScoreApi(router, logger);
addStageInterviewApi(router, logger);
Expand Down
12 changes: 0 additions & 12 deletions server/src/routes/course/template.ts

This file was deleted.

71 changes: 0 additions & 71 deletions server/src/services/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,6 @@ export async function getCourseTask(taskId: number) {
return courseTasks;
}

export async function getCourseTasks(courseId: number) {
const courseTasks = await getRepository(CourseTask)
.createQueryBuilder('courseTask')
.innerJoinAndSelect('courseTask.task', 'task')
.where('courseTask.courseId = :courseId', { courseId })
.andWhere('courseTask.disabled = :disabled', { disabled: false })
.getMany();
return courseTasks;
}

export async function getCourseTasksWithOwner(courseId: number) {
const courseTasks = await getRepository(CourseTask)
.createQueryBuilder('courseTask')
Expand Down Expand Up @@ -670,65 +660,4 @@ export async function getCrossMentorsByStudent(courseId: number, githubId: strin
return students;
}

function shiftDate(date: string, shift: number, format: string): string {
return moment(date).add(shift, 'days').format(format);
}

function adjustEvent(event: any, startDateDaysDiff: number, courseId: number) {
delete event.id;
delete event.createdDate;
delete event.updatedDate;

event.dateTime = shiftDate(event.dateTime, startDateDaysDiff, 'YYYY-MM-DD HH:mmZ');
if (event.endTime) {
event.endTime = shiftDate(event.endTime, startDateDaysDiff, 'YYYY-MM-DD HH:mmZ');
}
event.courseId = courseId;
}

function adjustTask(task: any, startDateDaysDiff: number, courseId: number) {
delete task.id;
delete task.createdDate;
delete task.updatedDate;
delete task.crossCheckStatus;

task.studentStartDate = shiftDate(task.studentStartDate, startDateDaysDiff, 'YYYY-MM-DD HH:mmZ');
task.studentEndDate = shiftDate(task.studentEndDate, startDateDaysDiff, 'YYYY-MM-DD HH:mmZ');
if (task.mentorStartDate) {
task.mentorStartDate = shiftDate(task.mentorStartDate, startDateDaysDiff, 'YYYY-MM-DD HH:mmZ');
}
if (task.mentorEndDate) {
task.mentorEndDate = shiftDate(task.mentorEndDate, startDateDaysDiff, 'YYYY-MM-DD HH:mmZ');
}
if (task.crossCheckEndDate) {
task.crossCheckEndDate = shiftDate(task.crossCheckEndDate, startDateDaysDiff, 'YYYY-MM-DD HH:mmZ');
}
task.courseId = courseId;
}

export async function createCourseFromCopy(courseId: number, details: any) {
const courseToCopy = await getRepository(Course).findOneBy({ id: courseId });

if (courseToCopy && courseToCopy.id) {
const events: any = await getEvents(courseId);
const tasks: any = await getCourseTasks(courseId);
const { id, ...couseWithoutId } = courseToCopy;
const courseCopy: Course = { ...couseWithoutId, ...details };
const courseData = await getRepository(Course).insert(courseCopy);

const startDateDaysDiff = moment(details.startDate).diff(moment(courseToCopy.startDate), 'days');
courseCopy.id = courseData.identifiers[0].id;

events.forEach((e: CourseEvent) => adjustEvent(e, startDateDaysDiff, courseCopy.id));
const savedEventsData = await getRepository(CourseEvent).insert(events);

tasks.forEach((t: CourseTask) => adjustTask(t, startDateDaysDiff, courseCopy.id));
const savedTasksData = await getRepository(CourseTask).insert(tasks);

return { courseCopy, savedEventsData, savedTasksData };
}

throw new Error(`not valid course to copy id: ${courseId}`);
}

const timeout = async (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

0 comments on commit a4f0ac0

Please sign in to comment.