| const axios = require('axios'); |
| const { PrismaClient } = require('@prisma/client'); |
| const prisma = new PrismaClient(); |
|
|
| async function verifyAll() { |
| console.log("--- STARTING END-TO-END VERIFICATION ---"); |
|
|
| try { |
| |
| const company = await prisma.courierCompany.findFirst(); |
| let courierCompanyId; |
| if (!company) { |
| console.log("No courier company found. Creating one..."); |
| const c = await prisma.courierCompany.create({ |
| data: { name: "EcoLogiq Logistics", code: "ECO001" } |
| }); |
| courierCompanyId = c.id; |
| } else { |
| courierCompanyId = company.id; |
| } |
|
|
| |
| await prisma.user.updateMany({ data: { courierCompanyId } }); |
| await prisma.truck.updateMany({ data: { courierCompanyId, isAvailable: true, registrationStatus: 'APPROVED' } }); |
| await prisma.delivery.updateMany({ data: { courierCompanyId, status: 'PENDING' } }); |
|
|
| console.log(`Using Courier Company: ${courierCompanyId}`); |
|
|
| |
| console.log("Creating pending deliveries for allocation..."); |
| const dispatcher = await prisma.user.findFirst({ where: { role: 'DISPATCHER' } }); |
| const shipper = await prisma.user.findFirst({ where: { role: 'SHIPPER' } }); |
|
|
| await prisma.delivery.updateMany({ |
| where: { status: 'COMPLETED' }, |
| data: { status: 'PENDING' } |
| }); |
|
|
| const delCount = await prisma.delivery.count({ where: { courierCompanyId, status: 'PENDING' } }); |
| const truckCount = await prisma.truck.count({ where: { courierCompanyId, isAvailable: true, registrationStatus: 'APPROVED' } }); |
| console.log(`Pending Deliveries found: ${delCount}`); |
| console.log(`Available Trucks found: ${truckCount}`); |
|
|
| |
| console.log("Triggering Route Allocation Logic..."); |
| |
| |
|
|
| |
| const routeController = require('../controllers/routeController'); |
| const req = { body: { courierCompanyId } }; |
| const res = { |
| status: (code) => ({ |
| json: (data) => { |
| console.log(`Allocation Response (${code}):`, data.message); |
| } |
| }) |
| }; |
|
|
| await routeController.allocateRoutes(req, res); |
|
|
| |
| const routes = await prisma.optimizedRoute.findMany({ |
| where: { courierCompanyId }, |
| include: { deliveries: true } |
| }); |
| console.log(`Routes created: ${routes.length}`); |
|
|
| if (routes.length >= 2) { |
| console.log("Triggering Proximity Check..."); |
| const synergyController = require('../controllers/synergyController'); |
| const truckA = await prisma.truck.findFirst({ where: { id: routes[0].truckId } }); |
| const hub = await prisma.virtualHub.findFirst(); |
|
|
| |
| await prisma.truck.update({ |
| where: { id: routes[0].truckId }, |
| data: { currentLat: 19.076, currentLng: 72.8777 } |
| }); |
| await prisma.truck.update({ |
| where: { id: routes[1].truckId }, |
| data: { currentLat: 19.077, currentLng: 72.8778 } |
| }); |
|
|
| |
| await prisma.optimizedRoute.updateMany({ data: { status: 'ACTIVE' } }); |
|
|
| const ioMock = { emit: (event, data) => console.log(`Socket Event [${event}]:`, data) }; |
| const opportunity = await synergyController.detectAbsorptionOpportunity(truckA.id, 19.076, 72.8777, ioMock); |
|
|
| if (opportunity) { |
| console.log(`Opportunity Created: ${opportunity.id}`); |
| console.log("VERIFICATION SUCCESSFUL"); |
| } else { |
| console.log("Opportunity not detected. Check proximity logs."); |
| } |
| } |
|
|
| } catch (err) { |
| console.error("Verification failed:", err); |
| } finally { |
| await prisma.$disconnect(); |
| } |
| } |
|
|
| verifyAll(); |
|
|