fix(proposals::warehouse): email events using warehouse fields
This commit is contained in:
@@ -91,13 +91,17 @@ async function onProposalAccepted( userId, proposalId ){
|
||||
const load = await loadsModel.findById( proposal.load );
|
||||
await onAcceptedEvents.sendNotification( proposal, load );
|
||||
|
||||
const warehouse = await branchesModel.findById( load.shipper_warehouse );
|
||||
if( warehouse ){
|
||||
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 driver = await usersModel.findById( load.driver ) || {};
|
||||
|
||||
await onAcceptedEvents.sendWarehouseEmail( warehouse, load, carrier, product, vehicle, driver );
|
||||
if( origin_warehouse ){
|
||||
await onAcceptedEvents.sendWarehouseEmail( origin_warehouse, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
if( destination_warehouse ){
|
||||
await onAcceptedEvents.sendWarehouseEmail( destination_warehouse, load, carrier, product, vehicle, driver );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,15 +7,10 @@ const usersModel = getModel('users');
|
||||
async function onProposalAccepted( warehouse, load, carrier, product, vehicle, driver ){
|
||||
const driver_name = `${driver.first_name} ${driver.last_name}`;
|
||||
|
||||
const list_of_warehouse_responsibles = await usersModel.find(
|
||||
{
|
||||
branch: warehouse.id,
|
||||
job_role: 'warehouse'
|
||||
}
|
||||
);
|
||||
/** Get the list of emails from the warehouse alert_list field */
|
||||
const list_of_warehouse_emails = warehouse.alert_list || [];
|
||||
|
||||
for( const entry of list_of_warehouse_responsibles ){
|
||||
warehouse_email = entry.email;
|
||||
for( const warehouse_email of list_of_warehouse_emails ){
|
||||
emailEvent(
|
||||
EMAIL_EVENTS.WAREHOUSE_DRIVER_ASSIGNED,
|
||||
warehouse_email,
|
||||
|
||||
Reference in New Issue
Block a user