-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add updateOrderFulfillmentGroup mutation #5020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bd4278c
feat: add updateOrderFulfillmentGroup internal mutation
aldeed fa3b443
feat: add updateOrderFulfillmentGroup GraphQL mutation
aldeed 07857db
feat: remove "orders/updateShipmentTracking" Meteor method
aldeed 7ce01f5
Merge branch 'develop' into feat-aldeed-update-order-group
aldeed 1c86ee9
feat: support setting trackingUrl on order fulfillment group
aldeed 2208c12
comment update
kieckhafer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
imports/plugins/core/orders/client/graphql/updateOrderFulfillmentGroup.graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| updateOrderFulfillmentGroup($orderFulfillmentGroupId: ID!, $orderId: ID!, $status: String, $tracking: String) { | ||
| updateOrderFulfillmentGroup(input: { | ||
| orderFulfillmentGroupId: $orderFulfillmentGroupId, | ||
| orderId: $orderId, | ||
| status: $status, | ||
| tracking: $tracking | ||
| }) { | ||
| order { | ||
| fulfillmentGroups { | ||
| status | ||
| tracking | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
imports/plugins/core/orders/server/methods/updateShipmentTracking.js
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
.../orders/server/no-meteor/mutations/__snapshots__/updateOrderFulfillmentGroup.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`throws if orderFulfillmentGroupId isn't supplied 1`] = `"Order fulfillment group ID is required"`; | ||
|
|
||
| exports[`throws if orderId isn't supplied 1`] = `"Order ID is required"`; | ||
|
|
||
| exports[`throws if permission check fails 1`] = `"Access Denied"`; | ||
|
|
||
| exports[`throws if the order doesn't exist 1`] = `"Order not found"`; | ||
|
|
||
| exports[`throws if the order fulfillment group doesn't exist 1`] = `"Order fulfillment group not found"`; |
4 changes: 3 additions & 1 deletion
4
imports/plugins/core/orders/server/no-meteor/mutations/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import cancelOrderItem from "./cancelOrderItem"; | ||
| import placeOrder from "./placeOrder"; | ||
| import updateOrder from "./updateOrder"; | ||
| import updateOrderFulfillmentGroup from "./updateOrderFulfillmentGroup"; | ||
|
|
||
| export default { | ||
| cancelOrderItem, | ||
| placeOrder, | ||
| updateOrder | ||
| updateOrder, | ||
| updateOrderFulfillmentGroup | ||
| }; |
95 changes: 95 additions & 0 deletions
95
imports/plugins/core/orders/server/no-meteor/mutations/updateOrderFulfillmentGroup.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import SimpleSchema from "simpl-schema"; | ||
| import ReactionError from "@reactioncommerce/reaction-error"; | ||
| import { Order as OrderSchema } from "/imports/collections/schemas"; | ||
|
|
||
| const inputSchema = new SimpleSchema({ | ||
| tracking: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| trackingUrl: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| orderFulfillmentGroupId: String, | ||
| orderId: String, | ||
| status: { | ||
| type: String, | ||
| optional: true | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * @method updateOrderFulfillmentGroup | ||
| * @summary Use this mutation to update an order fulfillment group status and tracking information | ||
| * @param {Object} context - an object containing the per-request state | ||
| * @param {Object} input - Necessary input. See SimpleSchema | ||
| * @return {Promise<Object>} Object with `order` property containing the updated order | ||
| */ | ||
| export default async function updateOrderFulfillmentGroup(context, input) { | ||
| inputSchema.validate(input); | ||
|
|
||
| const { | ||
| tracking, | ||
| trackingUrl, | ||
| orderFulfillmentGroupId, | ||
| orderId, | ||
| status | ||
| } = input; | ||
|
|
||
| const { appEvents, collections, isInternalCall, userHasPermission, userId } = context; | ||
| const { Orders } = collections; | ||
|
|
||
| // First verify that this order actually exists | ||
| const order = await Orders.findOne({ _id: orderId }); | ||
| if (!order) throw new ReactionError("not-found", "Order not found"); | ||
|
|
||
| // Allow update if the account has "orders" permission. When called internally by another | ||
| // plugin, context.isInternalCall can be set to `true` to disable this check. | ||
| if (!isInternalCall && !userHasPermission(["orders"], order.shopId)) { | ||
| throw new ReactionError("access-denied", "Access Denied"); | ||
| } | ||
|
|
||
| // Verify that there is a group with the ID | ||
| const orderFulfillmentGroup = order.shipping.find((group) => group._id === orderFulfillmentGroupId); | ||
| if (!orderFulfillmentGroup) throw new ReactionError("not-found", "Order fulfillment group not found"); | ||
|
|
||
| const modifier = { | ||
| $set: { | ||
| "shipping.$.updatedAt": new Date(), | ||
| "updatedAt": new Date() | ||
| } | ||
| }; | ||
|
|
||
| if (tracking) modifier.$set["shipping.$.tracking"] = tracking; | ||
| if (trackingUrl) modifier.$set["shipping.$.trackingUrl"] = trackingUrl; | ||
|
|
||
| if (status && orderFulfillmentGroup.workflow.status !== status) { | ||
| modifier.$set["shipping.$.workflow.status"] = status; | ||
| modifier.$push = { | ||
| "shipping.$.workflow.workflow": status | ||
| }; | ||
| } | ||
|
|
||
| // Skip updating if we have no updates to make | ||
| if (Object.keys(modifier.$set).length === 2) return { order }; | ||
|
|
||
| OrderSchema.validate(modifier, { modifier: true }); | ||
|
|
||
| const { modifiedCount, value: updatedOrder } = await Orders.findOneAndUpdate( | ||
| { | ||
| "_id": orderId, | ||
| "shipping._id": orderFulfillmentGroupId | ||
| }, | ||
| modifier, | ||
| { returnOriginal: false } | ||
| ); | ||
| if (modifiedCount === 0 || !updatedOrder) throw new ReactionError("server-error", "Unable to update order"); | ||
|
|
||
| await appEvents.emit("afterOrderUpdate", { | ||
| order: updatedOrder, | ||
| updatedBy: userId | ||
| }); | ||
|
|
||
| return { order: updatedOrder }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See that you noted trackingUrl is not updated here yet. Should we go ahead and add it already to keep this in sync with what the other mutation can do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather wait until we actually add a field in UI for it and need it here.