NOMERGE: Přenos změn
This commit is contained in:
@@ -239,34 +239,75 @@ export function initIfNeeded() {
|
||||
}
|
||||
}
|
||||
|
||||
export function removeChoice(login: string, data: ClientData) {
|
||||
for (let key of Object.keys(data.choices)) {
|
||||
if (data.choices[key] && data.choices[key].includes(login)) {
|
||||
const index = data.choices[key].indexOf(login);
|
||||
data.choices[key].splice(index, 1);
|
||||
if (data.choices[key].length == 0) {
|
||||
delete data.choices[key];
|
||||
/**
|
||||
* Odstraní kompletně volbu uživatele (včetně případných podřízených jídel).
|
||||
*
|
||||
* @param login login uživatele
|
||||
* @param location vybrané "umístění"
|
||||
* @returns
|
||||
*/
|
||||
export function removeChoices(login: string, location: Locations) {
|
||||
const today = formatDate(getToday());
|
||||
let data: ClientData = db.get(today);
|
||||
if (location in data.choices) {
|
||||
if (login in data.choices[location]) {
|
||||
delete data.choices[location][login]
|
||||
if (Object.keys(data.choices[location]).length === 0) {
|
||||
delete data.choices[location]
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export function updateChoice(login: string, choice: Locations | null) {
|
||||
/**
|
||||
* Odstraní konkrétní volbu jídla uživatele.
|
||||
* Neodstraňuje volbu samotnou, k tomu slouží {@link removeChoices}.
|
||||
*
|
||||
* @param login login uživatele
|
||||
* @param location vybrané "umístění"
|
||||
* @param foodIndex index jídla v jídelním lístku daného umístění, pokud existuje
|
||||
* @returns
|
||||
*/
|
||||
export function removeChoice(login: string, location: Locations, foodIndex: number) {
|
||||
const today = formatDate(getToday());
|
||||
let data: ClientData = db.get(today);
|
||||
if (location in data.choices) {
|
||||
if (login in data.choices[location]) {
|
||||
if (data.choices[location][login].includes(foodIndex)) {
|
||||
data.choices[location][login].splice(foodIndex, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Přidá volbu uživatele.
|
||||
*
|
||||
* @param login login uživatele
|
||||
* @param location vybrané "umístění"
|
||||
* @param foodIndex volitelný index jídla v daném umístění
|
||||
* @returns aktuální data
|
||||
*/
|
||||
export function addChoice(login: string, location: Locations, foodIndex?: number) {
|
||||
initIfNeeded();
|
||||
const today = formatDate(getToday());
|
||||
let data: ClientData = db.get(today);
|
||||
data = removeChoice(login, data);
|
||||
if (choice !== null) {
|
||||
if (!data.choices?.[choice]) {
|
||||
data.choices[choice] = [];
|
||||
}
|
||||
data.choices[choice].push(login);
|
||||
if (!(location in data.choices)) {
|
||||
data.choices[location] = {};
|
||||
}
|
||||
if (!(login in data.choices[location])) {
|
||||
data.choices[location][login] = [];
|
||||
}
|
||||
if (foodIndex != null && !data.choices[location][login].includes(foodIndex)) {
|
||||
data.choices[location][login].push(foodIndex);
|
||||
}
|
||||
db.set(today, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
// TODO přejmenovat, ať je jasné že to patří k pizza day
|
||||
export function updateNote(login: string, note?: string) {
|
||||
const today = formatDate(getToday());
|
||||
let clientData: ClientData = db.get(today);
|
||||
|
||||
Reference in New Issue
Block a user