Files
Zumri-Backend/migrations/20260909080000-phase-8-delivery-riders.js
Sathira Sri Sathara 222483d194
CI / test (push) Successful in 10m26s
feat: Implement Phase 8 Delivery and Rider Management
- Introduced new Delivery and Rider API documentation.
- Added new models for RiderProfile, Shipment, ShipmentItem, ShipmentAssignment, ShipmentEvent, and ShipmentProof.
- Developed controllers for admin and rider logistics, including shipment management and rider actions.
- Created services for handling shipment creation, assignment, and state transitions.
- Implemented validation schemas for shipment and rider operations.
- Added new routes for admin and rider logistics, including tracking endpoints.
- Established a state machine for shipment status transitions.
- Created migration scripts for new database tables and relationships.
- Added unit tests for shipment state transitions and validation security.
2026-09-09 12:55:32 +05:30

2 lines
3.0 KiB
JavaScript

"use strict";module.exports={async up(q,S){const ID={type:S.STRING,primaryKey:true,allowNull:false},REQ={type:S.STRING,allowNull:false},STR={type:S.STRING},DATE={type:S.DATE},INT={type:S.INTEGER,allowNull:false,defaultValue:0},TS={createdAt:{type:S.DATE,allowNull:false},updatedAt:{type:S.DATE,allowNull:false}};await q.createTable("rider_profiles",{id:ID,user_id:{type:S.STRING,allowNull:false,unique:true},employee_code:{type:S.STRING(60),allowNull:false,unique:true},phone_override:STR,vehicle_type:STR,vehicle_registration:STR,status:REQ,availability_status:REQ,current_latitude:{type:S.DECIMAL(10,7)},current_longitude:{type:S.DECIMAL(10,7)},last_location_at:DATE,max_active_assignments:{type:S.INTEGER,allowNull:false,defaultValue:1},...TS});await q.addIndex("rider_profiles",["status","availability_status"]);await q.createTable("shipments",{id:ID,shipment_number:{type:S.STRING(80),allowNull:false,unique:true},order_id:STR,return_request_id:STR,type:REQ,status:REQ,shipping_method_code:STR,shipping_method_name:STR,recipient_name:REQ,recipient_phone:REQ,address_snapshot:{type:S.JSON,allowNull:false},assigned_rider_id:STR,assigned_at:DATE,picked_up_at:DATE,out_for_delivery_at:DATE,delivered_at:DATE,failed_at:DATE,cancelled_at:DATE,scheduled_date:DATE,time_window_start:STR,time_window_end:STR,delivery_attempt_count:INT,notes:{type:S.STRING(500)},...TS});for(const fields of [["order_id"],["return_request_id"],["status"],["assigned_rider_id"],["createdAt"]])await q.addIndex("shipments",fields);await q.addConstraint("shipments",{fields:["return_request_id","type"],type:"unique",name:"uq_return_pickup_shipment"});await q.createTable("shipment_items",{id:ID,shipment_id:REQ,order_item_id:REQ,quantity:{type:S.INTEGER,allowNull:false},...TS});await q.addConstraint("shipment_items",{fields:["shipment_id","order_item_id"],type:"unique",name:"uq_shipment_order_item"});await q.createTable("shipment_assignments",{id:ID,shipment_id:REQ,rider_id:REQ,status:REQ,assigned_by:REQ,assigned_at:{type:S.DATE,allowNull:false},accepted_at:DATE,rejected_at:DATE,unassigned_at:DATE,completed_at:DATE,reason:{type:S.STRING(500)},...TS});await q.addIndex("shipment_assignments",["shipment_id","status"]);await q.addIndex("shipment_assignments",["rider_id","status"]);await q.createTable("shipment_events",{id:ID,shipment_id:REQ,event_id:{type:S.STRING(160),allowNull:false,unique:true},type:REQ,status:REQ,actor_user_id:STR,latitude:{type:S.DECIMAL(10,7)},longitude:{type:S.DECIMAL(10,7)},note:{type:S.STRING(500)},occurred_at:{type:S.DATE,allowNull:false},createdAt:{type:S.DATE,allowNull:false}});await q.addIndex("shipment_events",["shipment_id","occurred_at"]);await q.createTable("shipment_proofs",{id:ID,shipment_id:REQ,event_id:{type:S.STRING(160),allowNull:false,unique:true},type:REQ,recipient_name:STR,signature_upload_id:{type:S.INTEGER},photo_upload_id:{type:S.INTEGER},notes:{type:S.STRING(500)},captured_at:{type:S.DATE,allowNull:false},captured_by:REQ,...TS});},async down(){throw new Error("Phase 8 migration is forward-only; restore from a verified backup instead");}};