Added correct definitions file

This commit is contained in:
Ferdinand Thiessen 2021-03-18 13:08:43 +01:00
parent 20191be5dc
commit caa09a3c2c
5 changed files with 103 additions and 100 deletions

View File

@ -15,7 +15,7 @@ declare namespace FG {
mail: string; mail: string;
birthday?: Date; birthday?: Date;
roles: Array<string>; roles: Array<string>;
permissions?: string[]; permissions?: Array<string>;
avatar_url?: string; avatar_url?: string;
} }
type Permission = string; type Permission = string;
@ -29,9 +29,9 @@ declare namespace FG {
time: Date; time: Date;
amount: number; amount: number;
reversal_id: number; reversal_id: number;
sender_id?: number; sender_id?: string;
receiver_id?: number; receiver_id?: string;
author_id?: number; author_id?: string;
original_id?: number; original_id?: number;
} }
interface Drink { interface Drink {
@ -43,32 +43,26 @@ declare namespace FG {
cost_price_pro_volume?: number; cost_price_pro_volume?: number;
cost_price_package_netto?: number; cost_price_package_netto?: number;
tags: Array<Tag>; tags: Array<Tag>;
type?: DrinkType; type: DrinkType;
volumes: DrinkPriceVolume[]; volumes: Array<DrinkPriceVolume>;
} }
interface DrinkIngredient { interface DrinkIngredient {
id: number; id: number;
volume: number; volume: number;
drink_ingredient?: Drink; drink_ingredient_id: number;
price: number;
} }
interface DrinkPrice { interface DrinkPrice {
id: number; id: number;
price: number; price: number;
public: boolean; public: bool;
description?: string; description?: string;
} }
interface DrinkMinPrice {
percentage: number;
//price: ComputedRef<number>;
price: number;
}
interface DrinkPriceVolume { interface DrinkPriceVolume {
id: number; id: number;
volume: number; volume: number;
//computed_volume: ComputedRef<number>; ingredients: Array<DrinkIngredient | ExtraIngredient>;
min_prices: DrinkMinPrice[];
prices: Array<DrinkPrice>; prices: Array<DrinkPrice>;
ingredients: Array<Ingredient>;
} }
interface DrinkType { interface DrinkType {
id: number; id: number;
@ -81,8 +75,9 @@ declare namespace FG {
} }
interface Ingredient { interface Ingredient {
id: number; id: number;
drink_ingredient: DrinkIngredient | null; volume_id: number;
extra_ingredient: ExtraIngredient | null; drink_ingredient: DrinkIngredient;
extra_ingredient: ExtraIngredient;
} }
interface Tag { interface Tag {
id: number; id: number;

View File

@ -11,7 +11,7 @@ const plugin: FG_Plugin.Plugin = {
requiredBackendModules: ['pricelist'], requiredBackendModules: ['pricelist'],
version: '0.0.1', version: '0.0.1',
store: new Map<string, Module<DrinkInterface, StateInterface>>([['drink', drink]]), store: new Map<string, Module<DrinkInterface, StateInterface>>([['drink', drink]]),
widgets: [] widgets: [],
// widgets: [ // widgets: [
// { // {
// priority: 1, // priority: 1,

View File

@ -15,7 +15,7 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [
name: 'drinks-pricelist', name: 'drinks-pricelist',
shortcut: true, shortcut: true,
meta: { permissions: ['user'] }, meta: { permissions: ['user'] },
component: () => import('../pages/Pricelist.vue') component: () => import('../pages/Pricelist.vue'),
}, },
{ {
title: 'Einstellungen', title: 'Einstellungen',
@ -24,10 +24,10 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [
name: 'drinks-settings', name: 'drinks-settings',
shortcut: false, shortcut: false,
meta: { permissions: ['users_edit_other'] }, meta: { permissions: ['users_edit_other'] },
component: () => import('../pages/Settings.vue') component: () => import('../pages/Settings.vue'),
} },
] ],
} },
]; ];
export default mainRoutes; export default mainRoutes;

