feat: add stub admin (#43)
All checks were successful
it-academy/dry-wash-pl/pipeline/head This commit looks good

This commit is contained in:
Ильназ 2024-12-01 11:51:52 +03:00
parent 6705e74ece
commit 5ef0d5953d

View File

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