Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Replace implementation of upcoming-exams endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Abad committed May 8, 2021
1 parent 5bd4306 commit 5a6724d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 88 deletions.
17 changes: 1 addition & 16 deletions src/controllers/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Router } from 'express'
import Course, { CourseDocument } from '@/models/course'
import Exam from '@/models/exam'
import User from '@/models/user'
import helper from '@/utils/helper'
import ExamAttempt from '@/models/exam-attempt'

const coursesRouter = Router()
Expand Down Expand Up @@ -156,7 +155,7 @@ coursesRouter.get('/:course/exams/week/:week', async (req, res) => {
res.json(exams)
})

coursesRouter.get('/v2/:id/upcoming-exams', async (req, res) => {
coursesRouter.get('/:id/upcoming-exams', async (req, res) => {
const exams = await Exam.find({
course: req.params.id,
startDate: {
Expand All @@ -167,20 +166,6 @@ coursesRouter.get('/v2/:id/upcoming-exams', async (req, res) => {
res.json(exams)
})

coursesRouter.get('/:id/upcoming-exams', async (req, res) => {
const course = await Course.findById(req.params.id)

if (!course) {
res.status(404).end()
return
}

const exams = await Exam.find({ _id: { $in: course.exams } })
const events = await helper.getEvents(exams)

res.json(events)
})

coursesRouter.put('/:courseId', async (req, res) => {
const body = req.body
const course = await Course.findById(req.params.courseId)
Expand Down
21 changes: 1 addition & 20 deletions src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ExamAttempt from '@/models/exam-attempt'
import Exam from '@/models/exam'
import Course from '@/models/course'
import { Event } from '@/types'
import helper from '@/utils/helper'
import config from '@/utils/config'

const usersRouter = Router()
Expand Down Expand Up @@ -148,7 +147,7 @@ usersRouter.delete('/:id', async (req, res) => {
res.status(204).end()
})

usersRouter.get('/v2/:id/upcoming-exams', async (req, res) => {
usersRouter.get('/:id/upcoming-exams', async (req, res) => {
const user = await User.findById(req.params.id)

if (!user) {
Expand Down Expand Up @@ -191,24 +190,6 @@ usersRouter.get('/:id/open-exams', async (req, res) => {
res.json(exams)
})

/**
* @deprecated Use /v2/:id/upcoming-exams instead
*/
usersRouter.get('/:id/upcoming-exams', async (req, res) => {
const user = await User.findById(req.params.id)

if (!user) {
res.status(404).end()
return
}

const exams = await Exam.find({ course: { $in: user.courses } })

const events = await helper.getEvents(exams)

res.json(events)
})

usersRouter.get('/:id/recent-activity', async (req, res) => {
const user = await User.findById(req.params.id)

Expand Down
52 changes: 0 additions & 52 deletions src/utils/helper.ts

This file was deleted.

0 comments on commit 5a6724d

Please sign in to comment.