feat(loads::events): Adding date change events
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version" : {
|
"version" : {
|
||||||
"version" : "1.5.6",
|
"version" : "1.5.7",
|
||||||
"name": "ETA Beta",
|
"name": "ETA Beta",
|
||||||
"date":"22/07/2025"
|
"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 {*} userId -> Responsible of the change
|
||||||
* @param {*} elementId -> Element Affected
|
* @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 {*} userId -> Responsible of the change
|
||||||
* @param {*} elementId -> Element Affected
|
* @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 {*} userId -> Responsible of the change
|
||||||
* @param {*} elementId -> Element Affected
|
* @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 );
|
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 = {
|
module.exports = {
|
||||||
onProposalAccepted,
|
onProposalAccepted,
|
||||||
onProposalDriverChanged,
|
onProposalDriverChanged,
|
||||||
@@ -61,4 +69,6 @@ module.exports = {
|
|||||||
onLoadInTransit,
|
onLoadInTransit,
|
||||||
onLoadDownload,
|
onLoadDownload,
|
||||||
onLoadDelivered,
|
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 );
|
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 = {
|
module.exports = {
|
||||||
onProposalAccepted,
|
onProposalAccepted,
|
||||||
onProposalDriverChanged,
|
onProposalDriverChanged,
|
||||||
onProposalVehicleChanged
|
onProposalVehicleChanged,
|
||||||
|
onLoadLoadDateChanged,
|
||||||
|
onLoadDownloadDateChanged
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ async function onProposalVehicleChanged( notification_type, content ){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function onLoadLoading( notification_type, content ){
|
async function onLoadLoading( notification_type, content ){
|
||||||
const { load, carrier, product, vehicle, driver } = 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 = {
|
module.exports = {
|
||||||
NOTIFICATION_TYPE,
|
NOTIFICATION_TYPE,
|
||||||
onProposalAccepted,
|
onProposalAccepted,
|
||||||
@@ -114,4 +145,6 @@ module.exports = {
|
|||||||
onLoadInTransit,
|
onLoadInTransit,
|
||||||
onLoadDownload,
|
onLoadDownload,
|
||||||
onLoadDelivered,
|
onLoadDelivered,
|
||||||
|
onLoadLoadDateChanged,
|
||||||
|
onLoadDownloadDateChanged
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,21 +8,31 @@ const LoadsEvents = require( './Events/Loads' );
|
|||||||
* @param {*} newData -> New Data Applied
|
* @param {*} newData -> New Data Applied
|
||||||
*/
|
*/
|
||||||
async function onPatchEvent( userId, elementId, newData ){
|
async function onPatchEvent( userId, elementId, newData ){
|
||||||
const { load_status } = newData;
|
const { load_status, est_loading_date, est_unloading_date } = newData;
|
||||||
if( load_status ){
|
if( load_status ){
|
||||||
switch (load_status){
|
switch (load_status){
|
||||||
case "Delivered":
|
case "Delivered":
|
||||||
return await LoadsEvents.onDelivered( userId, elementId );
|
await LoadsEvents.onDelivered( userId, elementId );
|
||||||
|
break;
|
||||||
case "Loading":
|
case "Loading":
|
||||||
return await LoadsEvents.onLoading( userId, elementId );
|
await LoadsEvents.onLoading( userId, elementId );
|
||||||
|
break;
|
||||||
case "Transit":
|
case "Transit":
|
||||||
return await LoadsEvents.onTransit( userId, elementId );
|
await LoadsEvents.onTransit( userId, elementId );
|
||||||
|
break;
|
||||||
case "Downloading":
|
case "Downloading":
|
||||||
return await LoadsEvents.onDownloading( userId, elementId );
|
await LoadsEvents.onDownloading( userId, elementId );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( est_loading_date ){
|
||||||
|
await LoadsEvents.onLoadingDateChanged( userId, elementId );
|
||||||
|
}
|
||||||
|
if( est_unloading_date ){
|
||||||
|
await LoadsEvents.onDownloadDateChanged( userId, elementId );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { onPatchEvent };
|
module.exports = { onPatchEvent };
|
||||||
|
|||||||
@@ -106,6 +106,14 @@ async function WarehouseProposalVehicleChanged( receiver, content ){
|
|||||||
console.log("WarehouseProposalVehicleChanged email event not yet implemented");
|
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 ){
|
async function ClientProposalAccepted( receiver, content ){
|
||||||
console.log("ClientProposalAccepted email event not yet implemented");
|
console.log("ClientProposalAccepted email event not yet implemented");
|
||||||
console.log(`receiver: ${receiver}`);
|
console.log(`receiver: ${receiver}`);
|
||||||
@@ -148,6 +156,18 @@ async function ClientLoadDelivered( receiver, content ){
|
|||||||
console.log( 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 = {
|
module.exports = {
|
||||||
AccountVerifyEmail,
|
AccountVerifyEmail,
|
||||||
AccountConfirmed,
|
AccountConfirmed,
|
||||||
@@ -157,11 +177,15 @@ module.exports = {
|
|||||||
WarehouseProposalAccepted,
|
WarehouseProposalAccepted,
|
||||||
WarehouseProposalDriverChanged,
|
WarehouseProposalDriverChanged,
|
||||||
WarehouseProposalVehicleChanged,
|
WarehouseProposalVehicleChanged,
|
||||||
|
WarehouseLoadDateChanged,
|
||||||
|
WarehouseLoadDownloadDateChanged,
|
||||||
ClientProposalAccepted,
|
ClientProposalAccepted,
|
||||||
ClientProposalDriverChanged,
|
ClientProposalDriverChanged,
|
||||||
ClientProposalVehicleChanged,
|
ClientProposalVehicleChanged,
|
||||||
ClientLoadOnLoading,
|
ClientLoadOnLoading,
|
||||||
ClientLoadInTransit,
|
ClientLoadInTransit,
|
||||||
ClientLoadOnDownload,
|
ClientLoadOnDownload,
|
||||||
ClientLoadDelivered
|
ClientLoadDelivered,
|
||||||
|
ClientLoadDateChanged,
|
||||||
|
ClientLoadDownloadDateChanged
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ const {
|
|||||||
WarehouseProposalAccepted,
|
WarehouseProposalAccepted,
|
||||||
WarehouseProposalDriverChanged,
|
WarehouseProposalDriverChanged,
|
||||||
WarehouseProposalVehicleChanged,
|
WarehouseProposalVehicleChanged,
|
||||||
|
WarehouseLoadDateChanged,
|
||||||
|
WarehouseLoadDownloadDateChanged,
|
||||||
ClientProposalAccepted,
|
ClientProposalAccepted,
|
||||||
ClientProposalDriverChanged,
|
ClientProposalDriverChanged,
|
||||||
ClientProposalVehicleChanged,
|
ClientProposalVehicleChanged,
|
||||||
ClientLoadOnLoading,
|
ClientLoadOnLoading,
|
||||||
ClientLoadInTransit,
|
ClientLoadInTransit,
|
||||||
ClientLoadOnDownload,
|
ClientLoadOnDownload,
|
||||||
ClientLoadDelivered
|
ClientLoadDelivered,
|
||||||
|
ClientLoadDateChanged,
|
||||||
|
ClientLoadDownloadDateChanged
|
||||||
} = require('./StandAlone.handler');
|
} = require('./StandAlone.handler');
|
||||||
|
|
||||||
const EMAIL_EVENTS={
|
const EMAIL_EVENTS={
|
||||||
@@ -25,13 +29,17 @@ const EMAIL_EVENTS={
|
|||||||
WAREHOUSE_PROPOSAL_ACCEPTED:5,
|
WAREHOUSE_PROPOSAL_ACCEPTED:5,
|
||||||
WAREHOUSE_PROPOSAL_DRIVER_CHANGED:6,
|
WAREHOUSE_PROPOSAL_DRIVER_CHANGED:6,
|
||||||
WAREHOUSE_PROPOSAL_VEHICLE_CHANGED:7,
|
WAREHOUSE_PROPOSAL_VEHICLE_CHANGED:7,
|
||||||
CLIENT_PROPOSAL_ACCEPTED:8,
|
WAREHOUSE_LOAD_LOADING_DATE_CHANGED:8,
|
||||||
CLIENT_PROPOSAL_DRIVER_CHANGED:9,
|
WAREHOUSE_LOAD_DOWNLOADING_DATE_CHANGED:9,
|
||||||
CLIENT_PROPOSAL_VEHICLE_CHANGED:10,
|
CLIENT_PROPOSAL_ACCEPTED:10,
|
||||||
CLIENT_LOAD_ON_LOADING:11,
|
CLIENT_PROPOSAL_DRIVER_CHANGED:11,
|
||||||
CLIENT_LOAD_IN_TRANSIT:12,
|
CLIENT_PROPOSAL_VEHICLE_CHANGED:12,
|
||||||
CLIENT_LOAD_ON_DOWNLOAD:13,
|
CLIENT_LOAD_ON_LOADING:13,
|
||||||
CLIENT_LOAD_DELIVERED:14,
|
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 );
|
return await WarehouseProposalVehicleChanged( receiver, content );
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case EMAIL_EVENTS.CLIENT_PROPOSAL_ACCEPTED:
|
||||||
{
|
{
|
||||||
return await ClientProposalAccepted( receiver, content );
|
return await ClientProposalAccepted( receiver, content );
|
||||||
@@ -113,6 +131,16 @@ async function emailEvent( eventId, receiver , content ){
|
|||||||
return await ClientLoadDelivered( receiver, content );
|
return await ClientLoadDelivered( receiver, content );
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
{
|
{
|
||||||
throw new Error(`Email event not defined ${eventId}`);
|
throw new Error(`Email event not defined ${eventId}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user