-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4827 from reactioncommerce/feat-4766-aldeed-order…
…-ref-id Add Order.referenceId
- Loading branch information
Showing
21 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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,5 +1,7 @@ | ||
import orderById from "./orderById"; | ||
import orderByReferenceId from "./orderByReferenceId"; | ||
|
||
export default { | ||
orderById | ||
orderById, | ||
orderByReferenceId | ||
}; |
This file contains 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
46 changes: 46 additions & 0 deletions
46
imports/plugins/core/orders/server/no-meteor/queries/orderByReferenceId.js
This file contains 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,46 @@ | ||
import ReactionError from "@reactioncommerce/reaction-error"; | ||
import hashLoginToken from "/imports/node-app/core/util/hashLoginToken"; | ||
|
||
/** | ||
* @name orderByReferenceId | ||
* @method | ||
* @memberof Order/NoMeteorQueries | ||
* @summary Query the Orders collection for an order with the provided order referenceId | ||
* @param {Object} context - an object containing the per-request state | ||
* @param {Object} params - request parameters | ||
* @param {String} params.orderReferenceId - Order reference ID | ||
* @param {String} params.shopId - Shop ID for the shop that owns the order | ||
* @param {String} [params.token] - Anonymous order token | ||
* @return {Promise<Object>|undefined} - An Order document, if one is found | ||
*/ | ||
export default async function orderByReferenceId(context, { orderReferenceId, shopId, token } = {}) { | ||
const { accountId: contextAccountId, collections, userHasPermission } = context; | ||
const { Orders } = collections; | ||
|
||
if (!orderReferenceId || !shopId) { | ||
throw new ReactionError("invalid-param", "You must provide orderReferenceId and shopId arguments"); | ||
} | ||
|
||
let accountId; | ||
let anonymousAccessToken; | ||
if (token) { | ||
accountId = null; | ||
anonymousAccessToken = hashLoginToken(token); | ||
} else { | ||
// Unless you are an admin with orders permission, you are limited to seeing it if you placed it | ||
if (!userHasPermission(["orders"], shopId)) { | ||
if (!contextAccountId) { | ||
throw new ReactionError("access-denied", "Access Denied"); | ||
} | ||
accountId = contextAccountId; | ||
} | ||
anonymousAccessToken = null; | ||
} | ||
|
||
return Orders.findOne({ | ||
accountId, | ||
anonymousAccessToken, | ||
referenceId: orderReferenceId, | ||
shopId | ||
}); | ||
} |
4 changes: 3 additions & 1 deletion
4
imports/plugins/core/orders/server/no-meteor/resolvers/Query/index.js
This file contains 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,5 +1,7 @@ | ||
import orderById from "./orderById"; | ||
import orderByReferenceId from "./orderByReferenceId"; | ||
|
||
export default { | ||
orderById | ||
orderById, | ||
orderByReferenceId | ||
}; |
24 changes: 24 additions & 0 deletions
24
imports/plugins/core/orders/server/no-meteor/resolvers/Query/orderByReferenceId.js
This file contains 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,24 @@ | ||
import { decodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop"; | ||
|
||
/** | ||
* @name Query.orderByReferenceId | ||
* @method | ||
* @memberof Order/GraphQL | ||
* @summary Get an order by its reference ID | ||
* @param {Object} parentResult - unused | ||
* @param {ConnectionArgs} args - An object of all arguments that were sent by the client | ||
* @param {String} args.id - reference ID of the order | ||
* @param {String} args.shopId - shop ID of the order | ||
* @param {String} [args.token] - An anonymous order token, required if the order was placed without being logged in | ||
* @param {Object} context - An object containing the per-request state | ||
* @return {Promise<Object>|undefined} An Order object | ||
*/ | ||
export default async function orderByReferenceId(parentResult, args, context) { | ||
const { id, shopId, token } = args; | ||
|
||
return context.queries.orderByReferenceId(context, { | ||
orderReferenceId: id, | ||
shopId: decodeShopOpaqueId(shopId), | ||
token | ||
}); | ||
} |
This file contains 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
27 changes: 27 additions & 0 deletions
27
imports/plugins/core/versions/server/migrations/47_order_ref.js
This file contains 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,27 @@ | ||
import { Migrations } from "meteor/percolate:migrations"; | ||
import { Orders } from "/lib/collections"; | ||
import findAndConvertInBatches from "../util/findAndConvertInBatches"; | ||
|
||
Migrations.add({ | ||
version: 47, | ||
|
||
up() { | ||
findAndConvertInBatches({ | ||
collection: Orders, | ||
converter: (order) => { | ||
if (!order.referenceId) order.referenceId = order._id; | ||
return order; | ||
} | ||
}); | ||
}, | ||
|
||
down() { | ||
Orders.update({ | ||
referenceId: { $exists: true } | ||
}, { | ||
$unset: { | ||
referenceId: "" | ||
} | ||
}, { bypassCollection2: true }); | ||
} | ||
}); |
This file contains 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 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 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 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 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 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