Skip to content

Commit

Permalink
feat: syllabus
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaemin committed Mar 28, 2020
1 parent 2ca45e5 commit 56b2011
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/api/lectures/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TableNames } from '@/database/table-names'
import Db from '@/db'
import SqlB from '@/modules/sqlb'
import express from 'express'
Expand Down Expand Up @@ -31,11 +32,13 @@ router.get('/lectures/:year/:semester/:campus/list', async (req, res) => {
const offset = parseInt(req.query?.offset) || 0

const query = SqlB()
.select(...lectureAttrs)
.from('lecture')
.select(`${TableNames.lecture}.*, major.code AS major_code`)
.from()
.join(TableNames.lecture, `${TableNames.coverage_major} major`, 'left')
.on(`${TableNames.lecture}.major = major.name`)
.where(`year=? AND semester=? AND campus=?`)
.multiOrder([
['name', 'ASC'],
['lecture.name', 'ASC'],
['professor', 'ASC'],
['schedule', 'ASC'],
])
Expand All @@ -61,21 +64,25 @@ router.get('/lectures/:year/:semester/:campus/search', async (req, res) => {

const [err, results] = await Db.query(
SqlB()
.select(...lectureAttrs)
.from('lecture')
.select(`${TableNames.lecture}.*, major.code AS major_code`)
.from()
.join(TableNames.lecture, `${TableNames.coverage_major} major`, 'left')
.on(`${TableNames.lecture}.major = major.name`)
.where(`year=? AND semester=? AND campus=?`)
.and()
.like('college', `%${searchKeyword}%`)
.or()
.like('major', `%${searchKeyword}%`)
.or()
.like('name', `%${searchKeyword}%`)
.like('lecture.name', `%${searchKeyword}%`)
.or()
.like('lecture.code', `%${searchKeyword}%`)
.or()
.like('schedule', `%${searchKeyword}%`)
.or()
.like('professor', `%${searchKeyword}%`)
.multiOrder([
['name', 'ASC'],
['lecture.name', 'ASC'],
['professor', 'ASC'],
['schedule', 'ASC'],
])
Expand Down

0 comments on commit 56b2011

Please sign in to comment.