add shipment forms and start contract from form
This commit is contained in:
@@ -43,5 +43,4 @@ export type FormInputs = {
|
||||
end: string | null;
|
||||
productor_id: string;
|
||||
referer_id: string;
|
||||
shipments: ShipmentInputs[];
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import type { Product } from "./products";
|
||||
|
||||
export type Productor = {
|
||||
id: number;
|
||||
name: string;
|
||||
address: string;
|
||||
payment: string;
|
||||
type: string;
|
||||
products: Product[]
|
||||
}
|
||||
|
||||
export type ProductorCreate = {
|
||||
|
||||
@@ -19,42 +19,42 @@ export type Product = {
|
||||
id: number;
|
||||
productor: Productor;
|
||||
name: string;
|
||||
unit: number;
|
||||
unit: string;
|
||||
price: number;
|
||||
price_kg: number | null;
|
||||
weight: number;
|
||||
type: number;
|
||||
type: string;
|
||||
shipments: Shipment[];
|
||||
}
|
||||
|
||||
export type ProductCreate = {
|
||||
productor_id: number;
|
||||
name: string;
|
||||
unit: number;
|
||||
unit: string;
|
||||
price: number;
|
||||
price_kg: number | null;
|
||||
weight: number | null;
|
||||
type: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export type ProductEdit = {
|
||||
productor_id: number | null;
|
||||
name: string | null;
|
||||
unit: number | null;
|
||||
unit: string | null;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
weight: number | null;
|
||||
type: number | null;
|
||||
type: string | null;
|
||||
}
|
||||
|
||||
export type ProductInputs = {
|
||||
productor_id: number | null;
|
||||
productor_id: string | null;
|
||||
name: string;
|
||||
unit: number | null;
|
||||
unit: string | null;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
weight: number | null;
|
||||
type: number | null;
|
||||
type: string | null;
|
||||
}
|
||||
|
||||
export type ProductEditPayload = {
|
||||
@@ -64,7 +64,7 @@ export type ProductEditPayload = {
|
||||
|
||||
export function productToProductInputs(product: Product): ProductInputs {
|
||||
return {
|
||||
productor_id: product.productor.id,
|
||||
productor_id: String(product.productor.id),
|
||||
name: product.name,
|
||||
unit: product.unit,
|
||||
price: product.price,
|
||||
@@ -76,7 +76,7 @@ export function productToProductInputs(product: Product): ProductInputs {
|
||||
|
||||
export function productCreateFromProductInputs(productInput: ProductInputs): ProductCreate {
|
||||
return {
|
||||
productor_id: productInput.productor_id!,
|
||||
productor_id: Number(productInput.productor_id)!,
|
||||
name: productInput.name,
|
||||
unit: productInput.unit!,
|
||||
price: productInput.price!,
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
import type { Form } from "./forms";
|
||||
import type { Product } from "./products";
|
||||
|
||||
export type Shipment = {
|
||||
name: string;
|
||||
date: string;
|
||||
id: number;
|
||||
form: Form;
|
||||
form_id: number;
|
||||
products: Product[];
|
||||
}
|
||||
|
||||
export type ShipmentCreate = {
|
||||
name: string;
|
||||
date: string;
|
||||
form_id: number;
|
||||
product_ids: number[];
|
||||
}
|
||||
|
||||
export type ShipmentEdit = {
|
||||
name: string | null;
|
||||
date: string | null;
|
||||
form_id: number | null;
|
||||
product_ids: number[];
|
||||
}
|
||||
|
||||
export type ShipmentEditPayload = {
|
||||
@@ -25,6 +32,23 @@ export type ShipmentEditPayload = {
|
||||
export type ShipmentInputs = {
|
||||
name: string | null;
|
||||
date: string | null;
|
||||
id: number | null;
|
||||
form_id: number | null;
|
||||
form_id: string | null;
|
||||
product_ids: string[];
|
||||
}
|
||||
|
||||
export function shipmentToShipmentInputs(shipment: Shipment): ShipmentInputs {
|
||||
return {
|
||||
...shipment,
|
||||
form_id: String(shipment.form_id),
|
||||
product_ids: shipment.products.map((el) => (String(el.id)))
|
||||
};
|
||||
}
|
||||
|
||||
export function shipmentCreateFromShipmentInputs(shipmentInput: ShipmentInputs): ShipmentCreate {
|
||||
return {
|
||||
name: shipmentInput.name!,
|
||||
date: shipmentInput.date!,
|
||||
form_id: Number(shipmentInput.form_id),
|
||||
product_ids: shipmentInput.product_ids.map(el => (Number(el))),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user