diff --git a/stubs/api/admin.js b/stubs/api/admin.js new file mode 100644 index 0000000..e8c5a07 --- /dev/null +++ b/stubs/api/admin.js @@ -0,0 +1,38 @@ +/* eslint-disable no-undef */ +/* eslint-disable @typescript-eslint/no-require-imports */ +const router = require('express').Router(); + +const STUBS = { masters: 'success', orders: 'success' }; + +router.get('/set/:name/:value', (req, res) => { + const { name, value } = req.params; + + STUBS[name] = value; + + res.send('ok'); +}); + +router.get('/', (req, res) => { + res.send(`
+
+ Мастера + ${generateRadioInput('masters', 'success')} + ${generateRadioInput('masters', 'error')} +
+
+ Заказы + ${generateRadioInput('orders', 'success')} + ${generateRadioInput('orders', 'error')} +
+
`); +}); + +module.exports = router; +module.exports.STUBS = STUBS; + +function generateRadioInput(name, type) { + return ``; +} \ No newline at end of file diff --git a/stubs/api/index.js b/stubs/api/index.js index 6a7dc94..22ac104 100644 --- a/stubs/api/index.js +++ b/stubs/api/index.js @@ -2,63 +2,34 @@ /* eslint-disable @typescript-eslint/no-require-imports */ const router = require('express').Router(); -const commonError = { success: false, message: 'Что то пошло не так' }; +const STUBS = require('./admin').STUBS; -const stubs = { masters: 'success', orders: 'success' }; +const commonError = { success: false, message: 'Что-то пошло не так' }; + +const sleep = (duration = 300) => (req, res, next) => setTimeout(next, duration); + +router.use(sleep()); router.get('/arm/masters', (req, res) => { res - .status(/error/.test(stubs.masters) ? 500 : 200) + .status(/error/.test(STUBS.masters) ? 500 : 200) .send( - /^error$/.test(stubs.masters) + /^error$/.test(STUBS.masters) ? commonError - : require(`../json/arm-masters/${stubs.masters}.json`), + : require(`../json/arm-masters/${STUBS.masters}.json`), ); }); router.get('/arm/orders', (req, res) => { res - .status(/error/.test(stubs.orders) ? 500 : 200) + .status(/error/.test(STUBS.orders) ? 500 : 200) .send( - /^error$/.test(stubs.orders) + /^error$/.test(STUBS.orders) ? commonError - : require(`../json/arm-orders/${stubs.orders}.json`), + : require(`../json/arm-orders/${STUBS.orders}.json`), ); }); -router.get('/admin', (req, res) => { - res.send(`
-
- Мастера - - -
-
- Заказы - - -
-
`); -}); +router.use('/admin', require('./admin')); -router.get('/admin/set/:name/:value', (req, res) => { - const { name, value } = req.params; - - stubs[name] = value; - - res.send('ok'); -}); - -module.exports = router; +module.exports = router; \ No newline at end of file