add products

This commit is contained in:
Julien Aldon
2026-02-12 17:39:53 +01:00
parent 025b78d5dd
commit 1a98957466
12 changed files with 129 additions and 75 deletions

View File

@@ -1,34 +1,48 @@
import { t } from "@/config/i18n";
import type { Productor } from "@/services/resources/productors";
import type { Shipment } from "@/services/resources/shipments";
export const ProductType = [
"none",
t("planned"),
t("reccurent"),
];
export const ProductUnit = [
"none",
t("grams"),
t("kilo"),
t("piece"),
];
export type Product = {
id: number;
productor: Productor;
name: string;
unit: number;
price: number;
priceKg: number | null;
price_kg: number | null;
weight: number;
type: number;
shipments: Shipment[];
}
export type ProductCreate = {
productor_id: Productor;
productor_id: number;
name: string;
unit: number;
price: number;
priceKg: number | null;
weight: number;
price_kg: number | null;
weight: number | null;
type: number;
}
export type ProductEdit = {
productor_id: Productor | null;
productor_id: number | null;
name: string | null;
unit: number | null;
price: number | null;
priceKg: number | null;
price_kg: number | null;
weight: number | null;
type: number | null;
}
@@ -38,12 +52,36 @@ export type ProductInputs = {
name: string;
unit: number | null;
price: number | null;
priceKg: number | null;
price_kg: number | null;
weight: number | null;
type: string;
type: number | null;
}
export type ProductEditPayload = {
product: ProductEdit;
id: number;
}
export function productToProductInputs(product: Product): ProductInputs {
return {
productor_id: product.productor.id,
name: product.name,
unit: product.unit,
price: product.price,
price_kg: product.price_kg,
weight: product.weight,
type: product.type,
};
}
export function productCreateFromProductInputs(productInput: ProductInputs): ProductCreate {
return {
productor_id: productInput.productor_id!,
name: productInput.name,
unit: productInput.unit!,
price: productInput.price!,
price_kg: productInput.price_kg,
weight: productInput.weight,
type: productInput.type!,
}
}