From a4f0ac0d5d7b44a27b3cd2a947ad63d8538643e3 Mon Sep 17 00:00:00 2001 From: Dzmitry Chervanenka Date: Fri, 27 Oct 2023 11:45:18 +0300 Subject: [PATCH] refactor: removed unused code --- server/src/routes/course/index.ts | 2 - server/src/routes/course/template.ts | 12 ----- server/src/services/course.service.ts | 71 --------------------------- 3 files changed, 85 deletions(-) delete mode 100644 server/src/routes/course/template.ts diff --git a/server/src/routes/course/index.ts b/server/src/routes/course/index.ts index dbd1c3597d..82f870534e 100644 --- a/server/src/routes/course/index.ts +++ b/server/src/routes/course/index.ts @@ -70,7 +70,6 @@ import { updateStudentStatus, } from './student'; import * as tasks from './tasks'; -import { postCopyCourse } from './template'; export function courseRoute(logger: ILogger) { const router = new Router({ prefix: '/course/:courseId' }); @@ -78,7 +77,6 @@ export function courseRoute(logger: ILogger) { 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); diff --git a/server/src/routes/course/template.ts b/server/src/routes/course/template.ts deleted file mode 100644 index b603e936e5..0000000000 --- a/server/src/routes/course/template.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ILogger } from '../../logger'; -import Router from '@koa/router'; -import { courseService } from '../../services'; -import { setResponse } from '../utils'; -import { OK } from 'http-status-codes'; - -export const postCopyCourse = (_: ILogger) => async (ctx: Router.RouterContext) => { - const { courseId } = ctx.params; - - const courseCopy = await courseService.createCourseFromCopy(courseId, ctx.request.body); - setResponse(ctx, OK, courseCopy.courseCopy, 60); -}; diff --git a/server/src/services/course.service.ts b/server/src/services/course.service.ts index 4d30f8f664..c41facbd5b 100644 --- a/server/src/services/course.service.ts +++ b/server/src/services/course.service.ts @@ -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') @@ -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));