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
2 changes: 2 additions & 0 deletions bin/leafdoc-templates/html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
<h4>FoxApi namespaces</h4>
<ul>
<li><a href="#auth">Auth</a></li>
<li><a href="#account">Account</a></li>
<li><a href="#addresses">Addresses</a></li>
<li><a href="#cart">Cart</a></li>
<li><a href="#orders">Orders</a></li>
<li><a href="#creditcards">Credit Cards</a></li>
<li><a href="#storecredits">Store Credits</a></li>
</ul>
Expand Down
44 changes: 44 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ <h4>Utils</h4>
<h4>FoxApi namespaces</h4>
<ul>
<li><a href="#auth">Auth</a></li>
<li><a href="#account">Account</a></li>
<li><a href="#addresses">Addresses</a></li>
<li><a href="#cart">Cart</a></li>
<li><a href="#orders">Orders</a></li>
<li><a href="#creditcards">Credit Cards</a></li>
<li><a href="#storecredits">Store Credits</a></li>
</ul>
Expand Down Expand Up @@ -221,6 +223,11 @@ <h3 id='foxapi-property'>Properties</h3>
<td><code><a href='#account'>Account</a></code></td>
<td>Account instance</td>
</tr>
<tr id='foxapi-orders'>
<td><code><b>orders</b>
<td><code><a href='#orders'>Orders</a></code></td>
<td>Orders instance</td>
</tr>
</tbody></table>

</section>
Expand Down Expand Up @@ -1120,6 +1127,11 @@ <h3 id='account-method'>Methods</h3>
<td><code>Promise&lt;<a href='#loginresponse'>LoginResponse</a>&gt;</code></td>
<td>Updates account.</td>
</tr>
<tr id='account-changepassword'>
<td><code><b>changePassword</b>(<nobr>&lt;string&gt;</nobr> <i>oldPassword</i>, <nobr>&lt;string&gt;</nobr> <i>newPassword</i>)</nobr></code></td>
<td><code>Promise</code></td>
<td>Changes password for account.</td>
</tr>
</tbody></table>

</section>
Expand Down Expand Up @@ -3069,6 +3081,38 @@ <h3 id='creditcardupdatepayload-field'>CreditCardUpdatePayload</h3>
</section>
<span id='creditcardsresponse'></span>

<h2 id='orders'>Orders</h2>
<section>
<h3 id='orders-method'>Methods</h3>

<section >



<div class='section-comments'></div>

<table><thead>
<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr id='orders-list'>
<td><code><b>list</b>()</nobr></code></td>
<td><code>Promise</code></td>
<td></td>
</tr>
<tr id='orders-get'>
<td><code><b>get</b>(<nobr>&lt;string&gt;</nobr> <i>referenceNumber</i>)</nobr></code></td>
<td><code>Promise</code></td>
<td></td>
</tr>
</tbody></table>

</section>

</section>
<h2 id='storecredits'>StoreCredits</h2><p>Accessible via <a href="#foxapi-storecredits">storeCredits</a> property of <a href="#foxapi">FoxApi</a> instance.</p>

<section>
Expand Down
9 changes: 9 additions & 0 deletions src/api/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
43 changes: 43 additions & 0 deletions src/api/orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

// @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']});
}
}

// @method get(referenceNumber: string): Promise
get(referenceNumber) {
return this.api.get(endpoints.order(referenceNumber));
}
}
5 changes: 5 additions & 0 deletions src/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +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}`;
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down