Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions packages/reaction-core/server/methods/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,42 @@ Meteor.methods({
*
* @summary trigger shipmentShipped status and workflow update
* @param {Object} order - order object
* @return {Object} return workflow result
* @param {Object} shipment - shipment object
* @return {Object} return results of several operations
*/
"orders/shipmentShipped": function (order) {
"orders/shipmentShipped": function (order, shipment) {
check(order, Object);
this.unblock();

if (order) {
let shipment = order.shipping[0];
let completedItemsResult;
let completedOrderResult;

// Attempt to sent email notification
Meteor.call("orders/sendNotification", order);
// Attempt to sent email notification
const notifyResult = Meteor.call("orders/sendNotification", order);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does Email.send even return a value? And I don't think that function returns a value on error either

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially it returns true. And we could also refactor orders/sendNotification to make it return something, because I think this is important to admin to know was notification really sent or not.


const itemIds = shipment.items.map((item) => {
return item._id;
});
const itemIds = shipment.items.map((item) => {
return item._id;
});

Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/shipped", order, itemIds, (error) => {
// Move to completed status for items
// TODO: In the future, this could be handled by shipping delivery status
if (!error) {
Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/completed", order, itemIds, (error2) => {
// Then try to mark order as completed.
if (!error2) {
Meteor.call("workflow/pushOrderWorkflow", "coreOrderWorkflow", "completed", order);
}
});
}
});
// TODO: In the future, this could be handled by shipping delivery status
const workflowResult = Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/shipped", order, itemIds);

if (workflowResult === 1) {
// Move to completed status for items
completedItemsResult = Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/completed", order, itemIds);

if (completedItemsResult === 1) {
// Then try to mark order as completed.
completedOrderResult = Meteor.call("workflow/pushOrderWorkflow", "coreOrderWorkflow", "completed", order);
}
}

return {
notify: notifyResult,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables should be renamed for clarity. Especially "workflow" since you aren't returning a workflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, any suggestions how which names could be used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think workflowResult would be ok..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't understand. Now we have an result object:

{
  notify,
  workflow,
  completedItems,
  completedOrder
}

Should I rename some of these vars to workflowResult or that should I do?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, rename the variable workflow to workflowResult because you are not returning a workflow, rename the variable notify to notifyResult, etc.

workflow: workflowResult,
completedItems: completedItemsResult,
completedOrder: completedOrderResult
};
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Template.coreOrderShippingTracking.onCreated(() => {
Template.coreOrderShippingTracking.events({
"click [data-event-action=shipmentShipped]": function () {
let template = Template.instance();
Meteor.call("orders/shipmentShipped", template.order);
Meteor.call("orders/shipmentShipped", template.order, template.order.shipping[0]);
// Meteor.call("workflow/pushOrderShipmentWorkflow", "coreOrderShipmentWorkflow", "orderShipped", this._id);
},

Expand Down