dodelej me z pc
This commit is contained in:
@@ -69,11 +69,20 @@ const parseValidateFutureDayIndex = (req: Request<{}, any, AddChoiceData["body"]
|
||||
return dayIndex;
|
||||
}
|
||||
|
||||
const parseSlot = (body: Record<string, any>): string | undefined => {
|
||||
const slot = body?.slot;
|
||||
if (slot != null && slot !== 'obed' && slot !== 'extra') {
|
||||
throw Error(`Neplatný slot: ${slot}`);
|
||||
}
|
||||
return slot ?? undefined;
|
||||
};
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post("/addChoice", async (req: Request<{}, any, AddChoiceData["body"]>, res, next) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const trusted = getTrusted(parseToken(req));
|
||||
const slot = parseSlot(req.body);
|
||||
let date = undefined;
|
||||
if (req.body.dayIndex != null) {
|
||||
let dayIndex;
|
||||
@@ -85,7 +94,7 @@ router.post("/addChoice", async (req: Request<{}, any, AddChoiceData["body"]>, r
|
||||
date = getDateForWeekIndex(dayIndex);
|
||||
}
|
||||
try {
|
||||
const data = await addChoice(login, trusted, req.body.locationKey, req.body.foodIndex, date);
|
||||
const data = await addChoice(login, trusted, req.body.locationKey, req.body.foodIndex, date, slot);
|
||||
getWebsocket().emit("message", data);
|
||||
return res.status(200).json(data);
|
||||
} catch (e: any) { next(e) }
|
||||
@@ -94,6 +103,7 @@ router.post("/addChoice", async (req: Request<{}, any, AddChoiceData["body"]>, r
|
||||
router.post("/removeChoices", async (req: Request<{}, any, RemoveChoicesData["body"]>, res, next) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const trusted = getTrusted(parseToken(req));
|
||||
const slot = parseSlot(req.body);
|
||||
let date = undefined;
|
||||
if (req.body.dayIndex != null) {
|
||||
let dayIndex;
|
||||
@@ -105,7 +115,7 @@ router.post("/removeChoices", async (req: Request<{}, any, RemoveChoicesData["bo
|
||||
date = getDateForWeekIndex(dayIndex);
|
||||
}
|
||||
try {
|
||||
const data = await removeChoices(login, trusted, req.body.locationKey, date);
|
||||
const data = await removeChoices(login, trusted, req.body.locationKey, date, slot);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json(data);
|
||||
} catch (e: any) { next(e) }
|
||||
@@ -114,6 +124,7 @@ router.post("/removeChoices", async (req: Request<{}, any, RemoveChoicesData["bo
|
||||
router.post("/removeChoice", async (req: Request<{}, any, RemoveChoiceData["body"]>, res, next) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const trusted = getTrusted(parseToken(req));
|
||||
const slot = parseSlot(req.body);
|
||||
let date = undefined;
|
||||
if (req.body.dayIndex != null) {
|
||||
let dayIndex;
|
||||
@@ -125,7 +136,7 @@ router.post("/removeChoice", async (req: Request<{}, any, RemoveChoiceData["body
|
||||
date = getDateForWeekIndex(dayIndex);
|
||||
}
|
||||
try {
|
||||
const data = await removeChoice(login, trusted, req.body.locationKey, req.body.foodIndex, date);
|
||||
const data = await removeChoice(login, trusted, req.body.locationKey, req.body.foodIndex, date, slot);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json(data);
|
||||
} catch (e: any) { next(e) }
|
||||
@@ -135,6 +146,7 @@ router.post("/updateNote", async (req: Request<{}, any, UpdateNoteData["body"]>,
|
||||
const login = getLogin(parseToken(req));
|
||||
const trusted = getTrusted(parseToken(req));
|
||||
const note = req.body.note;
|
||||
const slot = parseSlot(req.body);
|
||||
try {
|
||||
if (note && note.length > 70) {
|
||||
throw Error("Poznámka může mít maximálně 70 znaků");
|
||||
@@ -149,7 +161,7 @@ router.post("/updateNote", async (req: Request<{}, any, UpdateNoteData["body"]>,
|
||||
}
|
||||
date = getDateForWeekIndex(dayIndex);
|
||||
}
|
||||
const data = await updateNote(login, trusted, note, date);
|
||||
const data = await updateNote(login, trusted, note, date, slot);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json(data);
|
||||
} catch (e: any) { next(e) }
|
||||
@@ -184,8 +196,9 @@ router.post("/jdemeObed", async (req, res, next) => {
|
||||
|
||||
router.post("/updateBuyer", async (req, res, next) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const slot = parseSlot(req.body ?? {});
|
||||
try {
|
||||
const data = await updateBuyer(login);
|
||||
const data = await updateBuyer(login, slot);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json({});
|
||||
} catch (e: any) { next(e) }
|
||||
|
||||
Reference in New Issue
Block a user