Commit Graph

32 Commits

Author SHA1 Message Date
Adrian Flores Cortes
85043cbaff [SYNC-ERP-CORE] feat: Propagate middlewares, logger, DTOs and Swagger from erp-core
- Add logger utility (winston-based)
- Add apiKeyAuth middleware for API key authentication
- Add fieldPermissions middleware for field-level access control
- Add Swagger/OpenAPI configuration and integration
- Refactor DTOs with Zod validation schemas:
  - feature-flag.dto.ts
  - terminal.dto.ts
  - transaction.dto.ts
  - ai.dto.ts
- Add error classes (AppError, UnauthorizedError, ForbiddenError, etc.)
- Add AuthenticatedRequest type for erp-core compatibility
- Add ESLint configuration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 19:39:23 -06:00
Adrian Flores Cortes
11f8bc3ad0 [SYNC] test: Add service-order service tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 08:11:33 -06:00
Adrian Flores Cortes
f9ec80b037 [SYNC] feat: Add audit, MFA, and feature flags modules
- Add audit module with controllers, DTOs, middleware and services
- Add MFA controller, routes and services
- Add feature flags module with controllers, DTOs and services
- Update audit entities with proper TypeORM decorators
- Update auth service and DTOs
- Update main.ts configuration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 08:02:07 -06:00
Adrian Flores Cortes
e38d3c3864 [MMD-D-006] feat: Add backend unit tests
Added Jest configuration and unit tests:
- jest.config.js: Jest configuration with ts-jest
- setup.ts: Global test setup with custom matchers

Test files (30 tests passing):
- service-order.service.test.ts: CRUD, status transitions, cost calculation
- diagnostic.service.test.ts: CRUD, OBD codes, completion workflow
- part.service.test.ts: CRUD, stock management, low stock alerts
- vehicle.service.test.ts: CRUD, VIN validation, odometer updates

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 05:03:12 -06:00
Adrian Flores Cortes
65c42663f0 [SPRINT-4] feat(service-management): Add ServiceOrderService business logic
- Add getCostBreakdown() for order cost calculation
- Add getOrderHistory() for change tracking
- Add assignTechnician() for mechanic assignment
- Add addDiscount() for order-level discounts
- Add updatePriority() for priority management
- Add searchOrders() with multi-field search
- Export new DTOs: ServiceContext, CostBreakdown, OrderHistoryEntry

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 02:46:49 -06:00
Adrian Flores Cortes
3a21a5a0fc [SPRINT-4] feat(parts-management): Implement complete PartsService business logic
- Add checkStock() with available stock calculation considering reservations
- Add reserveParts() with atomic transaction and pessimistic locking
- Add updateInventory() supporting ENTRADA, SALIDA, AJUSTE, TRANSFERENCIA
- Add calculateReorderPoint() with 90-day consumption analysis
- Add getPartCompatibility() with alternate parts lookup
- Add getLowStockParts() with criticality ranking (critical/warning/low)
- Update controller to use enhanced low-stock endpoint
- Export new DTOs: UpdateInventoryDto, ServiceContext, StockCheckResult,
  PartReservation, ReorderPointResult, PartCompatibilityResult, LowStockPart

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 02:46:00 -06:00
Adrian Flores Cortes
71efafd139 [SPRINT-4] feat: Fleet maintenance and document management services
- Add MaintenanceReminderService (420 lines, 11 methods)
  - Create, pause, resume, complete maintenance reminders
  - Find due and overdue reminders
  - Vehicle-specific statistics
- Add MaintenanceScheduleService (677 lines, 8 methods)
  - Generate maintenance schedules
  - Cost estimation and calendar views
  - Fleet-wide statistics
- Add VehicleDocumentService (448 lines, 11 methods)
  - Document lifecycle management
  - Expiration tracking and alerts
  - Fleet document status summary
- Add VehicleDocument entity with status tracking

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 01:35:51 -06:00
Adrian Flores Cortes
74027be804 [SPRINT-3] feat: Work execution and inventory management services
- Add work-execution.service.ts (701 lines, 10+ methods)
  - Work lifecycle management (start, pause, complete)
  - Part consumption tracking and reservation
  - Time tracking with pause/resume
  - Quality control integration
