diff --git a/vue3/src/locales/ar.json b/vue3/src/locales/ar.json
index ed180d634..85fec9c1e 100644
--- a/vue3/src/locales/ar.json
+++ b/vue3/src/locales/ar.json
@@ -205,6 +205,7 @@
"Print": "",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "",
"Proteins": "",
"Quick actions": "",
diff --git a/vue3/src/locales/bg.json b/vue3/src/locales/bg.json
index 4f7a847fd..f2758db87 100644
--- a/vue3/src/locales/bg.json
+++ b/vue3/src/locales/bg.json
@@ -198,6 +198,7 @@
"Print": "Печат",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "Защитен",
"Proteins": "Протеини (белтъчини)",
"Quick actions": "Бързи действия",
diff --git a/vue3/src/locales/ca.json b/vue3/src/locales/ca.json
index 393daa58f..c4de72fad 100644
--- a/vue3/src/locales/ca.json
+++ b/vue3/src/locales/ca.json
@@ -274,6 +274,7 @@
"Properties_Food_Amount": "",
"Properties_Food_Unit": "",
"Property": "",
+ "PropertyType": "",
"Property_Editor": "",
"Protected": "",
"Proteins": "",
diff --git a/vue3/src/locales/cs.json b/vue3/src/locales/cs.json
index ebefbbf9b..e52a5ddd4 100644
--- a/vue3/src/locales/cs.json
+++ b/vue3/src/locales/cs.json
@@ -272,6 +272,7 @@
"Properties_Food_Amount": "Množství nutriční vlastnosti",
"Properties_Food_Unit": "Jednotka nutriční vlastnosti",
"Property": "Nutriční vlastnost",
+ "PropertyType": "",
"Property_Editor": "Editovat nutriční vlastnosti",
"Protected": "Chráněný",
"Proteins": "Proteiny",
diff --git a/vue3/src/locales/da.json b/vue3/src/locales/da.json
index 7c954f92b..4243c8d60 100644
--- a/vue3/src/locales/da.json
+++ b/vue3/src/locales/da.json
@@ -255,6 +255,7 @@
"Properties": "Egenskaber",
"PropertiesFoodHelp": "",
"Property": "Egenskab",
+ "PropertyType": "",
"Protected": "Beskyttet",
"Proteins": "Proteiner",
"Quick actions": "Hurtige handlinger",
diff --git a/vue3/src/locales/de.json b/vue3/src/locales/de.json
index 94960b72b..36bb4fc61 100644
--- a/vue3/src/locales/de.json
+++ b/vue3/src/locales/de.json
@@ -276,6 +276,7 @@
"Properties_Food_Amount": "Eigenschaften: Lebensmittelmenge",
"Properties_Food_Unit": "Nährwert Einheit",
"Property": "Eigenschaft",
+ "PropertyType": "Eigenschafts Typ",
"Property_Editor": "Nährwerte bearbeiten",
"Protected": "Geschützt",
"Proteins": "Proteine",
diff --git a/vue3/src/locales/el.json b/vue3/src/locales/el.json
index 65c172a8f..5f6906bef 100644
--- a/vue3/src/locales/el.json
+++ b/vue3/src/locales/el.json
@@ -247,6 +247,7 @@
"Properties": "Ιδιότητες",
"PropertiesFoodHelp": "",
"Property": "Ιδιότητα",
+ "PropertyType": "",
"Protected": "Προστατευμένο",
"Proteins": "Πρωτεΐνες",
"Quick actions": "Γρήγηορες δράσεις",
diff --git a/vue3/src/locales/en.json b/vue3/src/locales/en.json
index 7f3fe7a50..3b439fa31 100644
--- a/vue3/src/locales/en.json
+++ b/vue3/src/locales/en.json
@@ -277,6 +277,7 @@
"Properties_Food_Amount": "Properties Food Amount",
"Properties_Food_Unit": "Properties Food Unit",
"Property": "Property",
+ "PropertyType": "Property Type",
"Property_Editor": "Property Editor",
"Protected": "Protected",
"Proteins": "Proteins",
diff --git a/vue3/src/locales/es.json b/vue3/src/locales/es.json
index c0a021031..e213c8d37 100644
--- a/vue3/src/locales/es.json
+++ b/vue3/src/locales/es.json
@@ -273,6 +273,7 @@
"Properties": "Propiedades",
"PropertiesFoodHelp": "",
"Property": "Propiedad",
+ "PropertyType": "",
"Property_Editor": "Editor de Propiedades",
"Protected": "Protegido",
"Proteins": "Proteinas",
diff --git a/vue3/src/locales/fi.json b/vue3/src/locales/fi.json
index 67e323c72..fd37f50db 100644
--- a/vue3/src/locales/fi.json
+++ b/vue3/src/locales/fi.json
@@ -139,6 +139,7 @@
"Print": "Tulosta",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Proteins": "Proteiinit",
"Rating": "Luokitus",
"Recently_Viewed": "Äskettäin katsotut",
diff --git a/vue3/src/locales/fr.json b/vue3/src/locales/fr.json
index 3cd20da7f..79d827677 100644
--- a/vue3/src/locales/fr.json
+++ b/vue3/src/locales/fr.json
@@ -274,6 +274,7 @@
"Properties_Food_Amount": "Propriété Quantité de nourriture",
"Properties_Food_Unit": "Propriété Unité de nourriture",
"Property": "Propriété",
+ "PropertyType": "",
"Property_Editor": "Editeur de propriétés",
"Protected": "Protégé",
"Proteins": "Protéines",
diff --git a/vue3/src/locales/he.json b/vue3/src/locales/he.json
index 18fd4d9ac..7465d3b37 100644
--- a/vue3/src/locales/he.json
+++ b/vue3/src/locales/he.json
@@ -275,6 +275,7 @@
"Properties_Food_Amount": "הגדרות כמות אוכל",
"Properties_Food_Unit": "הגדרות יחידת אוכל",
"Property": "נכס",
+ "PropertyType": "",
"Property_Editor": "עורך ערכים",
"Protected": "מוגן",
"Proteins": "פרוטאינים",
diff --git a/vue3/src/locales/hu.json b/vue3/src/locales/hu.json
index 1ad3b9617..2ac7f93a6 100644
--- a/vue3/src/locales/hu.json
+++ b/vue3/src/locales/hu.json
@@ -249,6 +249,7 @@
"Properties": "Tulajdonságok",
"PropertiesFoodHelp": "",
"Property": "Tulajdonság",
+ "PropertyType": "",
"Protected": "Védett",
"Proteins": "Fehérjék",
"Quick actions": "Gyors parancsok",
diff --git a/vue3/src/locales/hy.json b/vue3/src/locales/hy.json
index 8a4692572..42a3cea25 100644
--- a/vue3/src/locales/hy.json
+++ b/vue3/src/locales/hy.json
@@ -85,6 +85,7 @@
"Print": "Տպել",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Proteins": "",
"Rating": "",
"Recently_Viewed": "Վերջերս դիտած",
diff --git a/vue3/src/locales/id.json b/vue3/src/locales/id.json
index 2dc3ace80..db34bbc78 100644
--- a/vue3/src/locales/id.json
+++ b/vue3/src/locales/id.json
@@ -225,6 +225,7 @@
"Private_Recipe_Help": "Resep hanya diperlihatkan kepada Anda dan orang-orang yang dibagikan resep tersebut.",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "Terlindung",
"Proteins": "Protein",
"Quick actions": "",
diff --git a/vue3/src/locales/is.json b/vue3/src/locales/is.json
index ae9a4991f..6ac51c797 100644
--- a/vue3/src/locales/is.json
+++ b/vue3/src/locales/is.json
@@ -274,6 +274,7 @@
"Properties_Food_Amount": "",
"Properties_Food_Unit": "",
"Property": "",
+ "PropertyType": "",
"Property_Editor": "",
"Protected": "",
"Proteins": "",
diff --git a/vue3/src/locales/it.json b/vue3/src/locales/it.json
index cff9558cb..09f639a17 100644
--- a/vue3/src/locales/it.json
+++ b/vue3/src/locales/it.json
@@ -233,6 +233,7 @@
"Private_Recipe_Help": "La ricetta viene mostrata solo a te e a chi l'hai condivisa.",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "Protetto",
"Proteins": "Proteine",
"Quick actions": "Azioni rapide",
diff --git a/vue3/src/locales/lt.json b/vue3/src/locales/lt.json
index 9699da5fc..3874d1380 100644
--- a/vue3/src/locales/lt.json
+++ b/vue3/src/locales/lt.json
@@ -253,6 +253,7 @@
"Properties": "",
"PropertiesFoodHelp": "",
"Property": "",
+ "PropertyType": "",
"Protected": "",
"Proteins": "",
"Quick actions": "",
diff --git a/vue3/src/locales/nb_NO.json b/vue3/src/locales/nb_NO.json
index 984de5925..a2f336463 100644
--- a/vue3/src/locales/nb_NO.json
+++ b/vue3/src/locales/nb_NO.json
@@ -245,6 +245,7 @@
"Properties": "Egenskaper",
"PropertiesFoodHelp": "",
"Property": "Egenskap",
+ "PropertyType": "",
"Protected": "Beskyttet",
"Proteins": "Protein",
"Quick actions": "",
diff --git a/vue3/src/locales/nl.json b/vue3/src/locales/nl.json
index 79ca52d0a..b61f025ca 100644
--- a/vue3/src/locales/nl.json
+++ b/vue3/src/locales/nl.json
@@ -249,6 +249,7 @@
"Properties": "Eigenschappen",
"PropertiesFoodHelp": "",
"Property": "Eigenschap",
+ "PropertyType": "",
"Protected": "Beschermd",
"Proteins": "Eiwitten",
"Quick actions": "Snelle acties",
diff --git a/vue3/src/locales/pl.json b/vue3/src/locales/pl.json
index 0623960a2..2b132b514 100644
--- a/vue3/src/locales/pl.json
+++ b/vue3/src/locales/pl.json
@@ -276,6 +276,7 @@
"Properties_Food_Amount": "Właściwości ilości żywności",
"Properties_Food_Unit": "Właściwości jednostek żywności",
"Property": "Właściwość",
+ "PropertyType": "",
"Property_Editor": "Edytor właściwości",
"Protected": "Chroniony",
"Proteins": "Białka",
diff --git a/vue3/src/locales/pt.json b/vue3/src/locales/pt.json
index 7ede6b1e6..6e8544605 100644
--- a/vue3/src/locales/pt.json
+++ b/vue3/src/locales/pt.json
@@ -195,6 +195,7 @@
"Private_Recipe_Help": "A receita só é mostrada ás pessoas com que foi partilhada.",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "Protegido",
"Proteins": "Proteínas",
"Quick actions": "Acções Rápidas",
diff --git a/vue3/src/locales/pt_BR.json b/vue3/src/locales/pt_BR.json
index c01cf6528..8d86ab7c8 100644
--- a/vue3/src/locales/pt_BR.json
+++ b/vue3/src/locales/pt_BR.json
@@ -263,6 +263,7 @@
"Properties_Food_Amount": "Quantidade de Alimento das Propriedades",
"Properties_Food_Unit": "Unidade de Alimento das Propriedades",
"Property": "Propriedade",
+ "PropertyType": "",
"Property_Editor": "Editor de Propriedades",
"Protected": "Protegido",
"Proteins": "Proteínas",
diff --git a/vue3/src/locales/ro.json b/vue3/src/locales/ro.json
index bbe955c43..941d76932 100644
--- a/vue3/src/locales/ro.json
+++ b/vue3/src/locales/ro.json
@@ -237,6 +237,7 @@
"Private_Recipe_Help": "Rețeta este arătată doar ție și oamenilor cu care este împărtășită.",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "Protejat",
"Proteins": "Proteine",
"Quick actions": "Acțiuni rapide",
diff --git a/vue3/src/locales/ru.json b/vue3/src/locales/ru.json
index 6a94cd25c..722b0dbb3 100644
--- a/vue3/src/locales/ru.json
+++ b/vue3/src/locales/ru.json
@@ -181,6 +181,7 @@
"Print": "Распечатать",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "Защищено",
"Proteins": "Белки",
"Quick actions": "Быстрые действия",
diff --git a/vue3/src/locales/sl.json b/vue3/src/locales/sl.json
index a29c9d702..6c18fcc8c 100644
--- a/vue3/src/locales/sl.json
+++ b/vue3/src/locales/sl.json
@@ -176,6 +176,7 @@
"Private_Recipe_Help": "Recept je prikazan samo vam in osebam, s katerimi ga delite.",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Proteins": "Beljakovine",
"QuickEntry": "Hitri vnos",
"Rating": "Ocena",
diff --git a/vue3/src/locales/sv.json b/vue3/src/locales/sv.json
index 6ba19068e..d36ed9095 100644
--- a/vue3/src/locales/sv.json
+++ b/vue3/src/locales/sv.json
@@ -276,6 +276,7 @@
"Properties_Food_Amount": "Egenskaper Livsmedel Mängd",
"Properties_Food_Unit": "Egenskaper Livsmedel Enhet",
"Property": "Egendom",
+ "PropertyType": "",
"Property_Editor": "Egendom redigerare",
"Protected": "Skyddad",
"Proteins": "Protein",
diff --git a/vue3/src/locales/tr.json b/vue3/src/locales/tr.json
index 926680dbf..7ceb0d5ae 100644
--- a/vue3/src/locales/tr.json
+++ b/vue3/src/locales/tr.json
@@ -275,6 +275,7 @@
"Properties_Food_Amount": "Özellikler Yiyecek Miktar",
"Properties_Food_Unit": "Özellikler Yiyecek Birim",
"Property": "Özellik",
+ "PropertyType": "",
"Property_Editor": "Özellik Editörü",
"Protected": "Korumalı",
"Proteins": "Proteinler",
diff --git a/vue3/src/locales/uk.json b/vue3/src/locales/uk.json
index 7af71194b..8691f8e1a 100644
--- a/vue3/src/locales/uk.json
+++ b/vue3/src/locales/uk.json
@@ -213,6 +213,7 @@
"Private_Recipe_Help": "Рецепт показаний тільки Вам і тими з ким ви поділилися їм.",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Protected": "Захищено",
"Proteins": "Білки",
"Quick actions": "",
diff --git a/vue3/src/locales/zh_Hans.json b/vue3/src/locales/zh_Hans.json
index 1dbb15fd1..57eb8a26a 100644
--- a/vue3/src/locales/zh_Hans.json
+++ b/vue3/src/locales/zh_Hans.json
@@ -270,6 +270,7 @@
"Properties_Food_Amount": "食物数量属性",
"Properties_Food_Unit": "食品单位属性",
"Property": "属性",
+ "PropertyType": "",
"Property_Editor": "属性编辑器",
"Protected": "受保护的",
"Proteins": "蛋白质",
diff --git a/vue3/src/locales/zh_Hant.json b/vue3/src/locales/zh_Hant.json
index a7028e31d..79410c036 100644
--- a/vue3/src/locales/zh_Hant.json
+++ b/vue3/src/locales/zh_Hant.json
@@ -60,6 +60,7 @@
"Print": "",
"Profile": "",
"PropertiesFoodHelp": "",
+ "PropertyType": "",
"Proteins": "",
"Rating": "",
"Recently_Viewed": "",
diff --git a/vue3/src/pages/ModelListPage.vue b/vue3/src/pages/ModelListPage.vue
index 4403208ef..c43010f9e 100644
--- a/vue3/src/pages/ModelListPage.vue
+++ b/vue3/src/pages/ModelListPage.vue
@@ -8,17 +8,17 @@
-
- {{ $t(model.localizedName) }}
+ {{ $t(model.localizationKey) }}
-
- {{ $t(modelClass.localizedName) }}
+
+ {{ $t(genericModel.model.localizationKey) }}
@@ -57,8 +57,9 @@
import {onBeforeMount, onMounted, ref, watch} from "vue";
import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
import {useI18n} from "vue-i18n";
-import {Food, GenericModel, getModelFromStr, SUPPORTED_MODELS, Unit} from "@/types/Models";
+import {TFood, TUnit, GenericModel, getModelFromStr, TKeyword, TSupermarketCategory, TPropertyType} from "@/types/Models";
import {ca} from "vuetify/locale";
+import {ApiApi} from "@/openapi";
const {t} = useI18n()
@@ -87,15 +88,13 @@ const items = ref([] as Array)
const itemCount = ref(0)
const searchQuery = ref('')
-const modelClass = ref({} as GenericModel)
-const supportedModels = ref([
- new Food, new Unit
-])
+const genericModel = ref({} as GenericModel)
+
// watch for changes to the prop in case its changed
watch(() => props.model, () => {
console.log('loading model ', props.model)
- modelClass.value = getModelFromStr(props.model)
+ genericModel.value = getModelFromStr(props.model)
loadItems({page: 1, itemsPerPage: 10})
})
@@ -103,18 +102,19 @@ watch(() => props.model, () => {
* select model class before mount because template renders (and requests item load) before onMounted is called
*/
onBeforeMount(() => {
+
try {
- modelClass.value = getModelFromStr(props.model)
+ genericModel.value = getModelFromStr(props.model)
} catch (Error) {
console.error('Invalid model passed to ModelListPage, loading Food instead')
- modelClass.value = getModelFromStr('Food')
+ genericModel.value = getModelFromStr('Food')
}
})
function loadItems({page, itemsPerPage, search, sortBy, groupBy}) {
loading.value = true
- modelClass.value.list({page: page, pageSize: itemsPerPage, query: search}).then(r => {
+ genericModel.value.list({page: page, pageSize: itemsPerPage, query: search}).then(r => {
items.value = r.results
itemCount.value = r.count
}).catch(err => {
diff --git a/vue3/src/types/Models.ts b/vue3/src/types/Models.ts
index 733ef54f4..adb912bc2 100644
--- a/vue3/src/types/Models.ts
+++ b/vue3/src/types/Models.ts
@@ -12,227 +12,201 @@ import {
PropertyType as IPropertyType, ApiFoodListRequest, ApiUnitListRequest,
} from "@/openapi";
-export const SUPPORTED_MODELS = ["Food", "Unit"]
-export function getModelFromStr(model_name: String) {
- switch (model_name.toLowerCase()) {
- case 'food': {
- return new Food
- }
- case 'unit': {
- return new Unit
- }
- case 'keyword': {
- return new Keyword
- }
- case 'recipe': {
- return new Recipe
- }
- case 'mealtype': {
- return new MealType
- }
- case 'user': {
- return new User
- }
- case 'foodinheritfield': {
- return new FoodInheritField
- }
- case 'supermarketcategory': {
- return new SupermarketCategory
- }
- case 'propertytype': {
- return new PropertyType
- }
- default: {
- throw Error(`Invalid Model ${model_name}, did you forget to register it in Models.ts?`)
- }
+/**
+ * returns a GenericModel instance with the given model type
+ * throws and error if no model with the given name exist
+ * @param modelName name of the model
+ * @return instance of GenericModel
+ */
+export function getModelFromStr(modelName: String) {
+ if (SUPPORTED_MODELS.has(modelName)) {
+ return new GenericModel(SUPPORTED_MODELS.get(modelName))
+ } else {
+ throw Error(`Model ${modelName} not in SUPPORTED_MODELS`)
}
}
/**
- * Generic model used for generic model selects/requests
- * TODO should be somehow automatically created in the model but for now this works
+ * common list parameters shared by all generic models
*/
-export abstract class GenericModel {
+type GenericListRequestParameter = {
+ page: number,
+ pageSize: number,
+ query: string,
+}
- localizedName: string
- icon: string
+/**
+ * custom type containing all attributes needed by the generic model system to properly handle all functions
+ */
+type Model = {
+ name: string,
+ localizationKey: string,
+ icon: string,
- /**
- * override and set to false if model is read only
- */
- canCreate(): boolean {
- return true
+ disableList: boolean | undefined,
+ disableRetrieve: boolean | undefined,
+ disableCreate: boolean | undefined,
+ disableDelete: boolean | undefined,
+
+ // table headers
+ // canCreate
+ // canDelete
+}
+export let SUPPORTED_MODELS = new Map()
+
+export const TFood = {
+ name: 'Food',
+ localizationKey: 'Food',
+ icon: 'fa-solid fa-carrot'
+} as Model
+SUPPORTED_MODELS.set(TFood.name, TFood)
+
+export const TUnit = {
+ name: 'Unit',
+ localizationKey: 'Unit',
+ icon: 'fa-solid fa-scale-balanced',
+} as Model
+SUPPORTED_MODELS.set(TUnit.name, TUnit)
+
+export const TKeyword = {
+ name: 'Keyword',
+ localizationKey: 'Keyword',
+ icon: 'fa-solid fa-tags',
+} as Model
+SUPPORTED_MODELS.set(TKeyword.name, TKeyword)
+
+export const TRecipe = {
+ name: 'Recipe',
+ localizationKey: 'Recipe',
+ icon: 'fa-solid fa-book',
+} as Model
+SUPPORTED_MODELS.set(TRecipe.name, TRecipe)
+
+export const TMealType = {
+ name: 'MealType',
+ localizationKey: 'Meal_Type',
+ icon: 'fa-solid fa-utensils',
+} as Model
+SUPPORTED_MODELS.set(TMealType.name, TMealType)
+
+export const TUser = {
+ name: 'User',
+ localizationKey: 'User',
+ icon: 'fa-solid fa-users',
+
+ disableCreate: true,
+ disableDelete: true,
+} as Model
+SUPPORTED_MODELS.set(TUser.name, TUser)
+
+export const TSupermarketCategory = {
+ name: 'SupermarketCategory',
+ localizationKey: 'Category',
+ icon: 'fa-solid fa-boxes-stacked',
+} as Model
+SUPPORTED_MODELS.set(TSupermarketCategory.name, TSupermarketCategory)
+
+export const TPropertyType = {
+ name: 'PropertyType',
+ localizationKey: 'Property',
+ icon: 'fa-solid fa-database',
+} as Model
+SUPPORTED_MODELS.set(TPropertyType.name, TPropertyType)
+
+export const TFoodInheritField = {
+ name: 'FoodInheritField',
+ localizationKey: 'FoodInherit',
+ icon: 'fa-solid fa-list',
+
+ disableCreate: true,
+ disableDelete: true,
+ disableRetrieve: true,
+} as Model
+SUPPORTED_MODELS.set(TFoodInheritField.name, TFoodInheritField)
+
+
+/**
+ * Many of Tandoors models and model API endpoints share the same interfaces
+ * The GenericModel class allows interaction with these models in a standardized manner
+ */
+export class GenericModel {
+
+ api: Object
+ model: Model
+
+ constructor(model: Model) {
+ this.model = model
+ this.api = new ApiApi()
}
/**
- * create a new instance of a given model
- * do not override on models that cannot create
- * @param name value for field name
+ * query the models list endpoint using the given generic parameters
+ * @param genericListRequestParameter parameters
+ * @return promise of request
*/
- create(name: string): Promise {
- if (!this.canCreate()) {
- throw new Error('Cannot create on this model!')
+ list(genericListRequestParameter: GenericListRequestParameter) {
+ if (this.model.disableList) {
+ throw new Error('Cannot list on this model!')
+ } else {
+ return this.api[`api${this.model.name}List`](genericListRequestParameter)
}
- return new Promise(() => {
- return undefined
- })
};
/**
- * retrieves instances of given model with given query from DB
- * @param query value for standard query parameter of endpoint
+ * create a new instance of the given model
+ * throws error if creation is not supported for given model
+ * @param obj object to create
+ * @return promise of request
*/
- abstract list(query: string): Promise>
+ create(obj: any) {
+ if (this.model.disableCreate) {
+ throw new Error('Cannot create on this model!')
+ } else {
+ let createRequestParams = {}
+ createRequestParams[this.model.name.toLowerCase()] = obj
+ return this.api[`api${this.model.name}Create`](createRequestParams)
+ }
+ }
+
+ /**
+ * update a model instance with the given value
+ * throws error if updating is not supported for given model
+ * @param id id of object to update
+ * @param obj object to update
+ * @return promise of request
+ */
+ update(id: number, obj: any) {
+ if (this.model.disableCreate) {
+ throw new Error('Cannot update on this model!')
+ } else {
+ let updateRequestParams = {}
+ updateRequestParams['id'] = id
+ updateRequestParams[this.model.name.toLowerCase()] = obj
+ return this.api[`api${this.model.name}Update`](updateRequestParams)
+ }
+ }
+
+ /**
+ * deletes the given model instance
+ * throws error if creation is not supported for given model
+ * @param id object id to delete
+ * @return promise of request
+ */
+ destroy(id: number) {
+ if (this.model.disableDelete) {
+ throw new Error('Cannot delete on this model!')
+ } else {
+ let destroyRequestParams = {}
+ destroyRequestParams['id'] = id
+ return this.api[`api${this.model.name}Destroy`](createRequestParams)
+ }
+ }
+
}
-export class Keyword extends GenericModel {
- create(name: string) {
- const api = new ApiApi()
- return api.apiKeywordCreate({keyword: {name: name} as IKeyword})
- }
- list(query: string) {
- const api = new ApiApi()
- return api.apiKeywordList({query: query}).then(r => {
- if (r.results) {
- return r.results
- } else {
- return []
- }
- })
- }
-}
-// TODO review this whole file and its usages
-export class Food extends GenericModel {
-
- localizedName = 'Food'
- icon = 'fa-solid fa-carrot'
-
- create(name: string) {
- const api = new ApiApi()
- return api.apiFoodCreate({food: {name: name} as IFood})
- }
-
- list(requestParameters: ApiFoodListRequest = {}) {
- const api = new ApiApi()
- return api.apiFoodList(requestParameters)
- }
-}
-
-export class Unit extends GenericModel {
-
- localizedName = 'Unit'
- icon = 'fa-solid fa-scale-balanced'
-
- create(name: string) {
- const api = new ApiApi()
- return api.apiUnitCreate({unit: {name: name} as IUnit})
- }
-
- list(requestParameters: ApiUnitListRequest = {}) {
- const api = new ApiApi()
- return api.apiUnitList(requestParameters)
- }
-}
-
-export class Recipe extends GenericModel {
- create(name: string) {
- const api = new ApiApi()
- return api.apiRecipeCreate({recipe: {name: name} as IRecipe}).then(r => {
- return r as unknown as IRecipeOverview
- })
- }
-
- list(query: string) {
- const api = new ApiApi()
- return api.apiRecipeList({query: query}).then(r => {
- if (r.results) {
- return r.results
- } else {
- return []
- }
- })
- }
-}
-
-export class MealType extends GenericModel {
- create(name: string) {
- const api = new ApiApi()
- return api.apiMealTypeCreate({mealType: {name: name} as IMealType}).then(r => {
- return r as unknown as IMealType
- })
- }
-
- list(query: string) {
- const api = new ApiApi()
- return api.apiMealTypeList({}).then(r => {
- if (r.results) {
- return r.results
- } else {
- return []
- }
- })
- }
-}
-
-export class User extends GenericModel {
-
- canCreate(): boolean {
- return false
- }
-
- list(query: string) {
- const api = new ApiApi()
- return api.apiUserList({}).then(r => {
- if (r) {
- return r
- } else {
- return []
- }
- })
- }
-}
-
-export class FoodInheritField extends GenericModel {
-
- canCreate(): boolean {
- return false
- }
-
- list(query: string) {
- const api = new ApiApi()
- return api.apiFoodInheritFieldList({}).then(r => {
- if (r) {
- return r
- } else {
- return []
- }
- })
- }
-}
-
-export class SupermarketCategory extends GenericModel {
-
- create(name: string) {
- const api = new ApiApi()
- return api.apiSupermarketCategoryCreate({supermarketCategory: {name: name} as ISupermarketCategory}).then(r => {
- return r as unknown as ISupermarketCategory
- })
- }
-
- list(query: string) {
- const api = new ApiApi()
- return api.apiSupermarketCategoryList({query: query}).then(r => {
- if (r.results) {
- return r.results
- } else {
- return []
- }
- })
- }
-}
export class PropertyType extends GenericModel {