Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from paywteam/vacant/apply-daynum
Browse files Browse the repository at this point in the history
Vacant resource data format is changed.
  • Loading branch information
ihooni authored Aug 9, 2019
2 parents a65fb43 + 5ba0faa commit c3f2c7e
Show file tree
Hide file tree
Showing 6 changed files with 22,218 additions and 24,719 deletions.
7 changes: 2 additions & 5 deletions src/app/helpers/EmptyClassroomChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LectureDoc } from 'Database/schemas/lecture'
import { ClassDoc } from 'Database/schemas/class'

interface CurrentDate {
day: string
day: number
time: string
}

Expand Down Expand Up @@ -54,10 +54,7 @@ export default class EmptyClassroomChecker {
new Date().toLocaleString('en-US', { timeZone: 'Asia/Seoul' })
)

let day = local_date
.toString()
.split(' ')[0]
.toUpperCase()
let day = local_date.getDay()
let hour = local_date
.getHours()
.toString()
Expand Down
27 changes: 2 additions & 25 deletions src/app/helpers/LecturesComparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,13 @@ export default class LecturesComparator {
*/
public static comparator(): Comparator {
return (a, b) => {
let num_a = this.dayToNum(a.time.day)
let num_b = this.dayToNum(b.time.day)

return num_a < num_b
return a.time.day < b.time.day
? -1
: num_a > num_b
: a.time.day > b.time.day
? 1
: a.time.start < b.time.start
? -1
: 1
}
}

/**
* Convert day of week to number.
* ex) SUN - SAT => 0 - 6
*
* @param day
*/
private static dayToNum(day: string): number {
const day_num: { [index: string]: number } = {
SUN: 0,
MON: 1,
TUE: 2,
WED: 3,
THU: 4,
FRI: 5,
SAT: 6
}

return day_num[day.toUpperCase()]
}
}
2 changes: 1 addition & 1 deletion src/app/http/controllers/vacant/ClassroomsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Floor from 'Database/models/floor'
import logger from 'Configs/log'
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'
import LecturesComparator from 'Helpers/LecturesComparator'
import { TimeDoc } from 'Database/schemas/time'

export interface LectureInfo {
name: string
Expand Down
4 changes: 2 additions & 2 deletions src/database/schemas/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import mongoose, { Document } from 'mongoose'

export interface TimeDoc extends Document {
day: string
day: number
start: string
end: string
}

const timeSchema = new mongoose.Schema({
day: { type: String, required: true }, // ex. MON
day: { type: Number, required: true }, // SUN - SAT => 0 - 6
start: { type: String, required: true }, // ex. 3:30pm -> 1530
end: { type: String, required: true }
})
Expand Down
Loading

0 comments on commit c3f2c7e

Please sign in to comment.