- Add warehouse-entry.service.ts for inventory entries
- Add stock-alert.service.ts for minimum stock alerts
- Add inventory-movement.entity.ts for kardex tracking
- Add stock-alert.entity.ts for alert management
- Enhance part.service.ts with new inventory methods

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 01:15:27 -06:00
Adrian Flores Cortes
b455de93b2 feat(service-management): Implement Sprint 2 service order workflow
Sprint 2 - S2-T03, S2-T04, S2-T05

New services:
- VehicleReceptionService: Vehicle reception workflow
  - receiveVehicle, createQuickReception
  - getReceptionForm, validateVehiclePlate
  - Work bay management
  - Reception statistics

- DiagnosticService (enhanced): Complete diagnostic workflow
  - createDiagnostic with order status update
  - addScannerResults with DTC code parsing
  - completeDiagnostic with quote trigger
  - generateDiagnosticReport
  - 70+ diesel DTC codes database

- QuoteService (enhanced): Full quotation workflow
  - createQuote, addQuoteItem, updateQuoteItem
  - recalculateQuoteTotals (16% IVA)
  - sendQuoteToCustomer, customerResponse
  - convertToOrder

New entities:
- QuoteItem entity for quote line items

Fix: rbac.middleware.ts - Use role (singular) instead of roles

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 00:28:03 -06:00
Adrian Flores Cortes
f4ed131c1e [RBAC-005] feat: Propagate RBAC middleware from erp-core
- Add rbac.middleware.ts with requirePerm, requireAnyPerm, requireAllPerms, requireAccess, requirePermOrOwner
- Add shared middleware index exports
- Configure diesel-specific roles (manager, technician, admin, super_admin)

Propagated from erp-core TASK-2026-01-30-RBAC

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 14:58:25 -06:00
Adrian Flores Cortes
497307ed04 feat: Add roles, permissions, and company entities to auth
Entities added from erp-construccion:
- role.entity.ts
- permission.entity.ts
- user-role.entity.ts
- session.entity.ts
- api-key.entity.ts
- password-reset.entity.ts
- company.entity.ts
- group.entity.ts
- index.ts (new)

Build: Clean (0 TypeScript errors)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 09:17:23 -06:00
Adrian Flores Cortes
8c010221fb feat: Propagate core entities from erp-construccion
Modules added:
- audit (7 entities): audit logs, config changes, entity changes
- billing-usage (14 entities): subscriptions, invoices, coupons
- core (13 entities): countries, currencies, UoMs, sequences
- invoices (4 entities): invoices, payments, allocations
- notifications (6 entities): notifications, templates, channels

