dry-wash-pl/stubs/api/index.js

39 lines
938 B
JavaScript
Raw Normal View History

2024-11-03 12:23:47 +03:00
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-require-imports */
2024-10-19 12:07:17 +03:00
const router = require('express').Router();
2024-12-01 12:17:04 +03:00
const STUBS = require('./admin').STUBS;
2024-12-01 11:51:52 +03:00
2024-12-01 12:17:04 +03:00
const commonError = { success: false, message: 'Что-то пошло не так' };
2024-12-07 23:40:22 +03:00
const sleep =
(duration = 1000) =>
2024-12-08 11:00:43 +03:00
(req, res, next) =>
setTimeout(next, duration);
2024-12-01 12:17:04 +03:00
router.use(sleep());
2024-12-01 11:51:52 +03:00
router.get('/arm/masters', (req, res) => {
res
2024-12-01 12:17:04 +03:00
.status(/error/.test(STUBS.masters) ? 500 : 200)
2024-12-01 11:51:52 +03:00
.send(
2024-12-01 12:17:04 +03:00
/^error$/.test(STUBS.masters)
2024-12-01 11:51:52 +03:00
? commonError
2024-12-01 12:17:04 +03:00
: require(`../json/arm-masters/${STUBS.masters}.json`),
2024-12-01 11:51:52 +03:00
);
});
router.get('/arm/orders', (req, res) => {
res
2024-12-01 12:17:04 +03:00
.status(/error/.test(STUBS.orders) ? 500 : 200)
2024-12-01 11:51:52 +03:00
.send(
2024-12-01 12:17:04 +03:00
/^error$/.test(STUBS.orders)
2024-12-01 11:51:52 +03:00
? commonError
2024-12-01 12:17:04 +03:00
: require(`../json/arm-orders/${STUBS.orders}.json`),
2024-12-01 11:51:52 +03:00
);
});
2024-12-01 12:17:04 +03:00
router.use('/admin', require('./admin'));
2024-12-01 11:51:52 +03:00
2024-12-07 23:40:22 +03:00
module.exports = router;