const router = require('express').Router() const fs = require('node:fs') const path = require('node:path') const timer = (time = 1000) => (_req, _res, next) => setTimeout(next, time) router.use(timer()) const config = { examCreated: false } router.get('/course/list', (req, res) => { res.send(require('../mocks/courses/list/success.json')) }) 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')) } 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')) }) router.post('/course/toggle-exam-with-jury/:id', (req, res) => { config.examCreated = true; res.send({ success: true }) }) router.get('/lesson/list/:courseId', (req, res) => { res.send(require('../mocks/lessons/list/success.json')) }) 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'), ) // res.send(require('../mocks/lessons/access-code/create/success.json')) res.send(answer) }) router.get('/lesson/access-code/:accessCode', (req, res) => { res.status(400).send(require('../mocks/lessons/access-code/get/error.json')) }) router.get('/lesson/:lessonId', (req, res) => { res.send(require('../mocks/lessons/byid/success.json')) }) router.delete('/lesson/:lessonId', (req, res) => { res.send({ success: true, body: { ok: true }}) }) router.put('/lesson', (req, res) => { res.send({ success: true, body: req.body }) }) module.exports = router