core update, schedule router update, schedule populator update, collective update, other
This commit is contained in:
1 parent
7d97953877
commit
f3aaf5a547
8 files changed
+113
-178
No files matched your search
+23
-48
@@ -1,62 +1,37 @@
|
||||
/**
|
||||
* Created by tmshv on 22/11/14.
|
||||
*/
|
||||
import route from 'koa-route';
|
||||
import {json} from './';
|
||||
|
||||
var route = require("koa-route");
|
||||
var router = require("./");
|
||||
var db = require("../core/db");
|
||||
var schedule = require("../models/schedule");
|
||||
var populate = require("../utils/populate").populate;
|
||||
//import {getCourseNameByID} from "../models/course";
|
||||
//const team = require("../models/team");
|
||||
import {getSchedule, getScheduleList, populateSchedule} from '../core/schedule';
|
||||
|
||||
module.exports = function (app) {
|
||||
app.use(
|
||||
route.get("/schedule/:period?/:semester?", router.accepts(
|
||||
{
|
||||
"text/html": router.index(),
|
||||
"text/plain": router.index(),
|
||||
|
||||
"application/json": function *(period, semester) {
|
||||
this.type = "application/json";
|
||||
|
||||
var doPopulate = this.query.populate || false;
|
||||
|
||||
var data = yield db.c("schedules").findOne({
|
||||
period: period,
|
||||
semester: semester
|
||||
});
|
||||
|
||||
if(!data) {
|
||||
this.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
if(doPopulate) {
|
||||
//data.schedule = schedule.populate(data.schedule, [
|
||||
// populate(team.short, "teacher"),
|
||||
// populate(getCourseNameByID, "lesson")
|
||||
//]);
|
||||
}
|
||||
|
||||
this.body = data;
|
||||
}
|
||||
route.get('/schedule/list', json(
|
||||
function *() {
|
||||
this.type = 'application/json';
|
||||
let data = yield getScheduleList();
|
||||
if (!data) this.status = 404;
|
||||
else this.body = data;
|
||||
}
|
||||
))
|
||||
);
|
||||
|
||||
app.use(
|
||||
route.get("/schedules", router.accepts(
|
||||
{
|
||||
"text/html": router.index(),
|
||||
"text/plain": router.index(),
|
||||
route.get('/schedule/:period?/:semester?', json(
|
||||
function *(period, semester) {
|
||||
this.type = 'application/json';
|
||||
|
||||
"application/json": function *() {
|
||||
this.type = "application/json";
|
||||
var data = yield db.c("schedules").find({}, {period:1 , semester: 1}).toArray();
|
||||
if(!data) this.status = 404;
|
||||
else this.body = data;
|
||||
let data = yield getSchedule(period, semester);
|
||||
if (!data) {
|
||||
this.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
let doPopulate = this.query.populate || false;
|
||||
if (doPopulate) {
|
||||
data.schedule = yield populateSchedule(data.schedule);
|
||||
}
|
||||
|
||||
this.body = data;
|
||||
}
|
||||
))
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user