151 lines
5.7 KiB
JavaScript
151 lines
5.7 KiB
JavaScript
'user strict';
|
|
const ClientEvents = require('./Client');
|
|
const WarehouseEvents = require('./Warehouse');
|
|
|
|
const NOTIFICATION_TYPE={
|
|
CLIENT:0,
|
|
WAREHOUSE:1,
|
|
BOTH:2,
|
|
}
|
|
|
|
async function onProposalAccepted( notification_type, content ){
|
|
const { warehouse, load, carrier, product, vehicle, driver } = content;
|
|
|
|
switch ( notification_type ){
|
|
case NOTIFICATION_TYPE.CLIENT:
|
|
return await ClientEvents.onProposalAccepted( load, carrier, product, vehicle, driver );
|
|
case NOTIFICATION_TYPE.WAREHOUSE:
|
|
return await WarehouseEvents.onProposalAccepted( warehouse, load, carrier, product, vehicle, driver );
|
|
case NOTIFICATION_TYPE.BOTH:
|
|
await WarehouseEvents.onProposalAccepted( warehouse, load, carrier, product, vehicle, driver );
|
|
await ClientEvents.onProposalAccepted( load, carrier, product, vehicle, driver );
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
async function onProposalDriverChanged( notification_type, content ){
|
|
const { warehouse, load, carrier, product, vehicle, driver } = content;
|
|
|
|
switch ( notification_type ){
|
|
case NOTIFICATION_TYPE.CLIENT:
|
|
return await ClientEvents.onProposalDriverChanged( load, carrier, product, vehicle, driver );
|
|
case NOTIFICATION_TYPE.WAREHOUSE:
|
|
return await WarehouseEvents.onProposalDriverChanged( warehouse, load, carrier, product, vehicle, driver );
|
|
case NOTIFICATION_TYPE.BOTH:
|
|
await WarehouseEvents.onProposalDriverChanged( warehouse, load, carrier, product, vehicle, driver );
|
|
await ClientEvents.onProposalDriverChanged( load, carrier, product, vehicle, driver );
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
async function onProposalVehicleChanged( notification_type, content ){
|
|
const { warehouse, load, carrier, product, vehicle, driver } = content;
|
|
|
|
switch ( notification_type ){
|
|
case NOTIFICATION_TYPE.CLIENT:
|
|
return await ClientEvents.onProposalVehicleChanged( load, carrier, product, vehicle, driver );
|
|
case NOTIFICATION_TYPE.WAREHOUSE:
|
|
return await WarehouseEvents.onProposalVehicleChanged( warehouse, load, carrier, product, vehicle, driver );
|
|
case NOTIFICATION_TYPE.BOTH:
|
|
await WarehouseEvents.onProposalVehicleChanged( warehouse, load, carrier, product, vehicle, driver );
|
|
await ClientEvents.onProposalVehicleChanged( load, carrier, product, vehicle, driver );
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
async function onLoadLoading( notification_type, content ){
|
|
const { load, carrier, product, vehicle, driver } = content;
|
|
|
|
switch ( notification_type ){
|
|
case NOTIFICATION_TYPE.CLIENT:
|
|
case NOTIFICATION_TYPE.BOTH:
|
|
return await ClientEvents.onLoadLoading( load, carrier, product, vehicle, driver );
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
async function onLoadInTransit( notification_type, content ){
|
|
const { load, carrier, product, vehicle, driver } = content;
|
|
|
|
switch ( notification_type ){
|
|
case NOTIFICATION_TYPE.CLIENT:
|
|
case NOTIFICATION_TYPE.BOTH:
|
|
return await ClientEvents.onLoadInTransit( load, carrier, product, vehicle, driver );
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
async function onLoadDownload( notification_type, content ){
|
|
const { load, carrier, product, vehicle, driver } = content;
|
|
|
|
switch ( notification_type ){
|
|
case NOTIFICATION_TYPE.CLIENT:
|
|
case NOTIFICATION_TYPE.BOTH:
|
|
return await ClientEvents.onLoadDownload( load, carrier, onLoadOnDownload, vehicle, driver );
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
async function onLoadDelivered( notification_type, content ){
|
|
const { load, carrier, product, vehicle, driver } = content;
|
|
|
|
switch ( notification_type ){
|
|
case NOTIFICATION_TYPE.CLIENT:
|
|
case NOTIFICATION_TYPE.BOTH:
|
|
return await ClientEvents.onLoadDelivered( load, carrier, product, vehicle, driver );
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
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,
|
|
onProposalDriverChanged,
|
|
onProposalVehicleChanged,
|
|
onLoadLoading,
|
|
onLoadInTransit,
|
|
onLoadDownload,
|
|
onLoadDelivered,
|
|
onLoadLoadDateChanged,
|
|
onLoadDownloadDateChanged
|
|
};
|