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

65 lines
1.8 KiB
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 11:51:52 +03:00
const commonError = { success: false, message: 'Что то пошло не так' };
const stubs = { masters: 'success', orders: 'success' };
router.get('/arm/masters', (req, res) => {
res
.status(/error/.test(stubs.masters) ? 500 : 200)
.send(
/^error$/.test(stubs.masters)
? commonError
: require(`../json/arm-masters/${stubs.masters}.json`),
);
});
router.get('/arm/orders', (req, res) => {
res
.status(/error/.test(stubs.orders) ? 500 : 200)
.send(
/^error$/.test(stubs.orders)
? commonError
: require(`../json/arm-orders/${stubs.orders}.json`),
);
});
router.get('/admin', (req, res) => {
res.send(`<div>
<fieldset >
<legend>Мастера</legend>
<label>
<input ${stubs.masters === 'success' ? 'checked' : ''} onclick="fetch('/api/admin/set/masters/success')" type="radio" name="masters">
success
</label>
<label>
<input ${stubs.masters === 'error' ? 'checked' : ''} onclick="fetch('/api/admin/set/masters/error')" type="radio" name="masters" >
error
</label>
</fieldset>
<fieldset >
<legend>Заказы</legend>
<label>
<input ${stubs.orders === 'success' ? 'checked' : ''} onclick="fetch('/api/admin/set/orders/success')" type="radio" name="orders">
success
</label>
<label>
<input ${stubs.orders === 'error' ? 'checked' : ''} onclick="fetch('/api/admin/set/orders/error')" type="radio" name="orders" >
error
</label>
</fieldset>
</div>`);
});
router.get('/admin/set/:name/:value', (req, res) => {
const { name, value } = req.params;
stubs[name] = value;
res.send('ok');
});
2024-10-19 12:07:17 +03:00
module.exports = router;