feat: repositorios, servicios, UI completa con rutas, Capacitor Android sync

This commit is contained in:
mono
2026-10-24 21:11:50 -05:00
parent 0c7cf651ce
commit df3838c2f3
36 changed files with 4224 additions and 402 deletions

View File

@@ -1 +1,2 @@
export * from './db/schema';
export * from './repositories';

View File

@@ -0,0 +1,22 @@
import { db } from '../db/schema';
import type { Ajuste } from '@toldo/core';
import { validateAjusteMotivo } from '@toldo/core';
export class AjusteRepository {
async create(ajuste: Ajuste): Promise<string> {
validateAjusteMotivo(ajuste.motivo);
return db.ajustes.add(ajuste);
}
async getAll(): Promise<Ajuste[]> {
return db.ajustes.toArray();
}
async getByFecha(fecha: Date): Promise<Ajuste[]> {
const start = new Date(fecha);
start.setHours(0, 0, 0, 0);
const end = new Date(fecha);
end.setHours(23, 59, 59, 999);
return db.ajustes.where('fecha').between(start, end).toArray();
}
}

View File

@@ -0,0 +1,20 @@
import { db } from '../db/schema';
import type { CuadreCaja } from '@toldo/core';
export class CuadreRepository {
async create(cuadre: CuadreCaja): Promise<string> {
return db.cuadres.add(cuadre);
}
async getByFecha(fecha: Date): Promise<CuadreCaja[]> {
const start = new Date(fecha);
start.setHours(0, 0, 0, 0);
const end = new Date(fecha);
end.setHours(23, 59, 59, 999);
return db.cuadres.where('fecha').between(start, end).toArray();
}
async getAll(): Promise<CuadreCaja[]> {
return db.cuadres.toArray();
}
}

View File

@@ -0,0 +1,20 @@
import { db } from '../db/schema';
import type { Gasto } from '@toldo/core';
export class GastoRepository {
async create(gasto: Gasto): Promise<string> {
return db.gastos.add(gasto);
}
async getByFecha(fecha: Date): Promise<Gasto[]> {
const start = new Date(fecha);
start.setHours(0, 0, 0, 0);
const end = new Date(fecha);
end.setHours(23, 59, 59, 999);
return db.gastos.where('fecha').between(start, end).toArray();
}
async getAll(): Promise<Gasto[]> {
return db.gastos.toArray();
}
}

View File

@@ -0,0 +1,16 @@
import { db } from '../db/schema';
import type { MovimientoInventario } from '@toldo/core';
export class MovimientoInventarioRepository {
async create(mov: MovimientoInventario): Promise<string> {
return db.movimientosInventario.add(mov);
}
async getByProducto(productoId: string): Promise<MovimientoInventario[]> {
return db.movimientosInventario.where('productoId').equals(productoId).toArray();
}
async getAll(): Promise<MovimientoInventario[]> {
return db.movimientosInventario.toArray();
}
}

View File

@@ -0,0 +1,30 @@
import { db } from '../db/schema';
import type { Producto } from '@toldo/core';
export class ProductoRepository {
async getAll(): Promise<Producto[]> {
return db.productos.toArray();
}
async getByProductor(productorId: string): Promise<Producto[]> {
return db.productos.where('productorId').equals(productorId).toArray();
}
async getById(id: string): Promise<Producto | undefined> {
return db.productos.get(id);
}
async create(producto: Producto): Promise<string> {
// Ensure uniqueness by (productorId, nombrePresentacion)
const exists = await db.productos
.where('[productorId+nombrePresentacion]')
.equals([producto.productorId, producto.nombrePresentacion])
.first();
if (exists) throw new Error('Ya existe un producto con ese nombre para este productor');
return db.productos.add(producto);
}
async update(producto: Producto): Promise<number> {
return db.productos.put(producto);
}
}

View File

@@ -0,0 +1,24 @@
import { db } from '../db/schema';
import type { Productor } from '@toldo/core';
export class ProductorRepository {
async getAll(): Promise<Productor[]> {
return db.productores.toArray();
}
async getById(id: string): Promise<Productor | undefined> {
return db.productores.get(id);
}
async create(productor: Productor): Promise<string> {
return db.productores.add(productor);
}
async update(productor: Productor): Promise<number> {
return db.productores.put(productor);
}
async delete(id: string): Promise<void> {
return db.productores.delete(id);
}
}

View File

@@ -0,0 +1,24 @@
import { db } from '../db/schema';
import type { Venta, VentaLinea } from '@toldo/core';
export class VentaRepository {
async create(venta: Venta, lineas: VentaLinea[]): Promise<string> {
return db.transaction('rw', db.ventas, db.ventaLineas, async () => {
await db.ventas.add(venta);
await db.ventaLineas.bulkAdd(lineas);
return venta.id;
});
}
async getByFecha(fecha: Date): Promise<Venta[]> {
const start = new Date(fecha);
start.setHours(0, 0, 0, 0);
const end = new Date(fecha);
end.setHours(23, 59, 59, 999);
return db.ventas.where('fecha').between(start, end).toArray();
}
async getAll(): Promise<Venta[]> {
return db.ventas.toArray();
}
}

View File

@@ -0,0 +1,7 @@
export * from './ProductorRepository';
export * from './ProductoRepository';
export * from './VentaRepository';
export * from './GastoRepository';
export * from './AjusteRepository';
export * from './MovimientoInventarioRepository';
export * from './CuadreRepository';