feat: možnost editace existujících podniků u objednávání
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import express from "express";
|
||||
import { getStores, addStore, removeStore } from "../stores";
|
||||
import { getStores, addStore, updateStore, removeStore } from "../stores";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -32,6 +32,31 @@ router.post("/add", async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/update", async (req, res, next) => {
|
||||
const { name, newName, heslo, urls } = req.body ?? {};
|
||||
if (!name || typeof name !== 'string') {
|
||||
return res.status(400).json({ error: 'Nebyl předán název obchodu' });
|
||||
}
|
||||
if (!heslo || typeof heslo !== 'string') {
|
||||
return res.status(400).json({ error: 'Nebylo předáno heslo' });
|
||||
}
|
||||
if (newName != null && typeof newName !== 'string') {
|
||||
return res.status(400).json({ error: 'Neplatný název obchodu' });
|
||||
}
|
||||
if (urls != null && (!Array.isArray(urls) || urls.some((u: unknown) => typeof u !== 'string'))) {
|
||||
return res.status(400).json({ error: 'Neplatný seznam URL obchodu' });
|
||||
}
|
||||
try {
|
||||
const stores = await updateStore(name, heslo, newName ?? undefined, urls ?? undefined);
|
||||
res.status(200).json(stores);
|
||||
} catch (e: any) {
|
||||
if (e.message === 'UNAUTHORIZED') {
|
||||
return res.status(403).json({ error: 'Nesprávné heslo' });
|
||||
}
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/delete", async (req, res, next) => {
|
||||
const { name, heslo } = req.body ?? {};
|
||||
if (!name || typeof name !== 'string') {
|
||||
|
||||
Reference in New Issue
Block a user