Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7986632dab | ||
|
|
627564e8c6 | ||
|
|
917f3dc640 |
No files matched your search
@@ -5,6 +5,7 @@ use crate::models::variant::{load_article_variants, Variant};
|
|||||||
use sqlx::{Arguments, Pool, Row, Postgres, Error, AssertSqlSafe};
|
use sqlx::{Arguments, Pool, Row, Postgres, Error, AssertSqlSafe};
|
||||||
use sqlx::postgres::{PgArguments, PgQueryResult, PgRow};
|
use sqlx::postgres::{PgArguments, PgQueryResult, PgRow};
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
|
use crate::models::nutritional::{load_nutritional, Nutritional};
|
||||||
use crate::models::unit::Unit;
|
use crate::models::unit::Unit;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone, FromRow)]
|
#[derive(Debug, Deserialize, Serialize, Clone, FromRow)]
|
||||||
@@ -23,6 +24,7 @@ pub struct Article {
|
|||||||
pub bio_info: Option<String>,
|
pub bio_info: Option<String>,
|
||||||
pub topm_id: Option<String>,
|
pub topm_id: Option<String>,
|
||||||
pub additional_name: Option<String>,
|
pub additional_name: Option<String>,
|
||||||
|
pub nutritional: Option<Nutritional>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_postgres_row_small(row: PgRow) -> Article {
|
fn from_postgres_row_small(row: PgRow) -> Article {
|
||||||
@@ -41,6 +43,7 @@ fn from_postgres_row_small(row: PgRow) -> Article {
|
|||||||
bio_info: row.get(10),
|
bio_info: row.get(10),
|
||||||
topm_id: row.get(11),
|
topm_id: row.get(11),
|
||||||
additional_name: row.get(12),
|
additional_name: row.get(12),
|
||||||
|
nutritional: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +61,16 @@ async fn from_postgres_row(row: PgRow, pool: PgPool) -> Article {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let nutritional_id_option: Option<i64> = row.get(13);
|
||||||
|
let nutritional: Option<Nutritional> = match nutritional_id_option {
|
||||||
|
Some(nutritional_id) => {
|
||||||
|
load_nutritional(nutritional_id, &pool).await
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Article {
|
Article {
|
||||||
id: row.get(0),
|
id: row.get(0),
|
||||||
name: row.get(1),
|
name: row.get(1),
|
||||||
@@ -73,6 +86,7 @@ async fn from_postgres_row(row: PgRow, pool: PgPool) -> Article {
|
|||||||
bio_info: row.get(10),
|
bio_info: row.get(10),
|
||||||
topm_id: row.get(11),
|
topm_id: row.get(11),
|
||||||
additional_name: row.get(12),
|
additional_name: row.get(12),
|
||||||
|
nutritional: nutritional,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ pub mod unit;
|
|||||||
pub mod label;
|
pub mod label;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
pub mod supplier;
|
pub mod supplier;
|
||||||
|
pub mod nutritional;
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
use log::{error, info};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sqlx::{Arguments, Pool, Row, Postgres, Error, AssertSqlSafe, FromRow, PgPool};
|
||||||
|
use sqlx::postgres::{PgArguments, PgQueryResult, PgRow};
|
||||||
|
use crate::models::article::Article;
|
||||||
|
use crate::models::variant::load_article_variants;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, FromRow, Clone)]
|
||||||
|
pub struct Nutritional {
|
||||||
|
pub id: i64,
|
||||||
|
pub calorific_value_kj: f64,
|
||||||
|
pub calorific_value_kcal: f64,
|
||||||
|
pub fat: f64,
|
||||||
|
pub saturated_fat : f64,
|
||||||
|
pub carbohydrates: f64,
|
||||||
|
pub sugar: f64,
|
||||||
|
pub fibers: f64,
|
||||||
|
pub protein: f64,
|
||||||
|
pub salt: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Nutritional {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
id: 0,
|
||||||
|
calorific_value_kj: 0.0,
|
||||||
|
calorific_value_kcal: 0.0,
|
||||||
|
fat: 0.0,
|
||||||
|
saturated_fat: 0.0,
|
||||||
|
carbohydrates: 0.0,
|
||||||
|
sugar: 0.0,
|
||||||
|
fibers: 0.0,
|
||||||
|
protein: 0.0,
|
||||||
|
salt: 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Nutritional {
|
||||||
|
Nutritional {
|
||||||
|
id: row.get(0),
|
||||||
|
calorific_value_kj: row.get(1),
|
||||||
|
calorific_value_kcal: row.get(2),
|
||||||
|
fat: row.get(3),
|
||||||
|
saturated_fat: row.get(4),
|
||||||
|
carbohydrates: row.get(5),
|
||||||
|
sugar: row.get(6),
|
||||||
|
fibers: row.get(7),
|
||||||
|
protein: row.get(8),
|
||||||
|
salt: row.get(9),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn load_nutritional(nutritional_id: i64, pool: &PgPool) -> Option<Nutritional> {
|
||||||
|
let statement = format!(
|
||||||
|
"SELECT * FROM {} WHERE id = $1",
|
||||||
|
"nutritional"
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut args = PgArguments::default();
|
||||||
|
args.add(nutritional_id);
|
||||||
|
|
||||||
|
let res = sqlx::query_with(
|
||||||
|
AssertSqlSafe(statement.as_str()), args)
|
||||||
|
.fetch_one(pool).await;
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Ok(record) => {
|
||||||
|
let article = from_postgres_row(record, pool).await;
|
||||||
|
|
||||||
|
Some(article)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!("Error while loading nutritional value: ID: {}", nutritional_id);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn insert_nutritional(nutritional: &Nutritional, pool: PgPool) -> Option<Nutritional> {
|
||||||
|
let mut args = PgArguments::default();
|
||||||
|
args.add(&nutritional.calorific_value_kj);
|
||||||
|
args.add(&nutritional.calorific_value_kcal);
|
||||||
|
args.add(&nutritional.fat);
|
||||||
|
args.add(&nutritional.saturated_fat);
|
||||||
|
args.add(&nutritional.carbohydrates);
|
||||||
|
args.add(&nutritional.sugar);
|
||||||
|
args.add(&nutritional.fibers);
|
||||||
|
args.add(&nutritional.protein);
|
||||||
|
args.add(&nutritional.salt);
|
||||||
|
|
||||||
|
let statement = format!(
|
||||||
|
"INSERT INTO {} (calorific_value_kj, calorific_value_kcal, fat, carbohydrates, sugar, default_unit_id, fibers, protein, salt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *",
|
||||||
|
"nutritional",
|
||||||
|
);
|
||||||
|
|
||||||
|
let res = sqlx::query_with(
|
||||||
|
AssertSqlSafe(statement.as_str()),
|
||||||
|
args)
|
||||||
|
.fetch_one(&pool).await;
|
||||||
|
|
||||||
|
info!("{:#?}", res);
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Ok(record) => {
|
||||||
|
let nutritional = from_postgres_row(record, &pool).await;
|
||||||
|
|
||||||
|
Some(nutritional)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!("Error while loading newly created nutritional values. ID: {}", nutritional.id);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_nutritional(nutritional: &Nutritional, pool: PgPool) -> Option<Nutritional> {
|
||||||
|
let mut args = PgArguments::default();
|
||||||
|
args.add(&nutritional.id);
|
||||||
|
args.add(&nutritional.calorific_value_kj);
|
||||||
|
args.add(&nutritional.calorific_value_kcal);
|
||||||
|
args.add(&nutritional.fat);
|
||||||
|
args.add(&nutritional.saturated_fat);
|
||||||
|
args.add(&nutritional.carbohydrates);
|
||||||
|
args.add(&nutritional.sugar);
|
||||||
|
args.add(&nutritional.fibers);
|
||||||
|
args.add(&nutritional.protein);
|
||||||
|
args.add(&nutritional.salt);
|
||||||
|
let statement = format!(
|
||||||
|
"UPDATE {} SET calorific_value_kj = $3, calorific_value_kcal = $4, fat = $5,\
|
||||||
|
saturated_fat = $6, carbohydrates = $7, sugar = $8, fibers = $9, protein = $10, salt = $11 WHERE id = $1 RETURNING *",
|
||||||
|
"nutritional",
|
||||||
|
);
|
||||||
|
|
||||||
|
let res = sqlx::query_with(
|
||||||
|
AssertSqlSafe(statement.as_str()),
|
||||||
|
args)
|
||||||
|
.fetch_one(&pool).await;
|
||||||
|
|
||||||
|
info!("{:#?}", res);
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Ok(record) => {
|
||||||
|
let updated = from_postgres_row(record, &pool).await;
|
||||||
|
Some(updated)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!("Error while updating nutritional values. ID {}", nutritional.id);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_nutritional(nutritional_id: i64, pool: PgPool) -> Option<()> {
|
||||||
|
let result = sqlx::query(
|
||||||
|
AssertSqlSafe(format!("DELETE FROM {} WHERE id = {}",
|
||||||
|
"nutritional",
|
||||||
|
nutritional_id
|
||||||
|
).as_str())
|
||||||
|
).execute(&pool).await;
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(_) => {
|
||||||
|
Some(())
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("Error deleting nutritional. ID: {:#?}", err);
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use sqlx::{Arguments, AssertSqlSafe, FromRow, PgPool, Row};
|
use sqlx::{Arguments, AssertSqlSafe, FromRow, PgPool, Row};
|
||||||
use sqlx::postgres::{PgArguments, PgRow};
|
use sqlx::postgres::{PgArguments, PgRow};
|
||||||
use crate::models::label::{load_label, Label};
|
use crate::models::label::{load_label, Label};
|
||||||
|
use crate::models::nutritional::{load_nutritional, Nutritional};
|
||||||
use crate::models::unit::Unit;
|
use crate::models::unit::Unit;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone, FromRow)]
|
#[derive(Debug, Deserialize, Serialize, Clone, FromRow)]
|
||||||
@@ -17,6 +18,7 @@ pub struct Variant {
|
|||||||
pub label: Option<Label>,
|
pub label: Option<Label>,
|
||||||
pub variant_description: Option<String>,
|
pub variant_description: Option<String>,
|
||||||
pub topm_row: Option<String>,
|
pub topm_row: Option<String>,
|
||||||
|
pub nutritional: Option<Nutritional>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant {
|
async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant {
|
||||||
@@ -30,6 +32,16 @@ async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let nutritional_id_option: Option<i64> = row.get(11);
|
||||||
|
let nutritional: Option<Nutritional> = match nutritional_id_option {
|
||||||
|
Some(nutritional_id) => {
|
||||||
|
load_nutritional(nutritional_id, &pool).await
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Variant {
|
Variant {
|
||||||
id: row.get(0),
|
id: row.get(0),
|
||||||
weight: row.get(2),
|
weight: row.get(2),
|
||||||
@@ -41,6 +53,7 @@ async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant {
|
|||||||
label: label,
|
label: label,
|
||||||
variant_description: row.get(9),
|
variant_description: row.get(9),
|
||||||
topm_row: row.get(10),
|
topm_row: row.get(10),
|
||||||
|
nutritional: nutritional,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +99,15 @@ pub async fn insert_variant(article_id: i64, variant: &Variant, pool: PgPool) ->
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let nutritional_id = match &variant.nutritional {
|
||||||
|
Some(label) => {
|
||||||
|
Some(label.id)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut args = PgArguments::default();
|
let mut args = PgArguments::default();
|
||||||
args.add(&article_id);
|
args.add(&article_id);
|
||||||
args.add(&variant.weight);
|
args.add(&variant.weight);
|
||||||
@@ -97,9 +119,12 @@ pub async fn insert_variant(article_id: i64, variant: &Variant, pool: PgPool) ->
|
|||||||
args.add(label_id);
|
args.add(label_id);
|
||||||
args.add(&variant.variant_description);
|
args.add(&variant.variant_description);
|
||||||
args.add(&variant.topm_row);
|
args.add(&variant.topm_row);
|
||||||
|
args.add(nutritional_id);
|
||||||
|
|
||||||
let statement = format!(
|
let statement = format!(
|
||||||
"INSERT INTO {} (article_id, weight, ean, name, description, ingredients, unit_id, label_id, variant_description, topm_row) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *",
|
"INSERT INTO {} (article_id, weight, ean, name, description, ingredients, unit_id, label_id, \
|
||||||
|
variant_description, topm_row, nutritional_id) \
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *",
|
||||||
"variant",
|
"variant",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,8 @@
|
|||||||
|
|
||||||
<v-divider vertical/>
|
<v-divider vertical/>
|
||||||
|
|
||||||
|
<Nutrition v-bind:nutrition="store.article.nutritional"/>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
:flat="true"
|
:flat="true"
|
||||||
@click="toggleEdit();"
|
@click="toggleEdit();"
|
||||||
@@ -108,6 +110,7 @@
|
|||||||
Bearbeiten
|
Bearbeiten
|
||||||
</v-tooltip>
|
</v-tooltip>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,8 @@
|
|||||||
|
|
||||||
const article: Article = new Article(0, name.value, bio.value, origin.value, description.value,
|
const article: Article = new Article(0, name.value, bio.value, origin.value, description.value,
|
||||||
ingredients.value, default_unit.value, [],
|
ingredients.value, default_unit.value, [],
|
||||||
mhd.value, bio_origin.value, allergens_text.value, bio_info.value, topm_id.value, additional_name.value);
|
mhd.value, bio_origin.value, allergens_text.value, bio_info.value, topm_id.value,
|
||||||
|
additional_name.value, null);
|
||||||
|
|
||||||
await store.createArticle(article);
|
await store.createArticle(article);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {useLabelEditorStore} from "~/store/labelEditorStore";
|
||||||
|
import type {Ref} from "vue";
|
||||||
|
import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
|
||||||
|
import type {Nutritional} from "~/types/nutritional.ts";
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
nutrition: {type: Object as PropType<Nutritional | null>, required: true},
|
||||||
|
});
|
||||||
|
|
||||||
|
let store = useLabelEditorStore();
|
||||||
|
let loading: Ref<boolean> = ref<boolean>(false);
|
||||||
|
let dialog: Ref<boolean> = ref<boolean>(false);
|
||||||
|
|
||||||
|
async function updateNutrition() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteNutrition() {
|
||||||
|
|
||||||
|
closeDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeDialog() {
|
||||||
|
dialog.value = false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<v-dialog
|
||||||
|
v-model="dialog"
|
||||||
|
:scrollable="true"
|
||||||
|
width="800"
|
||||||
|
max-height="750"
|
||||||
|
height="750"
|
||||||
|
>
|
||||||
|
<template v-slot:activator="{ props }">
|
||||||
|
<v-btn
|
||||||
|
:flat="true"
|
||||||
|
v-bind="props"
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<v-icon v-if="nutrition != null" color="success">mdi-nutrition</v-icon>
|
||||||
|
<v-icon v-else>mdi-nutrition</v-icon>
|
||||||
|
|
||||||
|
<v-tooltip v-if="nutrition != null"
|
||||||
|
activator="parent"
|
||||||
|
location="bottom"
|
||||||
|
>
|
||||||
|
Nährwerte
|
||||||
|
</v-tooltip>
|
||||||
|
|
||||||
|
<v-tooltip v-else
|
||||||
|
activator="parent"
|
||||||
|
location="bottom"
|
||||||
|
>
|
||||||
|
Nährwerte hinzufügen
|
||||||
|
</v-tooltip>
|
||||||
|
</v-btn>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<v-card>
|
||||||
|
<v-card-title>
|
||||||
|
<v-row style="padding-top: 10px">
|
||||||
|
<v-icon size="small">
|
||||||
|
mdi-nutrition
|
||||||
|
</v-icon>
|
||||||
|
|
||||||
|
Nährwerte
|
||||||
|
|
||||||
|
<v-progress-circular v-if="loading" indeterminate :size="15" :width="2"></v-progress-circular>
|
||||||
|
</v-row>
|
||||||
|
</v-card-title>
|
||||||
|
|
||||||
|
<v-divider/>
|
||||||
|
|
||||||
|
<v-card-text>
|
||||||
|
test
|
||||||
|
</v-card-text>
|
||||||
|
|
||||||
|
<v-divider/>
|
||||||
|
|
||||||
|
<v-card-actions>
|
||||||
|
<v-spacer/>
|
||||||
|
<DeleteConfirm
|
||||||
|
title="Nährwert löschen?"
|
||||||
|
:disable="!loading"
|
||||||
|
@delete="deleteNutrition()"
|
||||||
|
/>
|
||||||
|
<v-divider vertical/>
|
||||||
|
|
||||||
|
<v-btn
|
||||||
|
variant="text"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="closeDialog()"
|
||||||
|
>
|
||||||
|
Speichern
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
|
<v-btn
|
||||||
|
variant="text"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="closeDialog()"
|
||||||
|
>
|
||||||
|
Schließen
|
||||||
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
import { Variant } from "~/types/variant";
|
import { Variant } from "~/types/variant";
|
||||||
import type {Unit} from "~/types/unit";
|
import type {Unit} from "~/types/unit";
|
||||||
import type {Label} from "~/types/label";
|
import type {Label} from "~/types/label";
|
||||||
|
import type {Nutritional} from "~/types/nutritional.ts";
|
||||||
|
|
||||||
let store = useLabelEditorStore();
|
let store = useLabelEditorStore();
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@
|
|||||||
|
|
||||||
const variant: Variant = new Variant(0, weight.value, ean.value, name.value,
|
const variant: Variant = new Variant(0, weight.value, ean.value, name.value,
|
||||||
description.value, ingredients.value, unit.value, label.value,
|
description.value, ingredients.value, unit.value, label.value,
|
||||||
variant_description.value, topm_row.value);
|
variant_description.value, topm_row.value, null);
|
||||||
|
|
||||||
await store.addVariant(variant);
|
await store.addVariant(variant);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
|
import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
|
||||||
import type {Unit} from "~/types/unit";
|
import type {Unit} from "~/types/unit";
|
||||||
import type {Label} from "~/types/label";
|
import type {Label} from "~/types/label";
|
||||||
|
import type {Nutritional} from "~/types/nutritional.ts";
|
||||||
|
|
||||||
let store = useLabelEditorStore();
|
let store = useLabelEditorStore();
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
let label: Ref<Label | null> = ref<Label | null>(JSON.parse(JSON.stringify(props.variant.label)));
|
let label: Ref<Label | null> = ref<Label | null>(JSON.parse(JSON.stringify(props.variant.label)));
|
||||||
let variant_description: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.variant_description)));
|
let variant_description: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.variant_description)));
|
||||||
let topm_row: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.topm_row)));
|
let topm_row: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.topm_row)));
|
||||||
|
let nutrition: Ref<Nutritional | null> = ref<Nutritional | null>(JSON.parse(JSON.stringify(props.variant.nutritional)));
|
||||||
|
|
||||||
function toggleEdit() {
|
function toggleEdit() {
|
||||||
if (edit.value) {
|
if (edit.value) {
|
||||||
@@ -51,7 +53,7 @@
|
|||||||
if (weight.value != null && unit.value != null) {
|
if (weight.value != null && unit.value != null) {
|
||||||
let updateVariant: Variant = new Variant(props.variant.id, weight.value,
|
let updateVariant: Variant = new Variant(props.variant.id, weight.value,
|
||||||
ean.value, name.value, description.value, ingredients.value,
|
ean.value, name.value, description.value, ingredients.value,
|
||||||
unit.value, label.value, variant_description.value, topm_row.value);
|
unit.value, label.value, variant_description.value, topm_row.value, nutrition.value);
|
||||||
|
|
||||||
await store.updateVariant(updateVariant);
|
await store.updateVariant(updateVariant);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type {Variant} from "~/types/variant";
|
import type {Variant} from "~/types/variant";
|
||||||
import type {Origin} from "~/types/origin";
|
import type {Origin} from "~/types/origin";
|
||||||
import type {Unit} from "~/types/unit";
|
import type {Unit} from "~/types/unit";
|
||||||
|
import type {Nutritional} from "~/types/nutritional.ts";
|
||||||
|
|
||||||
export class Article {
|
export class Article {
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
@@ -17,11 +18,13 @@ export class Article {
|
|||||||
bio_info: string | null;
|
bio_info: string | null;
|
||||||
topm_id: string | null;
|
topm_id: string | null;
|
||||||
additional_name: string | null;
|
additional_name: string | null;
|
||||||
|
nutritional: Nutritional | null;
|
||||||
|
|
||||||
constructor(id: number, name: string, bio: boolean, origin: Origin, description: string | null,
|
constructor(id: number, name: string, bio: boolean, origin: Origin, description: string | null,
|
||||||
ingredients: string | null, default_unit: Unit, variants: Array<Variant> | null,
|
ingredients: string | null, default_unit: Unit, variants: Array<Variant> | null,
|
||||||
mhd: string | null, bio_origin: string | null, allergens_text: string | null,
|
mhd: string | null, bio_origin: string | null, allergens_text: string | null,
|
||||||
bio_info: string | null, topm_id: string | null, additional_name: string | null) {
|
bio_info: string | null, topm_id: string | null, additional_name: string | null,
|
||||||
|
nutritional: Nutritional | null) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.bio = bio;
|
this.bio = bio;
|
||||||
@@ -42,5 +45,6 @@ export class Article {
|
|||||||
this.bio_info = bio_info;
|
this.bio_info = bio_info;
|
||||||
this.topm_id = topm_id;
|
this.topm_id = topm_id;
|
||||||
this.additional_name = additional_name;
|
this.additional_name = additional_name;
|
||||||
|
this.nutritional = nutritional;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
export class Nutritional {
|
||||||
|
id: number;
|
||||||
|
calorific_value_kj: number;
|
||||||
|
calorific_value_kcal: number;
|
||||||
|
fat: number;
|
||||||
|
saturated_fat: number;
|
||||||
|
carbohydrates: number;
|
||||||
|
sugar: number;
|
||||||
|
fibers: number;
|
||||||
|
protein: number;
|
||||||
|
salt: number;
|
||||||
|
|
||||||
|
constructor(id: number, calorific_value_kj: number, calorific_value_kcal: number, fat: number,
|
||||||
|
saturated_fat: number, carbohydrates: number, sugar: number,
|
||||||
|
fibers: number, protein: number, salt: number) {
|
||||||
|
this.id = id;
|
||||||
|
this.calorific_value_kj = calorific_value_kj;
|
||||||
|
this.calorific_value_kcal = calorific_value_kcal;
|
||||||
|
this.fat = fat;
|
||||||
|
this.saturated_fat = saturated_fat;
|
||||||
|
this.carbohydrates = carbohydrates;
|
||||||
|
this.sugar = sugar;
|
||||||
|
this.fibers = fibers;
|
||||||
|
this.protein = protein;
|
||||||
|
this.salt = salt;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type {Unit} from "~/types/unit";
|
import type {Unit} from "~/types/unit";
|
||||||
import type {Label} from "~/types/label";
|
import type {Label} from "~/types/label";
|
||||||
|
import type {Nutritional} from "~/types/nutritional.ts";
|
||||||
|
|
||||||
export class Variant {
|
export class Variant {
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
@@ -12,10 +13,12 @@ export class Variant {
|
|||||||
label: Label | null;
|
label: Label | null;
|
||||||
variant_description: string | null;
|
variant_description: string | null;
|
||||||
topm_row: string | null;
|
topm_row: string | null;
|
||||||
|
nutritional: Nutritional | null;
|
||||||
|
|
||||||
constructor(id: number, weight: string, ean: string|null, name: string|null,
|
constructor(id: number, weight: string, ean: string|null, name: string|null,
|
||||||
description:string|null, ingredients: string|null, unit: Unit,
|
description:string|null, ingredients: string|null, unit: Unit,
|
||||||
label: Label | null, variant_description: string | null, topm_row: string | null) {
|
label: Label | null, variant_description: string | null, topm_row: string | null,
|
||||||
|
nutritional: Nutritional | null) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
this.ean = ean;
|
this.ean = ean;
|
||||||
@@ -26,5 +29,6 @@ export class Variant {
|
|||||||
this.label = label;
|
this.label = label;
|
||||||
this.variant_description = variant_description;
|
this.variant_description = variant_description;
|
||||||
this.topm_row = topm_row;
|
this.topm_row = topm_row;
|
||||||
|
this.nutritional = nutritional;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
+4
-24
@@ -18,7 +18,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite-plugin-vuetify": "2.1.3",
|
"vite-plugin-vuetify": "2.1.3",
|
||||||
"vuetify": "4.2.1"
|
"vuetify": "4.2.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
@@ -4082,16 +4082,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/cac": {
|
|
||||||
"version": "6.7.14",
|
|
||||||
"resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz",
|
|
||||||
"integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==",
|
|
||||||
"extraneous": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/caniuse-api": {
|
"node_modules/caniuse-api": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-4.0.0.tgz",
|
||||||
@@ -4216,16 +4206,6 @@
|
|||||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/commander": {
|
|
||||||
"version": "15.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-15.0.0.tgz",
|
|
||||||
"integrity": "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg==",
|
|
||||||
"extraneous": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=22.12.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/commondir": {
|
"node_modules/commondir": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
|
||||||
@@ -9791,9 +9771,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vuetify": {
|
"node_modules/vuetify": {
|
||||||
"version": "4.2.1",
|
"version": "4.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/vuetify/-/vuetify-4.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/vuetify/-/vuetify-4.2.2.tgz",
|
||||||
"integrity": "sha512-K3ZIqu7YkorQFB6//dR5KEBpbfOo+y/LkcGtknsnneE3JN1pW3R7o/JB9QDkJuP1ELhENIdBZIkiSmXu0dQ9lQ==",
|
"integrity": "sha512-6PYw9V5bA1ug+r1gWOs+ztMnz4qJDue3WLiz5VJN/y1blW9e/oeh0D8eCw7jqc8ufjm8XSN7hf6x2odJXtzw0Q==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vuetify/v0": "^1.2.1"
|
"@vuetify/v0": "^1.2.1"
|
||||||
|
|||||||
@@ -21,6 +21,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite-plugin-vuetify": "2.1.3",
|
"vite-plugin-vuetify": "2.1.3",
|
||||||
"vuetify": "4.2.1"
|
"vuetify": "4.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
-- Add migration script here
|
||||||
|
CREATE TABLE nutritional
|
||||||
|
(
|
||||||
|
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 ) Unique,
|
||||||
|
calorific_value_kj double precision DEFAULT 0 NOT NULL,
|
||||||
|
calorific_value_kcal double precision DEFAULT 0 NOT NULL,
|
||||||
|
fat double precision DEFAULT 0 NOT NULL,
|
||||||
|
saturated_fat double precision DEFAULT 0 NOT NULL,
|
||||||
|
carbohydrates double precision DEFAULT 0 NOT NULL,
|
||||||
|
sugar double precision DEFAULT 0 NOT NULL,
|
||||||
|
fibers double precision DEFAULT 0 NOT NULL,
|
||||||
|
protein double precision DEFAULT 0 NOT NULL,
|
||||||
|
salt double precision DEFAULT 0 NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE public.article
|
||||||
|
ADD nutritional_id bigint,
|
||||||
|
ADD CONSTRAINT article_nutritional_id_fkey
|
||||||
|
foreign key (nutritional_id)
|
||||||
|
references nutritional(id)
|
||||||
|
ON DELETE NO ACTION;
|
||||||
|
|
||||||
|
ALTER TABLE public.variant
|
||||||
|
ADD nutritional_id bigint,
|
||||||
|
ADD CONSTRAINT variant_nutritional_id_fkey
|
||||||
|
foreign key (nutritional_id)
|
||||||
|
references nutritional(id)
|
||||||
|
ON DELETE NO ACTION;
|
||||||
@@ -125,6 +125,7 @@ async fn get_article(
|
|||||||
bio_info: None,
|
bio_info: None,
|
||||||
topm_id: None,
|
topm_id: None,
|
||||||
additional_name: None,
|
additional_name: None,
|
||||||
|
nutritional: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(article))
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(article))
|
||||||
@@ -159,6 +160,7 @@ async fn create_article(
|
|||||||
bio_info: None,
|
bio_info: None,
|
||||||
topm_id: None,
|
topm_id: None,
|
||||||
additional_name: None,
|
additional_name: None,
|
||||||
|
nutritional: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(article))
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(article))
|
||||||
@@ -195,6 +197,7 @@ async fn update_article_route(
|
|||||||
bio_info: None,
|
bio_info: None,
|
||||||
topm_id: None,
|
topm_id: None,
|
||||||
additional_name: None,
|
additional_name: None,
|
||||||
|
nutritional: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(article))
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(article))
|
||||||
@@ -246,6 +249,7 @@ async fn add_variant(
|
|||||||
label: None,
|
label: None,
|
||||||
variant_description: None,
|
variant_description: None,
|
||||||
topm_row: None,
|
topm_row: None,
|
||||||
|
nutritional: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant))
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant))
|
||||||
@@ -278,6 +282,7 @@ async fn update_variant_route(
|
|||||||
label: None,
|
label: None,
|
||||||
variant_description: None,
|
variant_description: None,
|
||||||
topm_row: None,
|
topm_row: None,
|
||||||
|
nutritional: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant))
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant))
|
||||||
|
|||||||
Reference in new issue
Block a user