Možnost označení objednávajícího
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import { getLogin, getTrusted } from "../auth";
|
||||
import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices, updateDepartureTime, updateNote, fetchRestaurantWeekMenuData, saveRestaurantWeekMenu } from "../service";
|
||||
import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices, updateDepartureTime, updateNote, fetchRestaurantWeekMenuData, saveRestaurantWeekMenu, updateBuyer } from "../service";
|
||||
import { getDayOfWeekIndex, parseToken, getFirstWorkDayOfWeek } from "../utils";
|
||||
import { getWebsocket } from "../websocket";
|
||||
import { callNotifikace } from "../notifikace";
|
||||
@@ -182,6 +182,15 @@ router.post("/jdemeObed", async (req, res, next) => {
|
||||
} catch (e: any) { next(e) }
|
||||
});
|
||||
|
||||
router.post("/updateBuyer", async (req, res, next) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
try {
|
||||
const data = await updateBuyer(login);
|
||||
getWebsocket().emit("message", data);
|
||||
res.status(200).json({});
|
||||
} catch (e: any) { next(e) }
|
||||
});
|
||||
|
||||
// /api/food/refresh?type=week&heslo=docasnyheslo
|
||||
export const refreshMetoda = async (req: Request, res: Response) => {
|
||||
const { type, heslo } = req.query as { type?: string; heslo?: string };
|
||||
|
||||
@@ -477,6 +477,24 @@ export async function updateDepartureTime(login: string, time?: string, date?: D
|
||||
return clientData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nastaví/odnastaví uživatele jako objednatele pro dnešní den.
|
||||
* Objednatelů může být více.
|
||||
*
|
||||
* @param login přihlašovací jméno uživatele
|
||||
*/
|
||||
export async function updateBuyer(login: string) {
|
||||
const usedDate = getToday();
|
||||
let clientData = await getClientData(usedDate);
|
||||
const userEntry = clientData.choices?.['OBJEDNAVAM']?.[login];
|
||||
if (!userEntry) {
|
||||
throw new Error("Nelze nastavit objednatele pro uživatele s jinou volbou než \"Budu objednávat\"");
|
||||
}
|
||||
userEntry.isBuyer = !(userEntry.isBuyer || false);
|
||||
await storage.setData(formatDate(usedDate), clientData);
|
||||
return clientData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrátí data pro klienta pro předaný nebo aktuální den.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user