From caa09a3c2c0bb45a545d37826b5efdc0fca279a1 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 18 Mar 2021 13:08:43 +0100 Subject: [PATCH] Added correct definitions file --- src/flaschengeist.d.ts | 31 +++---- src/plugins/pricelist/plugin.ts | 2 +- src/plugins/pricelist/routes/index.ts | 10 +-- src/plugins/pricelist/store/altStore.ts | 108 +++++++++++++----------- src/plugins/pricelist/store/drinks.ts | 52 ++++++------ 5 files changed, 103 insertions(+), 100 deletions(-) diff --git a/src/flaschengeist.d.ts b/src/flaschengeist.d.ts index 42c3a56..b930d82 100644 --- a/src/flaschengeist.d.ts +++ b/src/flaschengeist.d.ts @@ -15,7 +15,7 @@ declare namespace FG { mail: string; birthday?: Date; roles: Array; - permissions?: string[]; + permissions?: Array; avatar_url?: string; } type Permission = string; @@ -29,9 +29,9 @@ declare namespace FG { time: Date; amount: number; reversal_id: number; - sender_id?: number; - receiver_id?: number; - author_id?: number; + sender_id?: string; + receiver_id?: string; + author_id?: string; original_id?: number; } interface Drink { @@ -43,32 +43,26 @@ declare namespace FG { cost_price_pro_volume?: number; cost_price_package_netto?: number; tags: Array; - type?: DrinkType; - volumes: DrinkPriceVolume[]; + type: DrinkType; + volumes: Array; } interface DrinkIngredient { id: number; volume: number; - drink_ingredient?: Drink; + drink_ingredient_id: number; + price: number; } interface DrinkPrice { id: number; price: number; - public: boolean; + public: bool; description?: string; } - interface DrinkMinPrice { - percentage: number; - //price: ComputedRef; - price: number; - } interface DrinkPriceVolume { id: number; volume: number; - //computed_volume: ComputedRef; - min_prices: DrinkMinPrice[]; + ingredients: Array; prices: Array; - ingredients: Array; } interface DrinkType { id: number; @@ -81,8 +75,9 @@ declare namespace FG { } interface Ingredient { id: number; - drink_ingredient: DrinkIngredient | null; - extra_ingredient: ExtraIngredient | null; + volume_id: number; + drink_ingredient: DrinkIngredient; + extra_ingredient: ExtraIngredient; } interface Tag { id: number; diff --git a/src/plugins/pricelist/plugin.ts b/src/plugins/pricelist/plugin.ts index a7b69b0..7ef5f7a 100644 --- a/src/plugins/pricelist/plugin.ts +++ b/src/plugins/pricelist/plugin.ts @@ -11,7 +11,7 @@ const plugin: FG_Plugin.Plugin = { requiredBackendModules: ['pricelist'], version: '0.0.1', store: new Map>([['drink', drink]]), - widgets: [] + widgets: [], // widgets: [ // { // priority: 1, diff --git a/src/plugins/pricelist/routes/index.ts b/src/plugins/pricelist/routes/index.ts index 113f29a..bde127e 100644 --- a/src/plugins/pricelist/routes/index.ts +++ b/src/plugins/pricelist/routes/index.ts @@ -15,7 +15,7 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [ name: 'drinks-pricelist', shortcut: true, meta: { permissions: ['user'] }, - component: () => import('../pages/Pricelist.vue') + component: () => import('../pages/Pricelist.vue'), }, { title: 'Einstellungen', @@ -24,10 +24,10 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [ name: 'drinks-settings', shortcut: false, meta: { permissions: ['users_edit_other'] }, - component: () => import('../pages/Settings.vue') - } - ] - } + component: () => import('../pages/Settings.vue'), + }, + ], + }, ]; export default mainRoutes; diff --git a/src/plugins/pricelist/store/altStore.ts b/src/plugins/pricelist/store/altStore.ts index 6ac5df0..0c2d794 100644 --- a/src/plugins/pricelist/store/altStore.ts +++ b/src/plugins/pricelist/store/altStore.ts @@ -11,7 +11,7 @@ const state = reactive<{ drinks: [], tags: [], drinkTypes: [], - extraIngredients: [] + extraIngredients: [], }); interface MinPrice extends Omit { @@ -37,22 +37,22 @@ class DrinkPriceVolume { this.min_prices = [ { percentage: 100, - price: create_min_prices(drink, this, 100) + price: create_min_prices(drink, this, 100), }, { percentage: 250, - price: create_min_prices(drink, this, 250) + price: create_min_prices(drink, this, 250), }, { percentage: 300, - price: create_min_prices(drink, this, 300) - } + price: create_min_prices(drink, this, 300), + }, ]; this.volume = computed({ get: () => { - if (this.ingredients.some(ingredient => !!ingredient.drink_ingredient)) { + if (this.ingredients.some((ingredient) => !!ingredient.drink_ingredient)) { let retVal = 0; - this.ingredients.forEach(ingredient => { + this.ingredients.forEach((ingredient) => { if (ingredient.drink_ingredient?.volume) { retVal += ingredient.drink_ingredient.volume; } @@ -63,7 +63,7 @@ class DrinkPriceVolume { return this._volume; } }, - set: val => (this._volume = val) + set: (val) => (this._volume = val), }); } } @@ -79,7 +79,7 @@ class Drink { cost_price_package_netto, tags, type, - volumes + volumes, }: FG.Drink) { this.id = id; this.article_id = article_id; @@ -100,7 +100,7 @@ class Drink { 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.type = type; @@ -117,17 +117,17 @@ const actions = { .get('pricelist/drinks') .then((response: AxiosResponse) => { state.drinks = []; - response.data.forEach(drink => { + response.data.forEach((drink) => { state.drinks.push(new Drink(drink)); }); - state.drinks.forEach(drink => { - const _drink = response.data.find(a => a.id === drink.id); - _drink?.volumes.forEach(volume => { + state.drinks.forEach((drink) => { + const _drink = response.data.find((a) => a.id === drink.id); + _drink?.volumes.forEach((volume) => { drink.volumes.push(new DrinkPriceVolume(volume, drink)); }); }); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, setPrice(price: FG.DrinkPrice, volume: DrinkPriceVolume) { axios @@ -136,7 +136,7 @@ const actions = { volume.prices.push(response.data); this.sortPrices(volume); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, sortPrices(volume: DrinkPriceVolume) { volume.prices.sort((a, b) => { @@ -149,48 +149,54 @@ const actions = { axios .delete(`pricelist/prices/${price.id}`) .then(() => { - const index = volume.prices.findIndex(a => a.id == price.id); + const index = volume.prices.findIndex((a) => a.id == price.id); if (index > -1) { volume.prices.splice(index, 1); } }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, updatePrice(price: FG.DrinkPrice, volume: DrinkPriceVolume) { axios .put(`pricelist/prices/${price.id}`, price) .then((response: AxiosResponse) => { - const index = volume.prices.findIndex(a => a.id === price.id); + const index = volume.prices.findIndex((a) => a.id === price.id); if (index > -1) { this.sortPrices(volume); } }) - .catch(err => console.log(err)); + .catch((err) => console.log(err)); }, setVolume(volume: DrinkPriceVolume, drink: Drink) { console.log(volume); axios - .post(`pricelist/drinks/${drink.id}/volumes`, { ...volume, volume: volume.volume }) + .post(`pricelist/drinks/${drink.id}/volumes`, { + ...volume, + volume: volume.volume, + }) .then((response: AxiosResponse) => { drink.volumes.push(new DrinkPriceVolume(response.data, drink)); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, updateVolume(volume: DrinkPriceVolume, drink: Drink) { axios - .put(`pricelist/volumes/${volume.id}`, { ...volume, volume: volume.volume?.value }) - .catch(err => console.warn(err)); + .put(`pricelist/volumes/${volume.id}`, { + ...volume, + volume: volume.volume?.value, + }) + .catch((err) => console.warn(err)); }, deleteVolume(volume: FG.DrinkPriceVolume, drink: FG.Drink) { axios .delete(`pricelist/volumes/${volume.id}`) .then(() => { - const index = drink.volumes.findIndex(a => a.id === volume.id); + const index = drink.volumes.findIndex((a) => a.id === volume.id); if (index > -1) { drink.volumes.splice(index, 1); } }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, getExtraIngredients() { axios @@ -198,7 +204,7 @@ const actions = { .then((response: AxiosResponse) => { state.extraIngredients = response.data; }) - .catch(err => console.log(err)); + .catch((err) => console.log(err)); }, setIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) { axios @@ -206,29 +212,29 @@ const actions = { .then((response: AxiosResponse) => { volume.ingredients.push(response.data); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, updateIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) { axios .put(`pricelist/ingredients/${ingredient.id}`, ingredient) .then((response: AxiosResponse) => { - 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) { volume.ingredients[index] = response.data; } }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, deleteIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) { axios .delete(`pricelist/ingredients/${ingredient.id}`) .then(() => { - const index = volume.ingredients.findIndex(a => a.id === ingredient.id); + const index = volume.ingredients.findIndex((a) => a.id === ingredient.id); if (index > -1) { volume.ingredients.splice(index, 1); } }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, getDrinkTypes() { axios @@ -236,38 +242,38 @@ const actions = { .then((response: AxiosResponse) => { state.drinkTypes = response.data; }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, setDrink(drink: FG.Drink) { axios .post('pricelist/drinks', drink) .then((response: AxiosResponse) => { state.drinks.push(new Drink(response.data)); - const drink = state.drinks.find(a => a.id === response.data.id); - response.data.volumes.forEach(volume => { + const drink = state.drinks.find((a) => a.id === response.data.id); + response.data.volumes.forEach((volume) => { drink?.volumes.push(new DrinkPriceVolume(volume, drink)); }); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, updateDrink(drink: Drink) { axios .put(`pricelist/drinks/${drink.id}`, { ...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) { axios .delete(`pricelist/drinks/${drink.id}`) .then(() => { - const index = state.drinks.findIndex(a => a.id === drink.id); + const index = state.drinks.findIndex((a) => a.id === drink.id); if (index > -1) { state.drinks.splice(index, 1); } }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, setExtraIngredient(ingredient: FG.ExtraIngredient) { axios @@ -275,42 +281,42 @@ const actions = { .then((response: AxiosResponse) => { state.extraIngredients.push(response.data); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, updateExtraIngredient(ingredient: FG.ExtraIngredient) { axios .put(`pricelist/ingredients/extraIngredients/${ingredient.id}`, ingredient) .then((response: AxiosResponse) => { - const index = state.extraIngredients.findIndex(a => a.id === ingredient.id); + const index = state.extraIngredients.findIndex((a) => a.id === ingredient.id); if (index > -1) { state.extraIngredients[index] = response.data; } else { state.extraIngredients.push(response.data); } }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, deleteExtraIngredient(ingredient: FG.ExtraIngredient) { axios .delete(`pricelist/ingredients/extraIngredients/${ingredient.id}`) .then(() => { - const index = state.extraIngredients.findIndex(a => a.id === ingredient.id); + const index = state.extraIngredients.findIndex((a) => a.id === ingredient.id); if (index > -1) { state.extraIngredients.splice(index, 1); } }) - .catch(err => console.warn(err)); - } + .catch((err) => console.warn(err)); + }, }; const getters = {}; function create_min_prices(drink: Drink, volume: DrinkPriceVolume, percentage: number) { 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(() => { 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) { retVal += ingredient.extra_ingredient.price; } @@ -328,10 +334,10 @@ function create_min_prices(drink: Drink, volume: DrinkPriceVolume, percentage: n } else { return computed(() => { let retVal = 0; - volume.ingredients.forEach(ingredient => { + volume.ingredients.forEach((ingredient) => { if (ingredient.drink_ingredient) { 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); } @@ -348,5 +354,5 @@ export { create_min_prices, DrinkPriceVolume, MinPrice, Drink }; export default { state, actions, - getters + getters, }; diff --git a/src/plugins/pricelist/store/drinks.ts b/src/plugins/pricelist/store/drinks.ts index 6048c02..ce298eb 100644 --- a/src/plugins/pricelist/store/drinks.ts +++ b/src/plugins/pricelist/store/drinks.ts @@ -10,7 +10,7 @@ export interface DrinkInterface { const state: DrinkInterface = { drinkTypes: [], - drinks: [] + drinks: [], }; const mutations: MutationTree = { @@ -18,7 +18,7 @@ const mutations: MutationTree = { state.drinkTypes = drinkTypes; }, 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) { item.name = drinkType.name; } @@ -27,20 +27,20 @@ const mutations: MutationTree = { state.drinkTypes.unshift(drinkType); }, 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); }, setDrinks(state, drinks: FG.Drink[]) { - state.drinks = drinks + state.drinks = drinks; }, setDrink(state, drink: FG.Drink) { - const index = state.drinks.findIndex(item => item.id = drink.id) - if (index) { - state.drinks[index] = drink - } else { - state.drinks.push(drink) - } - } + const index = state.drinks.findIndex((item) => (item.id = drink.id)); + if (index) { + state.drinks[index] = drink; + } else { + state.drinks.push(drink); + } + }, }; const actions: ActionTree = { @@ -50,7 +50,7 @@ const actions: ActionTree = { .then((response: AxiosResponse) => { commit('setDrinkTypes', response.data); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, addDrinkType({ commit }, data) { axios @@ -58,7 +58,7 @@ const actions: ActionTree = { .then((response: AxiosResponse) => { commit('addDrinkType', response.data); }) - .catch(err => { + .catch((err) => { console.warn(err); }); }, @@ -68,7 +68,7 @@ const actions: ActionTree = { .then(() => { commit('removeDrinkType', data); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, changeDrinkTypeName({ commit }, drinkType: FG.DrinkType) { axios @@ -76,22 +76,24 @@ const actions: ActionTree = { .then(() => { commit('setDrinkType', drinkType); }) - .catch(err => console.warn(err)); + .catch((err) => console.warn(err)); }, - getDrinks({commit}) { - axios.get('/pricelist/drinks') + getDrinks({ commit }) { + axios + .get('/pricelist/drinks') .then((response: AxiosResponse) => { - commit('setDrinks', response.data) + commit('setDrinks', response.data); }) - .catch(err => console.warn(err)) + .catch((err) => console.warn(err)); }, - createDrink({commit}, data) { - axios.post('/pricelist/drinks', data) + createDrink({ commit }, data) { + axios + .post('/pricelist/drinks', data) .then((response: AxiosResponse) => { - commit('setDrink', response.data) + commit('setDrink', response.data); }) - .catch(err => console.warn(err)) - } + .catch((err) => console.warn(err)); + }, }; const getters: GetterTree = {}; @@ -100,7 +102,7 @@ const schedule: Module = { state, mutations, actions, - getters + getters, }; export default schedule;