journal.pl/stubs/api/index.js

57 lines
1.5 KiB
JavaScript
Raw Permalink 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 =
(time = 1000) =>
(_req, _res, next) =>
setTimeout(next, time)
router.use(timer())
router.get('/course/list', (req, res) => {
res.send(require('../mocks/courses/list/success.json'))
2024-02-13 21:09:49 +03:00
})
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.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