journal.pl/stubs/api/index.js

77 lines
2.0 KiB
JavaScript
Raw Normal View History

2024-03-01 11:43:31 +03:00
const router = require('express').Router()
const fs = require('node:fs')
const path = require('node:path')
2022-11-27 16:34:37 +03:00
const timer =
2024-08-29 08:10:03 +03:00
(time = 1000) =>
(_req, _res, next) =>
setTimeout(next, time)
router.use(timer())
2024-08-29 09:55:05 +03:00
const config = {
examCreated: false
}
router.get('/course/list', (req, res) => {
res.send(require('../mocks/courses/list/success.json'))
2024-02-13 21:09:49 +03:00
})
2024-08-29 09:55:05 +03:00
router.get('/course/:id', (req, res) => {
if(req.params.id === 'undefined')
return res.status(400).send({ success: false, error: 'Invalid course id' })
if (config.examCreated) {
config.examCreated = false
return res.send(require('../mocks/courses/by-id/with-exam.json'))
}
2024-08-29 08:10:03 +03:00
res.send(require('../mocks/courses/by-id/success.json'))
})
router.get('/course/students/:courseId', (req, res) => {
res.send(require('../mocks/courses/all-students/success.json'))
})
router.post('/course', (req, res) => {
res.send(require('../mocks/courses/create/success.json'))
})
2024-08-29 08:10:03 +03:00
router.post('/course/toggle-exam-with-jury/:id', (req, res) => {
2024-08-29 09:55:05 +03:00
config.examCreated = true;
2024-08-29 08:10:03 +03:00
res.send({ success: true })
})
router.get('/lesson/list/:courseId', (req, res) => {
2024-02-28 23:43:36 +03:00
res.send(require('../mocks/lessons/list/success.json'))
})
2024-03-01 11:43:31 +03:00
router.post('/lesson', (req, res) => {
res.send(require('../mocks/lessons/create/success.json'))
})
router.post('/lesson/access-code', (req, res) => {
const answer = fs.readFileSync(
path.resolve(__dirname, '../mocks/lessons/access-code/create/success.json'),
)
2024-03-01 11:43:31 +03:00
// res.send(require('../mocks/lessons/access-code/create/success.json'))
res.send(answer)
})
router.get('/lesson/access-code/:accessCode', (req, res) => {
2024-03-01 12:16:13 +03:00
res.status(400).send(require('../mocks/lessons/access-code/get/error.json'))
2024-03-01 11:43:31 +03:00
})
2024-03-01 12:16:13 +03:00
router.get('/lesson/:lessonId', (req, res) => {
2024-03-01 11:43:31 +03:00
res.send(require('../mocks/lessons/byid/success.json'))
})
router.delete('/lesson/:lessonId', (req, res) => {
res.send({ success: true, body: { ok: true }})
})
2024-04-02 16:27:22 +03:00
router.put('/lesson', (req, res) => {
res.send({ success: true, body: req.body })
})
2024-03-01 11:43:31 +03:00
module.exports = router