feature/successJson #45

Merged
primakov merged 4 commits from feature/successJson into main 2024-12-08 11:18:36 +03:00
Showing only changes of commit 5ef0d5953d - Show all commits

View File

@ -2,4 +2,63 @@
/* eslint-disable @typescript-eslint/no-require-imports */
const router = require('express').Router();
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');
});
module.exports = router;