Total: 44 new entity files
Build: Clean (0 TypeScript errors)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 09:06:11 -06:00
Adrian Flores Cortes
a0ca2bd77a fix: Resolve TypeScript build errors
- Replace class-validator with plain TypeScript interfaces in AI DTOs
- Fix AIModel field names (inputCostPer1k instead of inputCostPer1m)
- Fix AIUsageLog field mapping (promptTokens, completionTokens, cost)
- Add 'branches', 'financial', 'sales' to MCP ToolCategory
- Add branchId to McpContext interface
- Create stub entities for BranchPaymentTerminal and PaymentTransaction
- Create CircuitBreaker utility for payment transactions
- Create database config and error classes for base.service.ts
- Fix type assertions for fetch response.json() calls
- Align PaymentStatus and PaymentMethod types between entities and DTOs
- Add @types/pg dependency

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 07:54:42 -06:00
Adrian Flores Cortes
dad6575a3c feat(MMD-012): Implement Field Service module
- Add 11 entities: ServiceChecklist, ChecklistItemTemplate, ChecklistResponse, ChecklistItemResponse, WorkLog, DiagnosisRecord, ActivityCatalog, RootCauseCatalog, FieldEvidence, FieldCheckin, OfflineQueueItem
- Add 5 services: ChecklistService, WorkLogService, DiagnosisService, OfflineSyncService, CheckinService
- Add 5 controllers: ChecklistController, WorkLogController, DiagnosisController, SyncController, CheckinController
- Integrate module in main.ts with routes under /api/v1/field/*

Features:
- Configurable checklists with multiple item types
- Labor time tracking with pause/resume
- Diagnosis with OBD-II code parsing
- Offline sync queue with conflict resolution
- Technician check-in/check-out with geolocation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:43:03 -06:00
Adrian Flores Cortes
7e0d4ee841 feat(MMD-011): Implement Dispatch Center module
Add complete dispatch module for incident assignment:

Entities (7):
- DispatchBoard: Board configuration
- UnitStatus: Real-time unit state
- TechnicianSkill: Skills and certifications
- TechnicianShift: Shift schedules
- DispatchRule: Assignment rules
- EscalationRule: Escalation rules
- DispatchLog: Audit trail

Services (4):
- DispatchService: Unit management, assignments, suggestions
- SkillService: Skill CRUD, validation, matrix
- ShiftService: Shift management, availability
- RuleService: Dispatch and escalation rules

Controllers (4):
- DispatchController: /api/v1/dispatch
- SkillController: /api/v1/dispatch/skills
- ShiftController: /api/v1/dispatch/shifts
- RuleController: /api/v1/dispatch/rules

Integrated in main.ts with routes and documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:21:40 -06:00
Adrian Flores Cortes
89948663e9 feat(MMD-013): Implement Asset Management module
- 6 entities: Asset, AssetCategory, AssetAssignment, AssetAudit, AssetAuditItem, AssetMaintenance
- 4 services with CRUD, assignment, audit, and maintenance operations
- 4 controllers with REST endpoints
- Integration in main.ts with routes registration
- Multi-tenant support with RLS

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 01:44:58 -06:00
Adrian Flores Cortes
b927bafeb0 feat(MMD-014): Implement GPS module backend
- Add 5 entities: GpsDevice, GpsPosition, Geofence, GeofenceEvent, RouteSegment
- Add 4 services with full business logic
- Add 4 controllers with REST endpoints
- Integrate GPS module into main.ts
- Endpoints: /api/v1/gps/devices, positions, geofences, routes
- Features: device management, position tracking, geofencing, route calculation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 01:33:59 -06:00
Adrian Flores Cortes
e3baa0a480 chore: Update package-lock.json
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 14:10:42 -06:00
Adrian Flores Cortes
f74f713482 [MMD-010] feat: Add FiadosService module for customer credit management
- Create fiados module with 3 entities:
  - CustomerCreditAccount: Credit accounts per customer
  - Fiado: Individual credit sales (fiados)
  - FiadoPayment: Payment/abono tracking
- Implement FiadosService with full business logic:
  - Credit eligibility checking
  - Fiado creation with automatic due dates
  - Payment registration with FIFO allocation
  - Overdue tracking and account freezing
- Connect FiadosToolsService to real FiadosService
- Update MCP module registration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 08:22:28 -06:00
Adrian Flores Cortes
e26ab24aa5 feat: Connect MCP tools to real services
Analytics Module:
- Created AnalyticsService with sales/financial reporting
- Supports sales summary, reports, top products/customers, KPIs
- Uses analytics schema and service_management tables

MCP Tools Connected:
- products-tools → PartService (real inventory data)
- sales-tools → AnalyticsService (real sales analytics)
- financial-tools → AnalyticsService (real P&L and KPIs)

Updated tool registry to pass DataSource to connected tools.

MCP Tools Status:
- orders-tools: Connected to ServiceOrderService
- inventory-tools: Connected to PartService
- customers-tools: Connected to CustomersService
- products-tools: Connected to PartService (NEW)
- sales-tools: Connected to AnalyticsService (NEW)
- financial-tools: Connected to AnalyticsService (NEW)
- fiados-tools: Mock (needs FiadosService)
- branch-tools: Mock (single tenant)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 07:56:10 -06:00
Adrian Flores Cortes
eefbc8a7cd [SYNC] Synchronize mcp module from erp-core canonical
Source: erp-core (checksum: 9c067e47e556cc79e29a85923f8fe65b)
Priority: P1 - HIGH
Context: TASK-2026-01-25-SISTEMA-REUTILIZACION

Before: Diverged version
After: Synced with canonical

Changes:
- Complete mcp module synchronized from erp-core
- MCP Server integration unified
- Tool registry and logging standardized
- Consistent MCP protocol implementation

Benefits:
- Single source of truth for MCP functionality
- Unified Claude AI integration via MCP
- Reduced maintenance burden (~500 lines per project)
- Following erp-construccion example (already synced)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 07:02:31 -06:00
Adrian Flores Cortes
5842d2003e [SYNC] Synchronize payment-terminals module from erp-core canonical
Source: erp-core (checksum: c9040e545cf55beb87d3e437a4998855)
Priority: P1 - HIGH
Context: TASK-2026-01-25-SISTEMA-REUTILIZACION

Before: Diverged version (one of 3 different versions)
After: Synced with canonical

Changes:
- Complete payment-terminals module synchronized from erp-core
- 21 TypeScript files updated
- Unified payment terminal integration (MercadoPago + Clip)
- Consistent webhook handling across all ERP projects

Benefits:
- Single source of truth for payment terminals functionality
- Consistent TPV integration behavior
- Reduced maintenance burden (~4,000 lines saved)
- Unified webhook processing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 06:52:13 -06:00
Adrian Flores Cortes
63be8167bf [ADD] BaseService propagated from erp-core canonical
Source: erp-core (checksum: 900be2ee48f2faf72ce5253aeab27c88)
Priority: P1 - HIGH (architectural gap resolution)
Context: TASK-2026-01-25-SISTEMA-REUTILIZACION

Before: "Missing"
After: Synced with canonical

Changes:
- BaseService "added" from erp-core
- Checksum: 900be2ee48f2faf72ce5253aeab27c88
- Provides base CRUD operations for all services

Benefits:
- Unified service architecture
- Consistent error handling and validation
- Reduced code duplication in service implementations
- Standard pagination and filtering patterns

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 06:43:32 -06:00
Adrian Flores Cortes
e7b68b4558 [SYNC] Synchronize ai module from erp-core canonical
Source: erp-core (checksum: 39a6e229055a21158b63cc4eb4dd232f)
Priority: P0 - CRITICAL divergence resolution
Context: TASK-2026-01-25-SISTEMA-REUTILIZACION

Before: Diverged version with project-specific adaptations
After: Synced with canonical

Changes:
- Complete ai module synchronized from erp-core
- 24 TypeScript files updated
- Unified role-based AI configuration
- Consistent AI behavior across all ERP projects

Note: Project-specific role adaptations (if needed) can be
re-applied as documented extensions after this sync.

Benefits:
- Single source of truth for AI functionality
- Reduced maintenance burden
- Token savings from code reuse
- Consistent behavior baseline

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 06:36:16 -06:00
Adrian Flores Cortes
d5f1453492 [MCP] feat: Connect MCP tools to actual services
- orders-tools.service.ts → ServiceOrderService (6 tools)
  - create_service_order, get_service_order, list_service_orders
  - update_order_status, get_orders_kanban, get_orders_dashboard
- inventory-tools.service.ts → PartService (8 tools)
  - search_parts, get_part_details, check_stock
  - get_low_stock_parts, adjust_stock, get_inventory_value
  - create_part, list_parts
- customers-tools.service.ts → CustomersService (6 tools)
  - search_customers, get_customer, create_customer
  - update_customer, list_customers, get_customer_stats

Removed mock data, now using real database operations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 05:25:16 -06:00
Adrian Flores Cortes
669c0c2911 [PROP-CORE-004] feat: Register payment-terminals module in app
- Added PaymentTerminalsModule and entities imports
- Added entities to TypeORM DataSource
- Registered routes: /api/v1/payment-terminals, /api/v1/mercadopago, /api/v1/clip
- Registered webhooks: /webhooks/mercadopago, /webhooks/clip
- Updated API info with new endpoints

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 03:13:51 -06:00
Adrian Flores Cortes
db63fd17c9 [PROP-CORE-004] fix: Remove external entity references from payment-terminals
Fixed getEntities() to only reference own entities, avoiding require errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 03:08:31 -06:00
Adrian Flores Cortes
940095a170 [PROP-CORE-004] feat: Adapt AI roles for diesel mechanics domain
- Roles: ADMIN, JEFE_TALLER, MECANICO, CLIENTE
- Domain-specific tools (diagnostics, vehicles, OBD codes)
- Automotive workshop terminology

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 02:57:51 -06:00
Adrian Flores Cortes
5c7134cc03 [PROP-CORE-004] feat: Add Phase 6 modules from erp-core
Propagated modules:
- payment-terminals: MercadoPago + Clip TPV
- ai: Role-based AI access (ADMIN, JEFE_TALLER, MECANICO, CLIENTE)
- mcp: 18 ERP tools for AI assistants

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 02:45:37 -06:00
ceb6363bfd chore: Add .gitignore for clean repository
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 07:31:50 -06:00
8ed7d24e96 Migración desde erp-mecanicas-diesel/backend - Estándar multi-repo v2
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:11:24 -06:00
13cedb2959 Initial commit 2026-01-16 14:04:56 +00:00