From b23471a87c2a8a55a10a9c3852f74f2f2a826580 Mon Sep 17 00:00:00 2001 From: Andrey Rublev Date: Fri, 4 Nov 2016 18:16:48 +0700 Subject: [PATCH 1/4] add link to account namespace in top navigation menu --- bin/leafdoc-templates/html.hbs | 1 + index.html | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/leafdoc-templates/html.hbs b/bin/leafdoc-templates/html.hbs index 7bf5562..6a4c4e3 100644 --- a/bin/leafdoc-templates/html.hbs +++ b/bin/leafdoc-templates/html.hbs @@ -32,6 +32,7 @@

FoxApi namespaces

@@ -222,6 +223,11 @@

Properties

Account Account instance + + orders + Orders + Orders instance + @@ -3070,6 +3076,33 @@

CreditCardUpdatePayload

+

Orders

+
+

Methods

+ +
+ + + +
+ + + + + + + + + + + + + +
MethodReturnsDescription
list()Promise
+ +
+ +

StoreCredits

Accessible via storeCredits property of FoxApi instance.

diff --git a/src/api/orders.js b/src/api/orders.js new file mode 100644 index 0000000..7d3f20a --- /dev/null +++ b/src/api/orders.js @@ -0,0 +1,38 @@ + +// @class Orders + +import * as endpoints from '../endpoints'; + +function buildQuery(customerId) { + return { + 'query': { + 'nested': { + 'path': 'customer', + 'query': { + 'term': { + 'customer.id': { + 'value': customerId + } + } + } + } + } + } +} + +export default class Orders { + constructor(api) { + this.api = api; + } + + // @method list(): Promise + list() { + const customerId = this.api.getCustomerId(); + if (customerId != null) { + const query = buildQuery(customerId); + return this.api.post(endpoints.orders, query); + } else { + return Promise.reject({errors: ['Please sign in first']}); + } + } +} diff --git a/src/endpoints.js b/src/endpoints.js index 8e3383d..bcf7ddb 100644 --- a/src/endpoints.js +++ b/src/endpoints.js @@ -46,3 +46,6 @@ export const storeCredits = `/search/store_credits_search_view/_search`; // account endpoints export const account = '/v1/my/account'; + +// orders endpoints +export const orders = '/search/admin/orders_search_view/_search'; diff --git a/src/index.js b/src/index.js index b057f2b..568aa9d 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ import CreditCards from './api/credit-cards'; import StoreCredits from './api/store-credits'; import Cart from './api/cart'; import Account from './api/account'; +import Orders from './api/orders'; import jwtDecode from 'jwt-decode'; export default class Api { @@ -54,6 +55,10 @@ export default class Api { // @property account: Account // Account instance this.account = new Account(this); + + // @property orders: Orders + // Orders instance + this.orders = new Orders(this); } // @method addAuth(jwt: String): FoxApi From 91e66f84f30554707a75cd01e9979c4ff7025833 Mon Sep 17 00:00:00 2001 From: Andrey Rublev Date: Mon, 7 Nov 2016 21:24:35 +0700 Subject: [PATCH 3/4] added changePassord & orders.get methods --- src/api/account.js | 9 +++++++++ src/api/orders.js | 5 +++++ src/endpoints.js | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/api/account.js b/src/api/account.js index 24a0607..3fa5b1a 100644 --- a/src/api/account.js +++ b/src/api/account.js @@ -18,4 +18,13 @@ export default class Account { update(payload) { return this.api.patch(endpoints.account, payload); } + + // @method changePassword(oldPassword: string, newPassword: string): Promise + // Changes password for account. + changePassword(oldPassword, newPassword) { + return this.api.post(endpoints.changePassword, { + oldPassword, + newPassword, + }); + } } diff --git a/src/api/orders.js b/src/api/orders.js index 7d3f20a..7b21f27 100644 --- a/src/api/orders.js +++ b/src/api/orders.js @@ -35,4 +35,9 @@ export default class Orders { return Promise.reject({errors: ['Please sign in first']}); } } + + // @method get(referenceNumber: string): Promise + get(referenceNumber) { + return this.api.get(endpoints.order(referenceNumber)); + } } diff --git a/src/endpoints.js b/src/endpoints.js index bcf7ddb..36857e9 100644 --- a/src/endpoints.js +++ b/src/endpoints.js @@ -46,6 +46,8 @@ export const storeCredits = `/search/store_credits_search_view/_search`; // account endpoints export const account = '/v1/my/account'; +export const changePassword = '/v1/my/account/change-password'; // orders endpoints export const orders = '/search/admin/orders_search_view/_search'; +export const order = referenceNumber => `/v1/my/orders/${referenceNumber}`; From 7997e3120bd75893be17a5fca382ce109e03ab57 Mon Sep 17 00:00:00 2001 From: Andrey Rublev Date: Mon, 7 Nov 2016 21:25:13 +0700 Subject: [PATCH 4/4] update docs --- index.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.html b/index.html index fc0ffcc..49d64f0 100644 --- a/index.html +++ b/index.html @@ -1127,6 +1127,11 @@

Methods

Promise<LoginResponse> Updates account. + + changePassword(<string> oldPassword, <string> newPassword) + Promise + Changes password for account. +
@@ -3098,6 +3103,11 @@

Methods

Promise + + get(<string> referenceNumber) + Promise + +