forked from MONEI/Shopify-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer.js
74 lines (64 loc) · 1.9 KB
/
customer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict';
const assign = require('lodash/assign');
const base = require('../mixins/base');
/**
* Creates a Customer instance.
*
* @param {Shopify} shopify Reference to the Shopify instance
* @constructor
* @public
*/
function Customer(shopify) {
this.shopify = shopify;
this.name = 'customers';
this.key = 'customer';
}
assign(Customer.prototype, base);
/**
* Returns a list of customers matching the given search parameters.
*
* @param {Object} params Search parameters
* @return {Promise} Promise that resolves with the result
* @public
*/
Customer.prototype.search = function search(params) {
const url = this.buildUrl('search', params);
return this.shopify.request(url, 'GET', this.name);
};
/**
* Generates and retrieve an account activation URL for a customer.
*
* @param {Number} id Customer ID
* @return {Promise} Promise that resolves with the result
* @public
*/
Customer.prototype.accountActivationUrl = function accountActivationUrl(id) {
const url = this.buildUrl(`${id}/account_activation_url`);
return this.shopify.request(url, 'POST', undefined, {
customer: { id }
}).then(body => body.account_activation_url);
};
/**
* Sends an account invite for the customer.
*
* @param {Number} id Customer ID
* @param {Object} params Optional params for adjusting the sent email
* @return {Promise} Promise that resolves with the result
* @public
*/
Customer.prototype.sendInvite = function sendInvite(id, params) {
const url = this.buildUrl(`${id}/send_invite`);
return this.shopify.request(url, 'POST', 'customer_invite', params || {});
};
/**
* Get all orders belonging to a customer.
*
* @param {Number} id Customer ID
* @return {Promise} Promise that resolves with the result
* @public
*/
Customer.prototype.orders = function orders(id) {
const url = this.buildUrl(`${id}/orders`);
return this.shopify.request(url, 'GET', 'orders');
};
module.exports = Customer;