feat: Adding Loads/Vehicle events to populate data among different
tables fix(proposals): When patch event happens without is_accepted field, this is detected as a rejection event.
This commit is contained in:
@@ -13,7 +13,9 @@ const notificationsModel = getModel('notifications');
|
||||
const productsModel = getModel('products');
|
||||
|
||||
/**
|
||||
* When the proposal is created then the load owner should be notified
|
||||
* When the proposal is created then the load owner should be notified.
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} proposalId -> Proposal Affected
|
||||
*/
|
||||
async function onProposalCreate( userId, proposalId ){
|
||||
const proposal = await proposalsModel.findById( proposalId );
|
||||
@@ -32,7 +34,9 @@ async function onProposalCreate( userId, proposalId ){
|
||||
}
|
||||
|
||||
/**
|
||||
* When a proposal is removed from the load, it is considered as rejected
|
||||
* When a proposal is removed from the load, it is considered as rejected.
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} proposalId -> Proposal Affected
|
||||
*/
|
||||
async function onProposalRejected( userId, proposalId ){
|
||||
const proposal = await proposalsModel.findById( proposalId );
|
||||
@@ -56,7 +60,9 @@ async function onProposalRejected( userId, proposalId ){
|
||||
}
|
||||
|
||||
/**
|
||||
* When a proposal is accepted by the shipper
|
||||
* When a proposal is accepted by the shipper.
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} proposalId -> Proposal Affected
|
||||
*/
|
||||
async function onProposalAccepted( userId, proposalId ){
|
||||
const shipper_user = await usersModel.findById( userId );
|
||||
@@ -86,4 +92,21 @@ async function onProposalAccepted( userId, proposalId ){
|
||||
await onAcceptedEvents.sendNotification( proposal, load );
|
||||
}
|
||||
|
||||
module.exports = { onProposalCreate, onProposalRejected, onProposalAccepted };
|
||||
/**
|
||||
* When a vehicle changes from the original proposal
|
||||
* @param {*} userId -> Responsible of the change
|
||||
* @param {*} proposalId -> Proposal Affected
|
||||
*/
|
||||
async function onProposalVehicleChanged( userId, proposalId ){
|
||||
const proposal = await proposalsModel.findById( proposalId );
|
||||
const vehicle = await vehiclesModel.findById( proposal.vehicle );
|
||||
|
||||
/// Update Load:
|
||||
/// Add driver and vehicle
|
||||
await loadsModel.findByIdAndUpdate( proposal.load, {
|
||||
driver : vehicle.driver,
|
||||
vehicle : proposal.vehicle
|
||||
} );
|
||||
}
|
||||
|
||||
module.exports = { onProposalCreate, onProposalRejected, onProposalAccepted, onProposalVehicleChanged };
|
||||
|
||||
Reference in New Issue
Block a user