schedule/collective files move to server
This commit is contained in:
1 parent
c1d8ab3b97
commit
1f2b61cc29
6 files changed
+31
-33
No files matched your search
@@ -1,13 +1,11 @@
|
||||
import { connect } from '../../src/core/db'
|
||||
import { findSchedule } from '../../src/server/schedule'
|
||||
import { withMiddleware } from '../../src/middlewares/withMiddleware'
|
||||
|
||||
export default withMiddleware(async (req, res) => {
|
||||
await connect()
|
||||
|
||||
const period = req.query.period
|
||||
const semester = req.query.semester
|
||||
const data = await findSchedule(period, semester)
|
||||
const data = await findSchedule(req.collection, period, semester)
|
||||
|
||||
if (data) {
|
||||
res.json(data)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const React = require('react')
|
||||
const text = require('../core/schedule').text
|
||||
const text = require('../server/schedule').text
|
||||
|
||||
const ScheduleList = ({schedules}) => (
|
||||
<div className="schedule-selector">
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import {c} from '../core/db';
|
||||
|
||||
export async function getCollective(query={}) {
|
||||
return await c('collective')
|
||||
.find(query)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a person by it's id
|
||||
*
|
||||
* @param id
|
||||
* @returns {Promise|*}
|
||||
*/
|
||||
export async function getPerson(id){
|
||||
return await c('collective').findOne({id: id});
|
||||
}
|
||||
@@ -38,9 +38,7 @@ export function getPeriod(i){
|
||||
* @param i
|
||||
* @returns {*}
|
||||
*/
|
||||
function getPeriodString(i) {
|
||||
export function getPeriodString(i) {
|
||||
return getPeriod(i)
|
||||
.join('-')
|
||||
}
|
||||
|
||||
exports.getPeriodString = getPeriodString
|
||||
@@ -0,0 +1,18 @@
|
||||
const { collection } = require('../core/db')
|
||||
// import { collection } from '../core/db'
|
||||
|
||||
export async function getCollective(query = {}) {
|
||||
return await collection('collective')
|
||||
.find(query)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a person by it's id
|
||||
*
|
||||
* @param id
|
||||
* @returns {Promise|*}
|
||||
*/
|
||||
export async function getPerson(id) {
|
||||
return await collection('collective').findOne({ id: id });
|
||||
}
|
||||
+10
-9
@@ -1,6 +1,7 @@
|
||||
import {c} from '../core/db'
|
||||
// import {collection} from '../core/db'
|
||||
// const {collection} = require('../core/db')
|
||||
import {createMap} from '../utils/common'
|
||||
import {getCollective} from '../core/collective'
|
||||
import {getCollective} from './collective'
|
||||
|
||||
import {scheduleDate, getPeriod as schedulePeriod, getPeriodString} from '../models/schedule'
|
||||
import {getCourse} from '../models/course'
|
||||
@@ -10,8 +11,8 @@ const sortBy = require('../lib/sort').sortBy
|
||||
|
||||
const SCHEDULES = 'schedules'
|
||||
|
||||
async function findSchedule(period, semester) {
|
||||
const schedule = await c(SCHEDULES).findOne({
|
||||
export async function findSchedule(collection, period, semester) {
|
||||
const schedule = await collection(SCHEDULES).findOne({
|
||||
$or: [
|
||||
{period: period},
|
||||
{period: schedulePeriod(period)}
|
||||
@@ -23,7 +24,7 @@ async function findSchedule(period, semester) {
|
||||
}
|
||||
|
||||
async function findAllScheduleParams() {
|
||||
const schedules = await c(SCHEDULES)
|
||||
const schedules = await collection(SCHEDULES)
|
||||
.find({}, {
|
||||
period: 1,
|
||||
semester: 1,
|
||||
@@ -142,7 +143,7 @@ async function migrate20to30(schedule) {
|
||||
})
|
||||
}
|
||||
|
||||
exports.findSchedule = findSchedule
|
||||
exports.findAllScheduleParams = findAllScheduleParams
|
||||
exports.findDefaultScheduleParams = findDefaultScheduleParams
|
||||
exports.text = text
|
||||
// exports.findSchedule = findSchedule
|
||||
// exports.findAllScheduleParams = findAllScheduleParams
|
||||
// exports.findDefaultScheduleParams = findDefaultScheduleParams
|
||||
// exports.text = text
|
||||
Reference in new issue
Block a user