Aplanados productos en admin y pedido + movidos tipos y logica compartida a comunes.ts

This commit is contained in:
Alejandro Tasistro 2025-07-08 20:45:59 -03:00
parent 35e1d6455e
commit dd463a6a79
5 changed files with 66 additions and 34 deletions

View file

@ -0,0 +1,53 @@
export interface ProductoResponse {
id: number,
fila: number,
nombre: string,
precio: number,
categoria: string,
bono: boolean,
created_at: Date,
updated_at: Date,
requiere_notas: boolean,
es_solidario: boolean,
pivot: {
subpedido_id: number,
producto_id: number,
notas: string,
cantidad: number,
total: number,
}
}
export interface Producto {
id: number,
fila: number,
nombre: string,
precio: number,
categoria: string,
bono: boolean,
created_at: Date,
updated_at: Date,
requiere_notas: boolean,
es_solidario: boolean,
notas: string,
cantidad: number,
total: number,
}
export function aplanarProducto(producto: ProductoResponse): Producto {
return {
id: producto.id,
fila: producto.fila,
nombre: producto.nombre,
precio: producto.precio,
categoria: producto.categoria,
bono: producto.bono,
created_at: producto.created_at,
updated_at: producto.updated_at,
requiere_notas: producto.requiere_notas,
es_solidario: producto.es_solidario,
notas: producto.pivot.notas,
cantidad: producto.pivot.cantidad,
total: producto.pivot.total,
};
}

View file

@ -1,5 +1,6 @@
import axios from "axios";
import { AdminState } from "./types";
import { aplanarProducto } from "../../comunes";
const state: AdminState = {
lastFetch: undefined,
@ -20,11 +21,16 @@ const state: AdminState = {
const mutations = {
setState(state: AdminState, { grupo_de_compra }) {
const aplanarProductos = (pedido) => {
pedido.productos = pedido.productos.map(p => aplanarProducto(p));
return pedido;
};
state.lastFetch = new Date();
state.grupo_de_compra_id = grupo_de_compra.id;
state.nombre = grupo_de_compra.nombre;
state.devoluciones_habilitadas = grupo_de_compra.devoluciones_habilitadas;
state.pedidos = grupo_de_compra.pedidos;
state.pedidos = grupo_de_compra.pedidos.map(p => aplanarProductos(p));
state.total_a_recaudar = grupo_de_compra.total_a_recaudar;
state.total_sin_devoluciones = grupo_de_compra.total_sin_devoluciones;
state.total_barrial = grupo_de_compra.total_barrial;

View file

@ -1,3 +1,5 @@
import { Producto } from "../../comunes";
export interface AdminState extends Barrio {
lastFetch?: Date
}
@ -29,19 +31,3 @@ export interface Pedido {
devoluciones_total: number,
devoluciones_notas: string
}
export interface Producto {
id: number,
fila: number,
nombre: string,
precio: number,
categoria: string,
bono: boolean,
created_at: Date,
updated_at: Date,
requiere_notas: boolean,
es_solidario: boolean,
notas: string,
cantidad: number,
total: number,
}

View file

@ -1,5 +1,6 @@
import axios from "axios";
import { PedidoState } from "./types";
import { aplanarProducto } from "../../comunes";
const state: PedidoState = {
lastFetch: undefined,
@ -24,7 +25,7 @@ const mutations = {
state.lastFetch = new Date();
state.pedido_id = pedido.id;
state.nombre = pedido.nombre;
state.productos = pedido.productos;
state.productos = pedido.productos.map(p => aplanarProducto(p));
state.aprobado = pedido.aprobado;
state.total = pedido.total;
state.total_transporte = pedido.total_transporte;

View file

@ -1,3 +1,5 @@
import { Producto } from "../../comunes";
export interface PedidoState {
lastFetch?: Date,
grupo_de_compra?: Barrio,
@ -18,19 +20,3 @@ export interface Barrio {
nombre: string,
devoluciones_habilitadas: boolean,
}
export interface Producto {
id: number,
fila: number,
nombre: string,
precio: number,
categoria: string,
bono: boolean,
created_at: Date,
updated_at: Date,
requiere_notas: boolean,
es_solidario: boolean,
cantidad: number,
total: number,
notas: string,
}