feat(loads::events): Adding date change events
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
}
|
||||
},
|
||||
"version" : {
|
||||
"version" : "1.5.6",
|
||||
"version" : "1.5.7",
|
||||
"name": "ETA Beta",
|
||||
"date":"22/07/2025"
|
||||
},
|
||||
|
||||
@@ -77,7 +77,7 @@ async function onDelivered( userId, elementId ){
|
||||
}
|
||||
|
||||
/**
|
||||
* When a load is delivered, notify all involved parties
|
||||
* When a load is on loading, notify all involved parties
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} elementId -> Element Affected
|
||||
*/
|
||||
@@ -96,7 +96,7 @@ async function onLoading( userId, elementId ){
|
||||
}
|
||||
|
||||
/**
|
||||
* When a load is delivered, notify all involved parties
|
||||
* When a load is on transit, notify all involved parties
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} elementId -> Element Affected
|
||||
*/
|
||||
@@ -115,7 +115,7 @@ async function onTransit( userId, elementId ){
|
||||
}
|
||||
|
||||
/**
|
||||
* When a load is delivered, notify all involved parties
|
||||
* When a load is downloading, notify all involved parties
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} elementId -> Element Affected
|
||||
*/
|
||||
@@ -133,4 +133,72 @@ async function onDownloading( userId, elementId ){
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { onDelivered, onLoading, onTransit, onDownloading };
|
||||
/**
|
||||
* When a load loading date changes, notify all involved parties
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} elementId -> Element Affected
|
||||
*/
|
||||
async function onLoadingDateChanged( userId, elementId ){
|
||||
const load = await loadsModel.findById( elementId );
|
||||
|
||||
const origin_warehouse = await branchesModel.findById( load.origin_warehouse );
|
||||
const destination_warehouse = await branchesModel.findById( load.destination_warehouse );
|
||||
const carrier = await companiesModel.findById( load.carrier ) || {};
|
||||
const product = await productsModel.findById( load.product ) || {};
|
||||
const vehicle = await vehiclesModel.findById( load.vehicle ) || {};
|
||||
const driver = await usersModel.findById( load.driver ) || {};
|
||||
|
||||
if( origin_warehouse ){
|
||||
await ObserversEvents.onLoadLoadDateChanged(
|
||||
ObserversEvents.NOTIFICATION_TYPE.WAREHOUSE,
|
||||
{ origin_warehouse, load, carrier, product, vehicle, driver }
|
||||
);
|
||||
}
|
||||
if( destination_warehouse ){
|
||||
await ObserversEvents.onLoadLoadDateChanged(
|
||||
ObserversEvents.NOTIFICATION_TYPE.WAREHOUSE,
|
||||
{ destination_warehouse, load, carrier, product, vehicle, driver }
|
||||
);
|
||||
}
|
||||
|
||||
await ObserversEvents.onLoadLoadDateChanged(
|
||||
ObserversEvents.NOTIFICATION_TYPE.CLIENT,
|
||||
{ load, carrier, product, vehicle, driver }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When a load download date changes, notify all involved parties
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} elementId -> Element Affected
|
||||
*/
|
||||
async function onDownloadDateChanged( userId, elementId ){
|
||||
const load = await loadsModel.findById( elementId );
|
||||
|
||||
const origin_warehouse = await branchesModel.findById( load.origin_warehouse );
|
||||
const destination_warehouse = await branchesModel.findById( load.destination_warehouse );
|
||||
const carrier = await companiesModel.findById( load.carrier ) || {};
|
||||
const product = await productsModel.findById( load.product ) || {};
|
||||
const vehicle = await vehiclesModel.findById( load.vehicle ) || {};
|
||||
const driver = await usersModel.findById( load.driver ) || {};
|
||||
|
||||
if( origin_warehouse ){
|
||||
await ObserversEvents.onLoadDownloadDateChanged(
|
||||
ObserversEvents.NOTIFICATION_TYPE.WAREHOUSE,
|
||||
{ origin_warehouse, load, carrier, product, vehicle, driver }
|
||||
);
|
||||
}
|
||||
if( destination_warehouse ){
|
||||
await ObserversEvents.onLoadDownloadDateChanged(
|
||||
ObserversEvents.NOTIFICATION_TYPE.WAREHOUSE,
|
||||
{ destination_warehouse, load, carrier, product, vehicle, driver }
|
||||
);
|
||||
}
|
||||
|
||||
await ObserversEvents.onLoadDownloadDateChanged(
|
||||
ObserversEvents.NOTIFICATION_TYPE.CLIENT,
|
||||
{ load, carrier, product, vehicle, driver }
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { onDelivered, onLoading, onTransit, onDownloading, onLoadingDateChanged, onDownloadDateChanged };
|
||||
|
||||
@@ -53,6 +53,14 @@ async function onLoadDelivered(){
|
||||
await sendEmailEvent( EMAIL_EVENTS.CLIENT_LOAD_DELIVERED, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
|
||||
async function onLoadLoadDateChanged(){
|
||||
await sendEmailEvent( EMAIL_EVENTS.CLIENT_LOAD_LOADING_DATE_CHANGED, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
|
||||
async function onLoadDownloadDateChanged(){
|
||||
await sendEmailEvent( EMAIL_EVENTS.CLIENT_LOAD_DOWNLOADING_DATE_CHANGED, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
onProposalAccepted,
|
||||
onProposalDriverChanged,
|
||||
@@ -61,4 +69,6 @@ module.exports = {
|
||||
onLoadInTransit,
|
||||
onLoadDownload,
|
||||
onLoadDelivered,
|
||||
onLoadLoadDateChanged,
|
||||
onLoadDownloadDateChanged
|
||||
};
|
||||
|
||||
@@ -37,8 +37,18 @@ async function onProposalVehicleChanged( warehouse, load, carrier, product, vehi
|
||||
await sendEmailEvent( EMAIL_EVENTS.WAREHOUSE_PROPOSAL_VEHICLE_CHANGED, warehouse, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
|
||||
async function onLoadLoadDateChanged(){
|
||||
await sendEmailEvent( EMAIL_EVENTS.WAREHOUSE_LOAD_LOADING_DATE_CHANGED, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
|
||||
async function onLoadDownloadDateChanged(){
|
||||
await sendEmailEvent( EMAIL_EVENTS.WAREHOUSE_LOAD_DOWNLOADING_DATE_CHANGED, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
onProposalAccepted,
|
||||
onProposalDriverChanged,
|
||||
onProposalVehicleChanged
|
||||
onProposalVehicleChanged,
|
||||
onLoadLoadDateChanged,
|
||||
onLoadDownloadDateChanged
|
||||
};
|
||||
|
||||
@@ -56,7 +56,6 @@ async function onProposalVehicleChanged( notification_type, content ){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function onLoadLoading( notification_type, content ){
|
||||
const { load, carrier, product, vehicle, driver } = content;
|
||||
|
||||
@@ -105,6 +104,38 @@ async function onLoadDelivered( notification_type, content ){
|
||||
}
|
||||
}
|
||||
|
||||
async function onLoadLoadDateChanged( notification_type, content ){
|
||||
const { warehouse, load, carrier, product, vehicle, driver } = content;
|
||||
|
||||
switch ( notification_type ){
|
||||
case NOTIFICATION_TYPE.CLIENT:
|
||||
return await ClientEvents.onLoadLoadDateChanged( load, carrier, product, vehicle, driver );
|
||||
case NOTIFICATION_TYPE.WAREHOUSE:
|
||||
return await WarehouseEvents.onLoadLoadDateChanged( warehouse, load, carrier, product, vehicle, driver );
|
||||
case NOTIFICATION_TYPE.BOTH:
|
||||
await WarehouseEvents.onLoadLoadDateChanged( warehouse, load, carrier, product, vehicle, driver );
|
||||
await ClientEvents.onLoadLoadDateChanged( load, carrier, product, vehicle, driver );
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async function onLoadDownloadDateChanged( notification_type, content ){
|
||||
const { warehouse, load, carrier, product, vehicle, driver } = content;
|
||||
|
||||
switch ( notification_type ){
|
||||
case NOTIFICATION_TYPE.CLIENT:
|
||||
return await ClientEvents.onLoadDownloadDateChanged( load, carrier, product, vehicle, driver );
|
||||
case NOTIFICATION_TYPE.WAREHOUSE:
|
||||
return await WarehouseEvents.onLoadDownloadDateChanged( warehouse, load, carrier, product, vehicle, driver );
|
||||
case NOTIFICATION_TYPE.BOTH:
|
||||
await WarehouseEvents.onLoadDownloadDateChanged( warehouse, load, carrier, product, vehicle, driver );
|
||||
await ClientEvents.onLoadDownloadDateChanged( load, carrier, product, vehicle, driver );
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NOTIFICATION_TYPE,
|
||||
onProposalAccepted,
|
||||
@@ -114,4 +145,6 @@ module.exports = {
|
||||
onLoadInTransit,
|
||||
onLoadDownload,
|
||||
onLoadDelivered,
|
||||
onLoadLoadDateChanged,
|
||||
onLoadDownloadDateChanged
|
||||
};
|
||||
|
||||
@@ -8,21 +8,31 @@ const LoadsEvents = require( './Events/Loads' );
|
||||
* @param {*} newData -> New Data Applied
|
||||
*/
|
||||
async function onPatchEvent( userId, elementId, newData ){
|
||||
const { load_status } = newData;
|
||||
const { load_status, est_loading_date, est_unloading_date } = newData;
|
||||
if( load_status ){
|
||||
switch (load_status){
|
||||
case "Delivered":
|
||||
return await LoadsEvents.onDelivered( userId, elementId );
|
||||
await LoadsEvents.onDelivered( userId, elementId );
|
||||
break;
|
||||
case "Loading":
|
||||
return await LoadsEvents.onLoading( userId, elementId );
|
||||
await LoadsEvents.onLoading( userId, elementId );
|
||||
break;
|
||||
case "Transit":
|
||||
return await LoadsEvents.onTransit( userId, elementId );
|
||||
await LoadsEvents.onTransit( userId, elementId );
|
||||
break;
|
||||
case "Downloading":
|
||||
return await LoadsEvents.onDownloading( userId, elementId );
|
||||
await LoadsEvents.onDownloading( userId, elementId );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( est_loading_date ){
|
||||
await LoadsEvents.onLoadingDateChanged( userId, elementId );
|
||||
}
|
||||
if( est_unloading_date ){
|
||||
await LoadsEvents.onDownloadDateChanged( userId, elementId );
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { onPatchEvent };
|
||||
|
||||
@@ -106,6 +106,14 @@ async function WarehouseProposalVehicleChanged( receiver, content ){
|
||||
console.log("WarehouseProposalVehicleChanged email event not yet implemented");
|
||||
}
|
||||
|
||||
async function WarehouseLoadDateChanged( receiver, content ){
|
||||
console.log("WarehouseLoadDateChanged email event not yet implemented");
|
||||
}
|
||||
|
||||
async function WarehouseLoadDownloadDateChanged( receiver, content ){
|
||||
console.log("WarehouseLoadDownloadDateChanged email event not yet implemented");
|
||||
}
|
||||
|
||||
async function ClientProposalAccepted( receiver, content ){
|
||||
console.log("ClientProposalAccepted email event not yet implemented");
|
||||
console.log(`receiver: ${receiver}`);
|
||||
@@ -148,6 +156,18 @@ async function ClientLoadDelivered( receiver, content ){
|
||||
console.log( content );
|
||||
}
|
||||
|
||||
async function ClientLoadDateChanged( receiver, content ){
|
||||
console.log("ClientLoadDateChanged email event not yet implemented");
|
||||
console.log(`receiver: ${receiver}`);
|
||||
console.log( content );
|
||||
}
|
||||
|
||||
async function ClientLoadDownloadDateChanged( receiver, content ){
|
||||
console.log("ClientLoadDownloadDateChanged email event not yet implemented");
|
||||
console.log(`receiver: ${receiver}`);
|
||||
console.log( content );
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AccountVerifyEmail,
|
||||
AccountConfirmed,
|
||||
@@ -157,11 +177,15 @@ module.exports = {
|
||||
WarehouseProposalAccepted,
|
||||
WarehouseProposalDriverChanged,
|
||||
WarehouseProposalVehicleChanged,
|
||||
WarehouseLoadDateChanged,
|
||||
WarehouseLoadDownloadDateChanged,
|
||||
ClientProposalAccepted,
|
||||
ClientProposalDriverChanged,
|
||||
ClientProposalVehicleChanged,
|
||||
ClientLoadOnLoading,
|
||||
ClientLoadInTransit,
|
||||
ClientLoadOnDownload,
|
||||
ClientLoadDelivered
|
||||
ClientLoadDelivered,
|
||||
ClientLoadDateChanged,
|
||||
ClientLoadDownloadDateChanged
|
||||
};
|
||||
|
||||
@@ -8,13 +8,17 @@ const {
|
||||
WarehouseProposalAccepted,
|
||||
WarehouseProposalDriverChanged,
|
||||
WarehouseProposalVehicleChanged,
|
||||
WarehouseLoadDateChanged,
|
||||
WarehouseLoadDownloadDateChanged,
|
||||
ClientProposalAccepted,
|
||||
ClientProposalDriverChanged,
|
||||
ClientProposalVehicleChanged,
|
||||
ClientLoadOnLoading,
|
||||
ClientLoadInTransit,
|
||||
ClientLoadOnDownload,
|
||||
ClientLoadDelivered
|
||||
ClientLoadDelivered,
|
||||
ClientLoadDateChanged,
|
||||
ClientLoadDownloadDateChanged
|
||||
} = require('./StandAlone.handler');
|
||||
|
||||
const EMAIL_EVENTS={
|
||||
@@ -25,13 +29,17 @@ const EMAIL_EVENTS={
|
||||
WAREHOUSE_PROPOSAL_ACCEPTED:5,
|
||||
WAREHOUSE_PROPOSAL_DRIVER_CHANGED:6,
|
||||
WAREHOUSE_PROPOSAL_VEHICLE_CHANGED:7,
|
||||
CLIENT_PROPOSAL_ACCEPTED:8,
|
||||
CLIENT_PROPOSAL_DRIVER_CHANGED:9,
|
||||
CLIENT_PROPOSAL_VEHICLE_CHANGED:10,
|
||||
CLIENT_LOAD_ON_LOADING:11,
|
||||
CLIENT_LOAD_IN_TRANSIT:12,
|
||||
CLIENT_LOAD_ON_DOWNLOAD:13,
|
||||
CLIENT_LOAD_DELIVERED:14,
|
||||
WAREHOUSE_LOAD_LOADING_DATE_CHANGED:8,
|
||||
WAREHOUSE_LOAD_DOWNLOADING_DATE_CHANGED:9,
|
||||
CLIENT_PROPOSAL_ACCEPTED:10,
|
||||
CLIENT_PROPOSAL_DRIVER_CHANGED:11,
|
||||
CLIENT_PROPOSAL_VEHICLE_CHANGED:12,
|
||||
CLIENT_LOAD_ON_LOADING:13,
|
||||
CLIENT_LOAD_IN_TRANSIT:14,
|
||||
CLIENT_LOAD_ON_DOWNLOAD:15,
|
||||
CLIENT_LOAD_DELIVERED:16,
|
||||
CLIENT_LOAD_LOADING_DATE_CHANGED:17,
|
||||
CLIENT_LOAD_DOWNLOADING_DATE_CHANGED:18,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +86,16 @@ async function emailEvent( eventId, receiver , content ){
|
||||
return await WarehouseProposalVehicleChanged( receiver, content );
|
||||
}
|
||||
break;
|
||||
case EMAIL_EVENTS.WAREHOUSE_LOAD_LOADING_DATE_CHANGED:
|
||||
{
|
||||
return await WarehouseLoadDateChanged( receiver, content );
|
||||
}
|
||||
break;
|
||||
case EMAIL_EVENTS.WAREHOUSE_LOAD_DOWNLOADING_DATE_CHANGED:
|
||||
{
|
||||
return await WarehouseLoadDownloadDateChanged( receiver, content );
|
||||
}
|
||||
break;
|
||||
case EMAIL_EVENTS.CLIENT_PROPOSAL_ACCEPTED:
|
||||
{
|
||||
return await ClientProposalAccepted( receiver, content );
|
||||
@@ -113,6 +131,16 @@ async function emailEvent( eventId, receiver , content ){
|
||||
return await ClientLoadDelivered( receiver, content );
|
||||
}
|
||||
break;
|
||||
case EMAIL_EVENTS.CLIENT_LOAD_LOADING_DATE_CHANGED:
|
||||
{
|
||||
return await ClientLoadDateChanged( receiver, content );
|
||||
}
|
||||
break;
|
||||
case EMAIL_EVENTS.CLIENT_LOAD_DOWNLOADING_DATE_CHANGED:
|
||||
{
|
||||
return await ClientLoadDownloadDateChanged( receiver, content );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
throw new Error(`Email event not defined ${eventId}`);
|
||||
|
||||
Reference in New Issue
Block a user