From a9f7604c473ab18cf4199419be5449d5db5a420d Mon Sep 17 00:00:00 2001 From: "H.Chihoon" Date: Thu, 8 Aug 2019 15:00:12 +0900 Subject: [PATCH] Deprecate old vacant controllers. --- .../vacant/BuildingListController.ts | 129 -------------- .../vacant/ClassroomListController.ts | 122 -------------- .../controllers/vacant/FloorListController.ts | 157 ------------------ .../vacant/UniversityListController.ts | 40 ----- src/routes/api.ts | 94 ----------- 5 files changed, 542 deletions(-) delete mode 100644 src/app/http/controllers/vacant/BuildingListController.ts delete mode 100644 src/app/http/controllers/vacant/ClassroomListController.ts delete mode 100644 src/app/http/controllers/vacant/FloorListController.ts delete mode 100644 src/app/http/controllers/vacant/UniversityListController.ts diff --git a/src/app/http/controllers/vacant/BuildingListController.ts b/src/app/http/controllers/vacant/BuildingListController.ts deleted file mode 100644 index 23d8229..0000000 --- a/src/app/http/controllers/vacant/BuildingListController.ts +++ /dev/null @@ -1,129 +0,0 @@ -import University from 'Database/models/university' -import EmptyClassroomChecker from 'Helpers/EmptyClassroomChecker' -import logger from 'Configs/log' -import { UniversityDoc } from 'Database/schemas/university' -import { BuildingDoc } from 'Database/schemas/building' -import { FloorDoc } from 'Database/schemas/floor' - -interface BldgInfo { - number: string - name: string -} - -interface BldgEmptyInfo extends BldgInfo { - empty_classroom: number - total_classroom: number -} - -export default class BuildingListController { - public async getList(vendor: string): Promise { - const university = await University.findOne( - { vendor: vendor }, - { _id: 0, buildings: 1 }, - err => { - if (err) { - logger.error(err) - } - } - ).populate({ - path: 'buildings', - select: 'number name floors -_id', - options: { sort: { number: 1 } } - }) - - // if not found - if (!university) { - return Promise.reject('university not found') - } - - if (university.buildings.length == 0) { - return Promise.reject('buildings not found') - } - - const building_list: BldgInfo[] = [] - - university.buildings.forEach((building: BuildingDoc) => { - if (building.floors.length != 0) { - building_list.push({ - number: building.number, - name: building.name - }) - } - }) - - return Promise.resolve(building_list) - } - - public async getListIncludeEmptyNum( - vendor: string - ): Promise { - const university = await University.findOne( - { vendor: vendor }, - { _id: 0, buildings: 1 }, - err => { - if (err) { - logger.error(err) - } - } - ).populate({ - path: 'buildings', - select: 'number name floors -_id', - options: { sort: { number: 1 } }, - populate: { - path: 'floors', - select: 'classrooms -_id' - } - }) - - // if not found - if (!university) { - return Promise.reject('university not found') - } - - if (university.buildings.length == 0) { - return Promise.reject('buildings not found') - } - - const empty_controller = new EmptyClassroomChecker() - const building_list: BldgEmptyInfo[] = [] - const promise_list: Promise[][] = [] - - university.buildings.forEach((building: BuildingDoc) => { - if (building.floors.length != 0) { - promise_list.push([]) - - building.floors.forEach((floor: FloorDoc) => { - floor.classrooms.forEach((classroom_id: string) => { - promise_list[promise_list.length - 1].push( - empty_controller.isEmpty(classroom_id) - ) - }) - }) - - building_list.push({ - number: building.number, - name: building.name, - empty_classroom: 0, - total_classroom: promise_list[promise_list.length - 1].length - }) - } - }) - - const async_promise_list: Promise[] = [] - - for (let i = 0; i < promise_list.length; i++) { - async_promise_list[i] = Promise.all(promise_list[i]) - } - - let empty_lists = await Promise.all(async_promise_list) - empty_lists.forEach((empty_list, index) => { - empty_list.forEach(is_empty => { - if (is_empty) { - building_list[index].empty_classroom++ - } - }) - }) - - return Promise.resolve(building_list) - } -} diff --git a/src/app/http/controllers/vacant/ClassroomListController.ts b/src/app/http/controllers/vacant/ClassroomListController.ts deleted file mode 100644 index f624ef4..0000000 --- a/src/app/http/controllers/vacant/ClassroomListController.ts +++ /dev/null @@ -1,122 +0,0 @@ -import University from 'Database/models/university' -import { UniversityDoc } from 'Database/schemas/university' -import logger from 'Configs/log' -import { BuildingDoc } from 'Database/schemas/building' -import { FloorDoc } from 'Database/schemas/floor' -import { ClassroomDoc } from 'Database/schemas/classroom' -import { TimeDoc } from 'Database/schemas/time' -import { LectureDoc } from 'Database/schemas/lecture' -import { ClassDoc } from 'Database/schemas/class' - -interface LectureInfo { - name: string - instructor: string - time: TimeDoc -} - -interface ClassroomInfo { - number: string - lectures: LectureInfo[] -} - -export default class ClassroomListController { - public async getList( - vendor: string, - building_num: string, - floor_num: string - ): Promise { - const university = await University.findOne( - { vendor: vendor }, - { _id: 0, buildings: 1 }, - err => { - if (err) { - logger.error(err) - } - } - ).populate({ - path: 'buildings', - select: 'number floors -_id', - match: { number: building_num }, - populate: { - path: 'floors', - select: 'number classrooms -_id', - match: { number: floor_num }, - populate: { - path: 'classrooms', - select: 'number lectures -_id', - options: { sort: { number: 1 } }, - populate: { - path: 'lectures', - select: 'class order -_id', - populate: { - path: 'class', - select: 'name instructor times.day times.start times.end -_id' - } - } - } - } - }) - - let building, floor - - // if not found - if (!university) { - return Promise.reject('university not found') - } - - if (!university.buildings[0]) { - return Promise.reject('building not found') - } - building = university.buildings[0] - - if (!building.floors[0]) { - return Promise.reject('floor not found') - } - floor = building.floors[0] - - if (floor.classrooms.length == 0) { - return Promise.reject('classrooms not found') - } - - let lecture_list: LectureInfo[] - const classroom_list: ClassroomInfo[] = [] - - floor.classrooms.forEach((classroom: ClassroomDoc) => { - lecture_list = [] - classroom.lectures.forEach((lecture: LectureDoc) => { - lecture_list.push({ - name: (lecture.class).name, - instructor: (lecture.class).instructor, - time: (lecture.class).times[lecture.order] - }) - }) - - lecture_list.sort((a, b) => { - const day_num: { [index: string]: number } = { - MON: 0, - TUE: 1, - WED: 2, - THU: 3, - FRI: 4, - SAT: 5, - SUN: 6 - } - - return day_num[a.time.day] > day_num[b.time.day] - ? 1 - : day_num[a.time.day] < day_num[b.time.day] - ? -1 - : a.time.start > b.time.start - ? 1 - : -1 - }) - - classroom_list.push({ - number: classroom.number, - lectures: lecture_list - }) - }) - - return Promise.resolve(classroom_list) - } -} diff --git a/src/app/http/controllers/vacant/FloorListController.ts b/src/app/http/controllers/vacant/FloorListController.ts deleted file mode 100644 index 02d0541..0000000 --- a/src/app/http/controllers/vacant/FloorListController.ts +++ /dev/null @@ -1,157 +0,0 @@ -import University from 'Database/models/university' -import EmptyClassroomChecker from 'Helpers/EmptyClassroomChecker' -import logger from 'Configs/log' -import { UniversityDoc } from 'Database/schemas/university' -import { BuildingDoc } from 'Database/schemas/building' -import { FloorDoc } from 'Database/schemas/floor' - -interface FloorInfo { - number: string -} - -interface FloorEmptyInfo extends FloorInfo { - empty_classroom: number - total_classroom: number -} - -export default class FloorListController { - public async getList( - vendor: string, - building_num: string - ): Promise { - const university = await University.findOne( - { vendor: vendor }, - { _id: 0, buildings: 1 }, - err => { - if (err) { - logger.error(err) - } - } - ).populate({ - path: 'buildings', - select: 'number floors -_id', - match: { number: building_num }, - populate: { - path: 'floors', - select: 'number -_id' - } - }) - - let building - - // if not found - if (!university) { - return Promise.reject('university not found') - } - - if (!university.buildings[0]) { - return Promise.reject('building not found') - } - building = university.buildings[0] - - if (building.floors.length == 0) { - return Promise.reject('floors not found') - } - - building.floors.sort((a: FloorDoc, b: FloorDoc) => { - let int_a = this.floorToInt(a.number) - let int_b = this.floorToInt(b.number) - - return int_a > int_b ? -1 : int_a < int_b ? 1 : 0 - }) - - const floor_list: FloorInfo[] = [] - - building.floors.forEach((floor: FloorDoc) => { - floor_list.push({ - number: floor.number - }) - }) - - return Promise.resolve(floor_list) - } - - public async getListIncludeEmptyNum( - vendor: string, - building_num: string - ): Promise { - const university = await University.findOne( - { vendor: vendor }, - { _id: 0, buildings: 1 } - ).populate({ - path: 'buildings', - select: 'number floors -_id', - match: { number: building_num }, - populate: { - path: 'floors', - select: 'number classrooms -_id' - } - }) - - let building - - // if not found - if (!university) { - return Promise.reject('university not found') - } - - if (!university.buildings[0]) { - return Promise.reject('building not found') - } - building = university.buildings[0] - - if (building.floors.length == 0) { - return Promise.reject('floors not found') - } - - building.floors.sort((a: FloorDoc, b: FloorDoc) => { - let int_a = this.floorToInt(a.number) - let int_b = this.floorToInt(b.number) - - return int_a > int_b ? -1 : int_a < int_b ? 1 : 0 - }) - - const empty_controller = new EmptyClassroomChecker() - const floor_list: FloorEmptyInfo[] = [] - const promise_list: Promise[][] = [] - - building.floors.forEach((floor: FloorDoc, index) => { - promise_list[index] = [] - - floor.classrooms.forEach((classroom_id: string) => { - promise_list[index].push(empty_controller.isEmpty(classroom_id)) - }) - - floor_list.push({ - number: floor.number, - empty_classroom: 0, - total_classroom: promise_list[index].length - }) - }) - - const async_promise_list: Promise[] = [] - - for (let i = 0; i < promise_list.length; i++) { - async_promise_list[i] = Promise.all(promise_list[i]) - } - - let empty_lists = await Promise.all(async_promise_list) - empty_lists.forEach((empty_list, index) => { - empty_list.forEach(is_empty => { - if (is_empty) { - floor_list[index].empty_classroom++ - } - }) - }) - - return Promise.resolve(floor_list) - } - - private floorToInt(floor: string): number { - if (floor.substr(0, 1) == 'B') { - return -parseInt(floor.substr(1)) - } else { - return parseInt(floor) - } - } -} diff --git a/src/app/http/controllers/vacant/UniversityListController.ts b/src/app/http/controllers/vacant/UniversityListController.ts deleted file mode 100644 index ad5f005..0000000 --- a/src/app/http/controllers/vacant/UniversityListController.ts +++ /dev/null @@ -1,40 +0,0 @@ -import University from 'Database/models/university' -import logger from 'Configs/log' -import { UniversityDoc } from 'Database/schemas/university' -import { GlobalNameDoc } from 'Database/schemas/global_name' - -interface UnivInfo { - name: GlobalNameDoc - campus: GlobalNameDoc - vendor: string -} - -export default class UniversityListController { - public async getList(language: string): Promise { - const universities = await University.find( - {}, - { _id: 0, name: 1, campus: 1, vendor: 1 }, - err => { - if (err) { - logger.error(err) - } - } - ).sort([['name.' + language, 1]]) - - // if not found - if (universities.length == 0) { - return Promise.reject('universities not found') - } - - const univ_list: UnivInfo[] = [] - universities.forEach(university => { - univ_list.push({ - name: university.name[language], - campus: university.campus[language], - vendor: university.vendor - }) - }) - - return Promise.resolve(univ_list) - } -} diff --git a/src/routes/api.ts b/src/routes/api.ts index f0bbaaf..fafea20 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -1,8 +1,4 @@ import express from 'express' -import UniversityListController from 'Http/controllers/vacant/UniversityListController' -import BuildingListController from 'Http/controllers/vacant/BuildingListController' -import FloorListController from 'Http/controllers/vacant/FloorListController' -import ClassroomListController from 'Http/controllers/vacant/ClassroomListController' import LocaleMiddleware from 'Http/middleware/Locale' import CheckVendorMiddleware from 'Http/middleware/CheckVendor' import CampusesController from 'Http/controllers/CampusesController' @@ -26,94 +22,4 @@ router.use('/campuses/:vendor/vacant', vacant_router) // show campus list router.get('/campuses', LocaleMiddleware.handler(), CampusesController.index()) -// // University list data -// router.get('/university', async (req, res) => { -// const controller = new UniversityListController() -// -// try { -// const univ_list = await controller.getList(req.body.language) -// -// res.json({ err: false, universities: univ_list }) -// } catch (err) { -// res.json({ err: true, msg: err }) -// } -// }) -// -// // Building list data -// router.get('/:vendor', async (req, res) => { -// const controller = new BuildingListController() -// -// try { -// const building_list = await controller.getList(req.params.vendor) -// -// res.json({ err: false, buildings: building_list }) -// } catch (err) { -// res.json({ err: true, msg: err }) -// } -// }) -// -// // Building list data include number of empty classrooms -// router.get('/:vendor/empty', async (req, res) => { -// const controller = new BuildingListController() -// -// try { -// const building_list = await controller.getListIncludeEmptyNum( -// req.params.vendor -// ) -// -// res.json({ err: false, buildings: building_list }) -// } catch (err) { -// res.json({ err: true, msg: err }) -// } -// }) -// -// // Floor list data -// router.get('/:vendor/:building_num', async (req, res) => { -// const controller = new FloorListController() -// -// try { -// const floor_list = await controller.getList( -// req.params.vendor, -// req.params.building_num -// ) -// -// res.json({ err: false, floors: floor_list }) -// } catch (err) { -// res.json({ err: true, msg: err }) -// } -// }) -// -// // Floor list data include number of empty classrooms -// router.get('/:vendor/:building_num/empty', async (req, res) => { -// const controller = new FloorListController() -// -// try { -// const floor_list = await controller.getListIncludeEmptyNum( -// req.params.vendor, -// req.params.building_num -// ) -// -// res.json({ err: false, floors: floor_list }) -// } catch (err) { -// res.json({ err: true, msg: err }) -// } -// }) -// -// // Classroom list data -// router.get('/:vendor/:building_num/:floor_num', async (req, res) => { -// const controller = new ClassroomListController() -// -// try { -// const classroom_list = await controller.getList( -// req.params.vendor, -// req.params.building_num, -// req.params.floor_num.toUpperCase() -// ) -// -// res.json({ err: false, classrooms: classroom_list }) -// } catch (err) { -// res.json({ err: true, msg: err }) -// } -// }) - export default router