View File

@ -11,7 +11,7 @@ const state = reactive<{
drinks: [], drinks: [],
tags: [], tags: [],
drinkTypes: [], drinkTypes: [],
extraIngredients: [] extraIngredients: [],
}); });
interface MinPrice extends Omit<FG.DrinkMinPrice, 'price'> { interface MinPrice extends Omit<FG.DrinkMinPrice, 'price'> {
@ -37,22 +37,22 @@ class DrinkPriceVolume {
this.min_prices = [ this.min_prices = [
{ {
percentage: 100, percentage: 100,
price: create_min_prices(drink, this, 100) price: create_min_prices(drink, this, 100),
}, },
{ {
percentage: 250, percentage: 250,
price: create_min_prices(drink, this, 250) price: create_min_prices(drink, this, 250),
}, },
{ {
percentage: 300, percentage: 300,
price: create_min_prices(drink, this, 300) price: create_min_prices(drink, this, 300),
} },
]; ];
this.volume = computed<number>({ this.volume = computed<number>({
get: () => { get: () => {
if (this.ingredients.some(ingredient => !!ingredient.drink_ingredient)) { if (this.ingredients.some((ingredient) => !!ingredient.drink_ingredient)) {
let retVal = 0; let retVal = 0;
this.ingredients.forEach(ingredient => { this.ingredients.forEach((ingredient) => {
if (ingredient.drink_ingredient?.volume) { if (ingredient.drink_ingredient?.volume) {
retVal += ingredient.drink_ingredient.volume; retVal += ingredient.drink_ingredient.volume;
} }
@ -63,7 +63,7 @@ class DrinkPriceVolume {
return this._volume; return this._volume;
} }
}, },
set: val => (this._volume = val) set: (val) => (this._volume = val),
}); });
} }
} }
@ -79,7 +79,7 @@ class Drink {
cost_price_package_netto, cost_price_package_netto,
tags, tags,
type, type,
volumes volumes,
}: FG.Drink) { }: FG.Drink) {
this.id = id; this.id = id;
this.article_id = article_id; this.article_id = article_id;
@ -100,7 +100,7 @@ class Drink {
return this._cost_price_pro_volume; return this._cost_price_pro_volume;
}, },
set: val => (this._cost_price_pro_volume = val) set: (val) => (this._cost_price_pro_volume = val),
}); });
this.tags = tags; this.tags = tags;
this.type = type; this.type = type;
@ -117,17 +117,17 @@ const actions = {
.get('pricelist/drinks') .get('pricelist/drinks')
.then((response: AxiosResponse<FG.Drink[]>) => { .then((response: AxiosResponse<FG.Drink[]>) => {
state.drinks = []; state.drinks = [];
response.data.forEach(drink => { response.data.forEach((drink) => {
state.drinks.push(new Drink(drink)); state.drinks.push(new Drink(drink));
}); });
state.drinks.forEach(drink => { state.drinks.forEach((drink) => {
const _drink = response.data.find(a => a.id === drink.id); const _drink = response.data.find((a) => a.id === drink.id);
_drink?.volumes.forEach(volume => { _drink?.volumes.forEach((volume) => {
drink.volumes.push(new DrinkPriceVolume(volume, drink)); drink.volumes.push(new DrinkPriceVolume(volume, drink));
}); });
}); });
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
setPrice(price: FG.DrinkPrice, volume: DrinkPriceVolume) { setPrice(price: FG.DrinkPrice, volume: DrinkPriceVolume) {
axios axios
@ -136,7 +136,7 @@ const actions = {
volume.prices.push(response.data); volume.prices.push(response.data);
this.sortPrices(volume); this.sortPrices(volume);
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
sortPrices(volume: DrinkPriceVolume) { sortPrices(volume: DrinkPriceVolume) {
volume.prices.sort((a, b) => { volume.prices.sort((a, b) => {
@ -149,48 +149,54 @@ const actions = {
axios axios
.delete(`pricelist/prices/${price.id}`) .delete(`pricelist/prices/${price.id}`)
.then(() => { .then(() => {
const index = volume.prices.findIndex(a => a.id == price.id); const index = volume.prices.findIndex((a) => a.id == price.id);
if (index > -1) { if (index > -1) {
volume.prices.splice(index, 1); volume.prices.splice(index, 1);
} }
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
updatePrice(price: FG.DrinkPrice, volume: DrinkPriceVolume) { updatePrice(price: FG.DrinkPrice, volume: DrinkPriceVolume) {
axios axios
.put(`pricelist/prices/${price.id}`, price) .put(`pricelist/prices/${price.id}`, price)
.then((response: AxiosResponse<FG.DrinkPrice>) => { .then((response: AxiosResponse<FG.DrinkPrice>) => {
const index = volume.prices.findIndex(a => a.id === price.id); const index = volume.prices.findIndex((a) => a.id === price.id);
if (index > -1) { if (index > -1) {
this.sortPrices(volume); this.sortPrices(volume);
} }
}) })
.catch(err => console.log(err)); .catch((err) => console.log(err));
}, },
setVolume(volume: DrinkPriceVolume, drink: Drink) { setVolume(volume: DrinkPriceVolume, drink: Drink) {
console.log(volume); console.log(volume);
axios axios
.post(`pricelist/drinks/${drink.id}/volumes`, { ...volume, volume: volume.volume }) .post(`pricelist/drinks/${drink.id}/volumes`, {
...volume,
volume: volume.volume,
})
.then((response: AxiosResponse<FG.DrinkPriceVolume>) => { .then((response: AxiosResponse<FG.DrinkPriceVolume>) => {
drink.volumes.push(new DrinkPriceVolume(response.data, drink)); drink.volumes.push(new DrinkPriceVolume(response.data, drink));
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
updateVolume(volume: DrinkPriceVolume, drink: Drink) { updateVolume(volume: DrinkPriceVolume, drink: Drink) {
axios axios
.put(`pricelist/volumes/${volume.id}`, { ...volume, volume: volume.volume?.value }) .put(`pricelist/volumes/${volume.id}`, {
.catch(err => console.warn(err)); ...volume,
volume: volume.volume?.value,
})
.catch((err) => console.warn(err));
}, },
deleteVolume(volume: FG.DrinkPriceVolume, drink: FG.Drink) { deleteVolume(volume: FG.DrinkPriceVolume, drink: FG.Drink) {
axios axios
.delete(`pricelist/volumes/${volume.id}`) .delete(`pricelist/volumes/${volume.id}`)
.then(() => { .then(() => {
const index = drink.volumes.findIndex(a => a.id === volume.id); const index = drink.volumes.findIndex((a) => a.id === volume.id);
if (index > -1) { if (index > -1) {
drink.volumes.splice(index, 1); drink.volumes.splice(index, 1);
} }
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
getExtraIngredients() { getExtraIngredients() {
axios axios
@ -198,7 +204,7 @@ const actions = {
.then((response: AxiosResponse<FG.ExtraIngredient[]>) => { .then((response: AxiosResponse<FG.ExtraIngredient[]>) => {
state.extraIngredients = response.data; state.extraIngredients = response.data;
}) })
.catch(err => console.log(err)); .catch((err) => console.log(err));
}, },
setIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) { setIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
axios axios
@ -206,29 +212,29 @@ const actions = {
.then((response: AxiosResponse<FG.Ingredient>) => { .then((response: AxiosResponse<FG.Ingredient>) => {
volume.ingredients.push(response.data); volume.ingredients.push(response.data);
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
updateIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) { updateIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
axios axios
.put(`pricelist/ingredients/${ingredient.id}`, ingredient) .put(`pricelist/ingredients/${ingredient.id}`, ingredient)
.then((response: AxiosResponse<FG.Ingredient>) => { .then((response: AxiosResponse<FG.Ingredient>) => {
const index = volume.ingredients.findIndex(a => a.id === response.data.id); const index = volume.ingredients.findIndex((a) => a.id === response.data.id);
if (index > -1) { if (index > -1) {
volume.ingredients[index] = response.data; volume.ingredients[index] = response.data;
} }
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
deleteIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) { deleteIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
axios axios
.delete(`pricelist/ingredients/${ingredient.id}`) .delete(`pricelist/ingredients/${ingredient.id}`)
.then(() => { .then(() => {
const index = volume.ingredients.findIndex(a => a.id === ingredient.id); const index = volume.ingredients.findIndex((a) => a.id === ingredient.id);
if (index > -1) { if (index > -1) {
volume.ingredients.splice(index, 1); volume.ingredients.splice(index, 1);
} }
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
getDrinkTypes() { getDrinkTypes() {
axios axios
@ -236,38 +242,38 @@ const actions = {
.then((response: AxiosResponse<FG.DrinkType[]>) => { .then((response: AxiosResponse<FG.DrinkType[]>) => {
state.drinkTypes = response.data; state.drinkTypes = response.data;
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
setDrink(drink: FG.Drink) { setDrink(drink: FG.Drink) {
axios axios
.post('pricelist/drinks', drink) .post('pricelist/drinks', drink)
.then((response: AxiosResponse<FG.Drink>) => { .then((response: AxiosResponse<FG.Drink>) => {
state.drinks.push(new Drink(response.data)); state.drinks.push(new Drink(response.data));
const drink = state.drinks.find(a => a.id === response.data.id); const drink = state.drinks.find((a) => a.id === response.data.id);
response.data.volumes.forEach(volume => { response.data.volumes.forEach((volume) => {
drink?.volumes.push(new DrinkPriceVolume(volume, drink)); drink?.volumes.push(new DrinkPriceVolume(volume, drink));
}); });
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
updateDrink(drink: Drink) { updateDrink(drink: Drink) {
axios axios
.put(`pricelist/drinks/${drink.id}`, { .put(`pricelist/drinks/${drink.id}`, {
...drink, ...drink,
cost_price_pro_volume: drink.cost_price_pro_volume?.value cost_price_pro_volume: drink.cost_price_pro_volume?.value,
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
deleteDrink(drink: Drink) { deleteDrink(drink: Drink) {
axios axios
.delete(`pricelist/drinks/${drink.id}`) .delete(`pricelist/drinks/${drink.id}`)
.then(() => { .then(() => {
const index = state.drinks.findIndex(a => a.id === drink.id); const index = state.drinks.findIndex((a) => a.id === drink.id);
if (index > -1) { if (index > -1) {
state.drinks.splice(index, 1); state.drinks.splice(index, 1);
} }
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
setExtraIngredient(ingredient: FG.ExtraIngredient) { setExtraIngredient(ingredient: FG.ExtraIngredient) {
axios axios
@ -275,42 +281,42 @@ const actions = {
.then((response: AxiosResponse<FG.ExtraIngredient>) => { .then((response: AxiosResponse<FG.ExtraIngredient>) => {
state.extraIngredients.push(response.data); state.extraIngredients.push(response.data);
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
updateExtraIngredient(ingredient: FG.ExtraIngredient) { updateExtraIngredient(ingredient: FG.ExtraIngredient) {
axios axios
.put(`pricelist/ingredients/extraIngredients/${ingredient.id}`, ingredient) .put(`pricelist/ingredients/extraIngredients/${ingredient.id}`, ingredient)
.then((response: AxiosResponse<FG.ExtraIngredient>) => { .then((response: AxiosResponse<FG.ExtraIngredient>) => {
const index = state.extraIngredients.findIndex(a => a.id === ingredient.id); const index = state.extraIngredients.findIndex((a) => a.id === ingredient.id);
if (index > -1) { if (index > -1) {
state.extraIngredients[index] = response.data; state.extraIngredients[index] = response.data;
} else { } else {
state.extraIngredients.push(response.data); state.extraIngredients.push(response.data);
} }
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
deleteExtraIngredient(ingredient: FG.ExtraIngredient) { deleteExtraIngredient(ingredient: FG.ExtraIngredient) {
axios axios
.delete(`pricelist/ingredients/extraIngredients/${ingredient.id}`) .delete(`pricelist/ingredients/extraIngredients/${ingredient.id}`)
.then(() => { .then(() => {
const index = state.extraIngredients.findIndex(a => a.id === ingredient.id); const index = state.extraIngredients.findIndex((a) => a.id === ingredient.id);
if (index > -1) { if (index > -1) {
state.extraIngredients.splice(index, 1); state.extraIngredients.splice(index, 1);
} }
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
} },
}; };
const getters = {}; const getters = {};
function create_min_prices(drink: Drink, volume: DrinkPriceVolume, percentage: number) { function create_min_prices(drink: Drink, volume: DrinkPriceVolume, percentage: number) {
if (drink.cost_price_pro_volume?.value) { if (drink.cost_price_pro_volume?.value) {
if (volume.ingredients.every(ingredient => !!ingredient.drink_ingredient)) { if (volume.ingredients.every((ingredient) => !!ingredient.drink_ingredient)) {
return computed<number>(() => { return computed<number>(() => {
let retVal = (drink.cost_price_pro_volume?.value || 0) * (volume.volume?.value || 0); let retVal = (drink.cost_price_pro_volume?.value || 0) * (volume.volume?.value || 0);
volume.ingredients.forEach(ingredient => { volume.ingredients.forEach((ingredient) => {
if (ingredient.extra_ingredient) { if (ingredient.extra_ingredient) {
retVal += ingredient.extra_ingredient.price; retVal += ingredient.extra_ingredient.price;
} }
@ -328,10 +334,10 @@ function create_min_prices(drink: Drink, volume: DrinkPriceVolume, percentage: n
} else { } else {
return computed<number>(() => { return computed<number>(() => {
let retVal = 0; let retVal = 0;
volume.ingredients.forEach(ingredient => { volume.ingredients.forEach((ingredient) => {
if (ingredient.drink_ingredient) { if (ingredient.drink_ingredient) {
const _drink = state.drinks.find( const _drink = state.drinks.find(
a => a.id === ingredient.drink_ingredient?.drink_ingredient?.id (a) => a.id === ingredient.drink_ingredient?.drink_ingredient?.id
); );
retVal += ingredient.drink_ingredient.volume * (_drink?.cost_price_pro_volume.value || 0); retVal += ingredient.drink_ingredient.volume * (_drink?.cost_price_pro_volume.value || 0);
} }
@ -348,5 +354,5 @@ export { create_min_prices, DrinkPriceVolume, MinPrice, Drink };
export default { export default {
state, state,
actions, actions,
getters getters,
}; };

View File

@ -10,7 +10,7 @@ export interface DrinkInterface {
const state: DrinkInterface = { const state: DrinkInterface = {
drinkTypes: [], drinkTypes: [],
drinks: [] drinks: [],
}; };
const mutations: MutationTree<DrinkInterface> = { const mutations: MutationTree<DrinkInterface> = {
@ -18,7 +18,7 @@ const mutations: MutationTree<DrinkInterface> = {
state.drinkTypes = drinkTypes; state.drinkTypes = drinkTypes;
}, },
setDrinkType(state, drinkType: FG.DrinkType) { setDrinkType(state, drinkType: FG.DrinkType) {
const item = state.drinkTypes.find(item => item.id == drinkType.id); const item = state.drinkTypes.find((item) => item.id == drinkType.id);
if (item) { if (item) {
item.name = drinkType.name; item.name = drinkType.name;
} }
@ -27,20 +27,20 @@ const mutations: MutationTree<DrinkInterface> = {
state.drinkTypes.unshift(drinkType); state.drinkTypes.unshift(drinkType);
}, },
removeDrinkType(state, id: number) { removeDrinkType(state, id: number) {
const index = state.drinkTypes.findIndex(item => item.id == id); const index = state.drinkTypes.findIndex((item) => item.id == id);
state.drinkTypes.splice(index, 1); state.drinkTypes.splice(index, 1);
}, },
setDrinks(state, drinks: FG.Drink[]) { setDrinks(state, drinks: FG.Drink[]) {
state.drinks = drinks state.drinks = drinks;
}, },
setDrink(state, drink: FG.Drink) { setDrink(state, drink: FG.Drink) {
const index = state.drinks.findIndex(item => item.id = drink.id) const index = state.drinks.findIndex((item) => (item.id = drink.id));
if (index) { if (index) {
state.drinks[index] = drink state.drinks[index] = drink;
} else { } else {
state.drinks.push(drink) state.drinks.push(drink);
}
} }
},
}; };
const actions: ActionTree<DrinkInterface, StateInterface> = { const actions: ActionTree<DrinkInterface, StateInterface> = {
@ -50,7 +50,7 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
.then((response: AxiosResponse<FG.DrinkType[]>) => { .then((response: AxiosResponse<FG.DrinkType[]>) => {
commit('setDrinkTypes', response.data); commit('setDrinkTypes', response.data);
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
addDrinkType({ commit }, data) { addDrinkType({ commit }, data) {
axios axios
@ -58,7 +58,7 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
.then((response: AxiosResponse<FG.DrinkType>) => { .then((response: AxiosResponse<FG.DrinkType>) => {
commit('addDrinkType', response.data); commit('addDrinkType', response.data);
}) })
.catch(err => { .catch((err) => {
console.warn(err); console.warn(err);
}); });
}, },
@ -68,7 +68,7 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
.then(() => { .then(() => {
commit('removeDrinkType', data); commit('removeDrinkType', data);
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
changeDrinkTypeName({ commit }, drinkType: FG.DrinkType) { changeDrinkTypeName({ commit }, drinkType: FG.DrinkType) {
axios axios
@ -76,22 +76,24 @@ const actions: ActionTree<DrinkInterface, StateInterface> = {
.then(() => { .then(() => {
commit('setDrinkType', drinkType); commit('setDrinkType', drinkType);
}) })
.catch(err => console.warn(err)); .catch((err) => console.warn(err));
}, },
getDrinks({ commit }) { getDrinks({ commit }) {
axios.get('/pricelist/drinks') axios
.get('/pricelist/drinks')
.then((response: AxiosResponse<FG.Drink[]>) => { .then((response: AxiosResponse<FG.Drink[]>) => {
commit('setDrinks', response.data) commit('setDrinks', response.data);
}) })
.catch(err => console.warn(err)) .catch((err) => console.warn(err));
}, },
createDrink({ commit }, data) { createDrink({ commit }, data) {
axios.post('/pricelist/drinks', data) axios
.post('/pricelist/drinks', data)
.then((response: AxiosResponse<FG.Drink>) => { .then((response: AxiosResponse<FG.Drink>) => {
commit('setDrink', response.data) commit('setDrink', response.data);
}) })
.catch(err => console.warn(err)) .catch((err) => console.warn(err));
} },
}; };
const getters: GetterTree<DrinkInterface, StateInterface> = {}; const getters: GetterTree<DrinkInterface, StateInterface> = {};
@ -100,7 +102,7 @@ const schedule: Module<DrinkInterface, StateInterface> = {
state, state,
mutations, mutations,
actions, actions,
getters getters,
}; };
export default schedule; export default schedule;