Možnost zvolit pouze jednu variantu obědu
This commit is contained in:
@@ -285,6 +285,24 @@ export function removeChoice(login: string, location: Locations, foodIndex: numb
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odstraní kompletně volbu uživatele.
|
||||
*
|
||||
* @param login login uživatele
|
||||
*/
|
||||
function removeChoiceIfPresent(login: string) {
|
||||
const today = formatDate(getToday());
|
||||
let data: ClientData = db.get(today);
|
||||
for (const key of Object.keys(data.choices)) {
|
||||
if (login in data.choices[key]) {
|
||||
delete data.choices[key][login];
|
||||
if (Object.keys(data.choices[key]).length === 0) {
|
||||
delete data.choices[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Přidá volbu uživatele.
|
||||
*
|
||||
@@ -295,6 +313,10 @@ export function removeChoice(login: string, location: Locations, foodIndex: numb
|
||||
*/
|
||||
export function addChoice(login: string, location: Locations, foodIndex?: number) {
|
||||
initIfNeeded();
|
||||
// Pokud měníme pouze lokaci, mažeme případné předchozí
|
||||
if (foodIndex == null) {
|
||||
removeChoiceIfPresent(login);
|
||||
}
|
||||
const today = formatDate(getToday());
|
||||
let data: ClientData = db.get(today);
|
||||
if (!(location in data.choices)) {
|
||||
|
||||
Reference in New Issue
Block a user