Skip to content

Commit b1d5399

Browse files
authored
Orders (#21)
* add link to account namespace in top navigation menu * added `orders.list` method * added changePassord & orders.get methods * update docs
1 parent 903b923 commit b1d5399

6 files changed

Lines changed: 108 additions & 0 deletions

File tree

bin/leafdoc-templates/html.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
<h4>FoxApi namespaces</h4>
3333
<ul>
3434
<li><a href="#auth">Auth</a></li>
35+
<li><a href="#account">Account</a></li>
3536
<li><a href="#addresses">Addresses</a></li>
3637
<li><a href="#cart">Cart</a></li>
38+
<li><a href="#orders">Orders</a></li>
3739
<li><a href="#creditcards">Credit Cards</a></li>
3840
<li><a href="#storecredits">Store Credits</a></li>
3941
</ul>

index.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ <h4>Utils</h4>
3232
<h4>FoxApi namespaces</h4>
3333
<ul>
3434
<li><a href="#auth">Auth</a></li>
35+
<li><a href="#account">Account</a></li>
3536
<li><a href="#addresses">Addresses</a></li>
3637
<li><a href="#cart">Cart</a></li>
38+
<li><a href="#orders">Orders</a></li>
3739
<li><a href="#creditcards">Credit Cards</a></li>
3840
<li><a href="#storecredits">Store Credits</a></li>
3941
</ul>
@@ -221,6 +223,11 @@ <h3 id='foxapi-property'>Properties</h3>
221223
<td><code><a href='#account'>Account</a></code></td>
222224
<td>Account instance</td>
223225
</tr>
226+
<tr id='foxapi-orders'>
227+
<td><code><b>orders</b>
228+
<td><code><a href='#orders'>Orders</a></code></td>
229+
<td>Orders instance</td>
230+
</tr>
224231
</tbody></table>
225232

226233
</section>
@@ -1120,6 +1127,11 @@ <h3 id='account-method'>Methods</h3>
11201127
<td><code>Promise&lt;<a href='#loginresponse'>LoginResponse</a>&gt;</code></td>
11211128
<td>Updates account.</td>
11221129
</tr>
1130+
<tr id='account-changepassword'>
1131+
<td><code><b>changePassword</b>(<nobr>&lt;string&gt;</nobr> <i>oldPassword</i>, <nobr>&lt;string&gt;</nobr> <i>newPassword</i>)</nobr></code></td>
1132+
<td><code>Promise</code></td>
1133+
<td>Changes password for account.</td>
1134+
</tr>
11231135
</tbody></table>
11241136

11251137
</section>
@@ -3069,6 +3081,38 @@ <h3 id='creditcardupdatepayload-field'>CreditCardUpdatePayload</h3>
30693081
</section>
30703082
<span id='creditcardsresponse'></span>
30713083

3084+
<h2 id='orders'>Orders</h2>
3085+
<section>
3086+
<h3 id='orders-method'>Methods</h3>
3087+
3088+
<section >
3089+
3090+
3091+
3092+
<div class='section-comments'></div>
3093+
3094+
<table><thead>
3095+
<tr>
3096+
<th>Method</th>
3097+
<th>Returns</th>
3098+
<th>Description</th>
3099+
</tr>
3100+
</thead><tbody>
3101+
<tr id='orders-list'>
3102+
<td><code><b>list</b>()</nobr></code></td>
3103+
<td><code>Promise</code></td>
3104+
<td></td>
3105+
</tr>
3106+
<tr id='orders-get'>
3107+
<td><code><b>get</b>(<nobr>&lt;string&gt;</nobr> <i>referenceNumber</i>)</nobr></code></td>
3108+
<td><code>Promise</code></td>
3109+
<td></td>
3110+
</tr>
3111+
</tbody></table>
3112+
3113+
</section>
3114+
3115+
</section>
30723116
<h2 id='storecredits'>StoreCredits</h2><p>Accessible via <a href="#foxapi-storecredits">storeCredits</a> property of <a href="#foxapi">FoxApi</a> instance.</p>
30733117

30743118
<section>

src/api/account.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@ export default class Account {
1818
update(payload) {
1919
return this.api.patch(endpoints.account, payload);
2020
}
21+
22+
// @method changePassword(oldPassword: string, newPassword: string): Promise
23+
// Changes password for account.
24+
changePassword(oldPassword, newPassword) {
25+
return this.api.post(endpoints.changePassword, {
26+
oldPassword,
27+
newPassword,
28+
});
29+
}
2130
}

src/api/orders.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
// @class Orders
3+
4+
import * as endpoints from '../endpoints';
5+
6+
function buildQuery(customerId) {
7+
return {
8+
'query': {
9+
'nested': {
10+
'path': 'customer',
11+
'query': {
12+
'term': {
13+
'customer.id': {
14+
'value': customerId
15+
}
16+
}
17+
}
18+
}
19+
}
20+
}
21+
}
22+
23+
export default class Orders {
24+
constructor(api) {
25+
this.api = api;
26+
}
27+
28+
// @method list(): Promise
29+
list() {
30+
const customerId = this.api.getCustomerId();
31+
if (customerId != null) {
32+
const query = buildQuery(customerId);
33+
return this.api.post(endpoints.orders, query);
34+
} else {
35+
return Promise.reject({errors: ['Please sign in first']});
36+
}
37+
}
38+
39+
// @method get(referenceNumber: string): Promise
40+
get(referenceNumber) {
41+
return this.api.get(endpoints.order(referenceNumber));
42+
}
43+
}

src/endpoints.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ export const storeCredits = `/search/store_credits_search_view/_search`;
4646

4747
// account endpoints
4848
export const account = '/v1/my/account';
49+
export const changePassword = '/v1/my/account/change-password';
50+
51+
// orders endpoints
52+
export const orders = '/search/admin/orders_search_view/_search';
53+
export const order = referenceNumber => `/v1/my/orders/${referenceNumber}`;

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import CreditCards from './api/credit-cards';
1818
import StoreCredits from './api/store-credits';
1919
import Cart from './api/cart';
2020
import Account from './api/account';
21+
import Orders from './api/orders';
2122
import jwtDecode from 'jwt-decode';
2223

2324
export default class Api {
@@ -54,6 +55,10 @@ export default class Api {
5455
// @property account: Account
5556
// Account instance
5657
this.account = new Account(this);
58+
59+
// @property orders: Orders
60+
// Orders instance
61+
this.orders = new Orders(this);
5762
}
5863

5964
// @method addAuth(jwt: String): FoxApi

0 commit comments

Comments
 (0)