merchi_sdk_js 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/dist/address.js +109 -0
  2. package/dist/assignment.js +175 -0
  3. package/dist/automatic_payment_relationship.js +72 -0
  4. package/dist/backup.js +32 -0
  5. package/dist/bank.js +25 -0
  6. package/dist/cart.js +133 -0
  7. package/dist/cart_item.js +71 -0
  8. package/dist/cart_shipment_group.js +23 -0
  9. package/dist/cart_shipment_quote.js +26 -0
  10. package/dist/category.js +68 -0
  11. package/dist/company.js +248 -0
  12. package/dist/company_invitation.js +70 -0
  13. package/dist/component.js +107 -0
  14. package/dist/component_tag.js +60 -0
  15. package/dist/component_version.js +21 -0
  16. package/dist/country_tax.js +93 -0
  17. package/dist/dictionary.js +130 -0
  18. package/dist/discount.js +22 -0
  19. package/dist/discount_group.js +18 -0
  20. package/dist/domain.js +245 -0
  21. package/dist/domain_invitation.js +17 -0
  22. package/dist/domain_tag.js +87 -0
  23. package/dist/domain_types.js +22 -0
  24. package/dist/draft.js +97 -0
  25. package/dist/draft_comment.js +45 -0
  26. package/dist/draft_template.js +39 -0
  27. package/dist/email_address.js +34 -0
  28. package/dist/email_counter.js +47 -0
  29. package/dist/enrolled_domain.js +88 -0
  30. package/dist/exchange_rate.js +66 -0
  31. package/dist/field_types.js +19 -0
  32. package/dist/helpers.js +86 -0
  33. package/dist/internal_tag.js +98 -0
  34. package/dist/inventory.js +100 -0
  35. package/dist/inventory_unit_variation.js +19 -0
  36. package/dist/invoice.js +225 -0
  37. package/dist/invoice_types.js +11 -0
  38. package/dist/item.js +25 -0
  39. package/dist/job.js +536 -0
  40. package/dist/job_comment.js +45 -0
  41. package/dist/job_status.js +47 -0
  42. package/dist/matching_inventory.js +21 -0
  43. package/dist/md5.js +149 -0
  44. package/dist/menu.js +37 -0
  45. package/dist/menu_item.js +24 -0
  46. package/dist/merchi.js +1004 -0
  47. package/dist/merchi_file.js +165 -0
  48. package/dist/model.js +753 -0
  49. package/dist/notification.js +151 -0
  50. package/dist/notification_types.js +199 -0
  51. package/dist/output.cjs.js +31317 -0
  52. package/dist/output.esm.js +31312 -0
  53. package/dist/page.js +41 -0
  54. package/dist/payment.js +32 -0
  55. package/dist/payment_device.js +21 -0
  56. package/dist/payment_types.js +20 -0
  57. package/dist/phone_number.js +37 -0
  58. package/dist/product.js +288 -0
  59. package/dist/product_types.js +32 -0
  60. package/dist/production_comment.js +44 -0
  61. package/dist/quote.js +91 -0
  62. package/dist/quote_item.js +59 -0
  63. package/dist/roles.js +29 -0
  64. package/dist/seo_domain_page.js +42 -0
  65. package/dist/session.js +103 -0
  66. package/dist/set.js +29 -0
  67. package/dist/shipment.js +181 -0
  68. package/dist/shipment_item.js +17 -0
  69. package/dist/shipment_item_fulfillment.js +17 -0
  70. package/dist/shipment_method.js +81 -0
  71. package/dist/shipment_method_variation.js +38 -0
  72. package/dist/subscription_plan.js +75 -0
  73. package/dist/supply_domain.js +65 -0
  74. package/dist/system_role.js +12 -0
  75. package/dist/theme.js +180 -0
  76. package/dist/theme_css_setting.js +61 -0
  77. package/dist/theme_status.js +11 -0
  78. package/dist/user.js +409 -0
  79. package/dist/user_company.js +19 -0
  80. package/dist/user_types.js +23 -0
  81. package/dist/uuid.js +12 -0
  82. package/dist/variation.js +233 -0
  83. package/dist/variation_field.js +233 -0
  84. package/dist/variation_fields_option.js +41 -0
  85. package/dist/variation_option.js +62 -0
  86. package/dist/variations_group.js +43 -0
  87. package/dist/white_label_accessibilities.js +11 -0
  88. package/package.json +30 -0
  89. package/src/address.js +107 -0
  90. package/src/assignment.js +165 -0
  91. package/src/automatic_payment_relationship.js +65 -0
  92. package/src/backup.js +29 -0
  93. package/src/bank.js +21 -0
  94. package/src/cart.js +131 -0
  95. package/src/cart_item.js +71 -0
  96. package/src/cart_shipment_group.js +20 -0
  97. package/src/cart_shipment_quote.js +23 -0
  98. package/src/category.js +62 -0
  99. package/src/company.js +267 -0
  100. package/src/company_invitation.js +63 -0
  101. package/src/component.js +100 -0
  102. package/src/component_tag.js +53 -0
  103. package/src/component_version.js +17 -0
  104. package/src/country_tax.js +89 -0
  105. package/src/dictionary.js +135 -0
  106. package/src/discount.js +19 -0
  107. package/src/discount_group.js +15 -0
  108. package/src/domain.js +254 -0
  109. package/src/domain_invitation.js +13 -0
  110. package/src/domain_tag.js +79 -0
  111. package/src/domain_types.js +18 -0
  112. package/src/draft.js +92 -0
  113. package/src/draft_comment.js +41 -0
  114. package/src/draft_template.js +35 -0
  115. package/src/email_address.js +27 -0
  116. package/src/email_counter.js +42 -0
  117. package/src/enrolled_domain.js +79 -0
  118. package/src/exchange_rate.js +61 -0
  119. package/src/field_types.js +15 -0
  120. package/src/helpers.js +81 -0
  121. package/src/internal_tag.js +90 -0
  122. package/src/inventory.js +99 -0
  123. package/src/inventory_unit_variation.js +18 -0
  124. package/src/invoice.js +224 -0
  125. package/src/invoice_types.js +7 -0
  126. package/src/item.js +22 -0
  127. package/src/job.js +616 -0
  128. package/src/job_comment.js +41 -0
  129. package/src/job_status.js +51 -0
  130. package/src/matching_inventory.js +17 -0
  131. package/src/md5.js +162 -0
  132. package/src/menu.js +32 -0
  133. package/src/menu_item.js +22 -0
  134. package/src/merchi.js +1074 -0
  135. package/src/merchi_file.js +163 -0
  136. package/src/model.js +820 -0
  137. package/src/notification.js +153 -0
  138. package/src/notification_types.js +246 -0
  139. package/src/page.js +38 -0
  140. package/src/payment.js +32 -0
  141. package/src/payment_device.js +17 -0
  142. package/src/payment_types.js +18 -0
  143. package/src/phone_number.js +30 -0
  144. package/src/product.js +309 -0
  145. package/src/product_types.js +28 -0
  146. package/src/production_comment.js +40 -0
  147. package/src/quote.js +89 -0
  148. package/src/quote_item.js +51 -0
  149. package/src/roles.js +27 -0
  150. package/src/seo_domain_page.js +35 -0
  151. package/src/session.js +102 -0
  152. package/src/set.js +28 -0
  153. package/src/shipment.js +191 -0
  154. package/src/shipment_item.js +13 -0
  155. package/src/shipment_item_fulfillment.js +13 -0
  156. package/src/shipment_method.js +73 -0
  157. package/src/shipment_method_variation.js +34 -0
  158. package/src/subscription_plan.js +68 -0
  159. package/src/supply_domain.js +60 -0
  160. package/src/system_role.js +8 -0
  161. package/src/theme.js +188 -0
  162. package/src/theme_css_setting.js +54 -0
  163. package/src/theme_status.js +6 -0
  164. package/src/user.js +442 -0
  165. package/src/user_company.js +15 -0
  166. package/src/user_types.js +19 -0
  167. package/src/uuid.js +3 -0
  168. package/src/variation.js +257 -0
  169. package/src/variation_field.js +261 -0
  170. package/src/variation_fields_option.js +41 -0
  171. package/src/variation_option.js +59 -0
  172. package/src/variations_group.js +43 -0
  173. package/src/white_label_accessibilities.js +6 -0
@@ -0,0 +1,35 @@
1
+ import { addPropertyTo, serialise, create, enumerateFiles,
2
+ fromJson } from './model.js';
3
+ import { Job } from './job.js';
4
+ import { Product } from './product.js';
5
+ import { MerchiFile } from './merchi_file.js';
6
+
7
+ export function DraftTemplate() {
8
+ this.resource = '/draft_comments';
9
+ this.json = 'draftComment';
10
+
11
+ addPropertyTo(this, 'id');
12
+ addPropertyTo(this, 'product', Product);
13
+ addPropertyTo(this, 'file', MerchiFile);
14
+ addPropertyTo(this, 'job', Job);
15
+ addPropertyTo(this, 'date');
16
+ addPropertyTo(this, 'name');
17
+ addPropertyTo(this, 'description');
18
+ addPropertyTo(this, 'height');
19
+ addPropertyTo(this, 'width');
20
+
21
+ this.create = function (options) {
22
+ var data = serialise(this),
23
+ self = this;
24
+ function handleResponse(result) {
25
+ options.success(fromJson(self, result[self.json]));
26
+ }
27
+ create({resource: this.resource,
28
+ parameters: data[0],
29
+ files: enumerateFiles(data[1]),
30
+ success: handleResponse,
31
+ as_domain: options.as_domain,
32
+ error: options.error,
33
+ embed: options.embed});
34
+ };
35
+ }
@@ -0,0 +1,27 @@
1
+ import { generateUUID } from './uuid.js';
2
+ import { addPropertyTo, getList, fromJsonList } from './model.js';
3
+
4
+ export function EmailAddress() {
5
+ this.resource = '/email_addresses';
6
+ this.json = 'emailAddress';
7
+ this.temporaryId = generateUUID();
8
+
9
+ addPropertyTo(this, 'id');
10
+ addPropertyTo(this, 'emailAddress');
11
+ }
12
+
13
+ export function EmailAddresses() {
14
+ this.resource = '/email_addresses';
15
+ this.json = 'emailAddresses';
16
+ this.single = EmailAddress;
17
+
18
+ this.get = function (success, error, offset, limit, q) {
19
+ var self = this;
20
+ function handleResponse(result) {
21
+ success(fromJsonList(self, result,
22
+ {makesDirty: false}));
23
+ }
24
+ getList(this.resource, handleResponse, error,
25
+ {offset: offset, limit: limit, q: q});
26
+ };
27
+ }
@@ -0,0 +1,42 @@
1
+ import { addPropertyTo, serialise, getList, fromJsonList, fromJson, patchOne } from './model.js';
2
+
3
+ export function EmailCounter() {
4
+ this.resource = '/email_counters';
5
+ this.json = 'emailCounter';
6
+
7
+ addPropertyTo(this, 'emailAddress');
8
+ addPropertyTo(this, 'unsubscribed');
9
+ addPropertyTo(this, 'silenced');
10
+ addPropertyTo(this, 'tokens');
11
+
12
+ this.patch = function (success, error, embed) {
13
+ var self = this,
14
+ data = serialise(this, undefined, undefined, undefined,
15
+ {excludeOld: true})[0];
16
+ function handleResponse(result) {
17
+ success(fromJson(self, result[self.json]));
18
+ }
19
+ patchOne({resource: this.resource,
20
+ id: this.emailAddress(),
21
+ success: handleResponse,
22
+ error: error,
23
+ data: data,
24
+ embed: embed});
25
+ };
26
+ }
27
+
28
+ export function EmailCounters() {
29
+ this.resource = '/email_counters';
30
+ this.json = 'emailCounters';
31
+ this.single = EmailCounter;
32
+
33
+ this.get = function (success, error, parameters) {
34
+ var self = this;
35
+ function handleResponse(result) {
36
+ success(fromJsonList(self, result,
37
+ {makesDirty: false}));
38
+ }
39
+ getList(this.resource, handleResponse, error,
40
+ parameters);
41
+ };
42
+ }
@@ -0,0 +1,79 @@
1
+ import { generateUUID } from './uuid.js';
2
+ import { addPropertyTo, serialise, fromJson, create, enumerateFiles,
3
+ getOne, patchOne, deleteOne, getList, fromJsonList } from './model.js';
4
+ import { Domain } from './domain.js';
5
+ import { User } from './user.js';
6
+
7
+ export function EnrolledDomain() {
8
+ this.resource = '/enrolled_domains';
9
+ this.json = 'enrolledDomain';
10
+ this.temporaryId = generateUUID();
11
+
12
+ addPropertyTo(this, 'id');
13
+ addPropertyTo(this, 'role');
14
+ addPropertyTo(this, 'user', User);
15
+ addPropertyTo(this, 'domain', Domain);
16
+ addPropertyTo(this, 'isJobsAssignee');
17
+
18
+
19
+ this.create = function (success, error, embed, as_domain) {
20
+ var self = this,
21
+ data = serialise(self);
22
+ function handleResponse(result) {
23
+ success(fromJson(self, result[self.json]));
24
+ }
25
+ create({resource: this.resource,
26
+ parameters: data[0],
27
+ as_domain: as_domain,
28
+ files: enumerateFiles(data[1]),
29
+ success: handleResponse,
30
+ error: error,
31
+ embed: embed});
32
+ };
33
+ this.get = function (success, error) {
34
+ var self = this;
35
+ function handleResponse(result) {
36
+ success(fromJson(self, result[self.json],
37
+ {makesDirty: false}));
38
+ }
39
+ getOne({resource: this.resource,
40
+ id: this.id(),
41
+ success: handleResponse,
42
+ error: error});
43
+ };
44
+
45
+ this.patch = function (success, error, embed, asDomain) {
46
+ var self = this,
47
+ data = serialise(self, undefined, undefined, undefined,
48
+ {excludeOld: true})[0];
49
+ function handleResponse(result) {
50
+ success(fromJson(self, result[self.json],
51
+ {makesDirty: false}));
52
+ }
53
+ patchOne({resource: this.resource,
54
+ id: this.id(),
55
+ as_domain: asDomain,
56
+ success: handleResponse,
57
+ error: error,
58
+ data: data,
59
+ embed: embed});
60
+ };
61
+
62
+ this.destroy = function (success, error) {
63
+ deleteOne(this.resource + "/" + this.id(), success, error);
64
+ };
65
+ }
66
+
67
+ export function EnrolledDomains() {
68
+ this.resource = '/enrolled_domains';
69
+ this.json = 'enrolledDomains';
70
+ this.single = EnrolledDomain;
71
+
72
+ this.get = function (success, error, parameters) {
73
+ var self = this;
74
+ function handleResponse(result) {
75
+ success(fromJsonList(self, result, {makesDirty: false}));
76
+ }
77
+ getList(this.resource, handleResponse, error, parameters);
78
+ };
79
+ }
@@ -0,0 +1,61 @@
1
+ import { generateUUID } from './uuid.js';
2
+ import { addPropertyTo, serialise, fromJson, create, enumerateFiles, deleteOne,
3
+ getOne, fromJsonList, getList } from './model.js';
4
+
5
+
6
+ export function ExchangeRate() {
7
+ this.resource = '/exchange_rates';
8
+ this.json = 'exchangeRate';
9
+ this.temporaryId = generateUUID();
10
+
11
+ addPropertyTo(this, 'id');
12
+ addPropertyTo(this, 'fromCurrency');
13
+ addPropertyTo(this, 'toCurrency');
14
+ addPropertyTo(this, 'rate');
15
+ addPropertyTo(this, 'lastUpdated');
16
+
17
+ this.create = function (success, error, embed, domainId) {
18
+ var data = serialise(this),
19
+ self = this;
20
+ function handleResponse(result) {
21
+ success(fromJson(self, result[self.json]));
22
+ }
23
+ create({resource: this.resource,
24
+ parameters: data[0],
25
+ files: enumerateFiles(data[1]),
26
+ success: handleResponse,
27
+ error: error,
28
+ embed: embed,
29
+ as_domain: domainId});
30
+ };
31
+
32
+ this.get = function (success, error) {
33
+ var self = this;
34
+ function handleResponse(result) {
35
+ success(fromJson(self, result[self.json],
36
+ {makesDirty: false}));
37
+ }
38
+ getOne({resource: this.resource,
39
+ id: this.id(),
40
+ success: handleResponse,
41
+ error: error});
42
+ };
43
+
44
+ this.destroy = function (success, error) {
45
+ deleteOne(this.resource + "/" + this.id(), success, error);
46
+ };
47
+ }
48
+
49
+ export function ExchangeRates() {
50
+ this.resource = '/exchange_rates';
51
+ this.json = 'exchangeRates';
52
+ this.single = ExchangeRate;
53
+
54
+ this.get = function (success, error, parameters) {
55
+ var self = this;
56
+ function handleResponse(result) {
57
+ success(fromJsonList(self, result, {makesDirty: false}));
58
+ }
59
+ getList(this.resource, handleResponse, error, parameters);
60
+ };
61
+ }
@@ -0,0 +1,15 @@
1
+ import { Dictionary } from './dictionary.js';
2
+
3
+ export const fieldTypes = new Dictionary();
4
+
5
+ fieldTypes.add("TEXT_INPUT", 1);
6
+ fieldTypes.add("SELECT", 2);
7
+ fieldTypes.add("FILE_UPLOAD", 3);
8
+ fieldTypes.add("TEXT_AREA", 4);
9
+ fieldTypes.add("NUMBER_INPUT", 5);
10
+ fieldTypes.add("CHECKBOX", 6);
11
+ fieldTypes.add("RADIO", 7);
12
+ fieldTypes.add("FIELD_INSTRUCTIONS", 8);
13
+ fieldTypes.add("IMAGE_SELECT", 9);
14
+ fieldTypes.add("COLOUR_PICKER", 10);
15
+ fieldTypes.add("COLOUR_SELECT", 11);
package/src/helpers.js ADDED
@@ -0,0 +1,81 @@
1
+ import { isBrowser, isJsDom } from "browser-or-node";
2
+
3
+ export function id(x) {
4
+ return x;
5
+ }
6
+
7
+ export function isUndefined(x) {
8
+ return x === undefined;
9
+ }
10
+
11
+ export function notEmpty(value) {
12
+ return !(isUndefined(value) || value === null || value === "");
13
+ }
14
+
15
+ export function isNull(x) {
16
+ return x === null;
17
+ }
18
+
19
+ export function isUndefinedOrNull(x) {
20
+ return isUndefined(x) || isNull(x);
21
+ }
22
+
23
+ export function getGlobal() {
24
+ if (isBrowser || isJsDom) {
25
+ return window;
26
+ }
27
+ return global;
28
+ }
29
+
30
+ export function isArray(x) {
31
+ return Array.isArray(x);
32
+ }
33
+
34
+ export function notEmptyArray(array) {
35
+ return isArray(array) && array.length > 0;
36
+ }
37
+
38
+ export function removeObjectFromArrayBasedOnCondition(array, condition) {
39
+ array.splice(array.findIndex(condition), 1);
40
+ }
41
+
42
+ export function removeObjectFromArrayWithIntegerValue(array, objectKey, value) {
43
+ var key = !objectKey ? objectKey : 'id',
44
+ intValue = parseInt(value, 10);
45
+ removeObjectFromArrayBasedOnCondition(array, function (obj) {
46
+ return obj[key]() === intValue;
47
+ });
48
+ }
49
+
50
+ export function clone(oldObject) {
51
+ return Object.assign(oldObject, {});
52
+ }
53
+
54
+ export function any(iterable, condition) {
55
+ for (var index = 0; index < iterable.length; ++index) {
56
+ if (!isUndefined(condition) && condition(iterable[index])) {
57
+ return true;
58
+ } else if (iterable[index]) {
59
+ return true;
60
+ }
61
+ }
62
+ return false;
63
+ }
64
+
65
+ export function sortArray(array, objectKey, desc) {
66
+ return array ? array.sort(function (a, b) {
67
+ if (desc) {
68
+ return b[objectKey]() - a[objectKey]();
69
+ } else {
70
+ return a[objectKey]() - b[objectKey]();
71
+ }
72
+ }) : [];
73
+ }
74
+
75
+ export function sortArrayByObjectKey(array, objectKey) {
76
+ return sortArray(array, objectKey);
77
+ }
78
+
79
+ export function sortArrayByObjectKeyDescending(array, objectKey) {
80
+ return sortArray(array, objectKey, true);
81
+ }
@@ -0,0 +1,90 @@
1
+ import { generateUUID } from './uuid.js';
2
+ import { addPropertyTo, serialise, create, fromJson, patchOne, deleteOne,
3
+ fromJsonList, getList, enumerateFiles, getOne } from './model.js';
4
+ import { Company } from './company.js';
5
+ import { Domain } from './domain.js';
6
+ import { Invoice } from './invoice.js';
7
+ import { Job } from './job.js';
8
+ import { Product } from './product.js';
9
+ import { Shipment } from './shipment.js';
10
+ import { Theme } from './theme.js';
11
+ import { User } from './user.js';
12
+
13
+ export function InternalTag() {
14
+ this.resource = '/internal_tags';
15
+ this.json = 'internalTag';
16
+ this.temporaryId = generateUUID();
17
+
18
+ addPropertyTo(this, 'id');
19
+ addPropertyTo(this, 'name');
20
+ addPropertyTo(this, 'description');
21
+ addPropertyTo(this, 'colour');
22
+ addPropertyTo(this, 'companies', Company);
23
+ addPropertyTo(this, 'domains', Domain);
24
+ addPropertyTo(this, 'invoices', Invoice);
25
+ addPropertyTo(this, 'jobs', Job);
26
+ addPropertyTo(this, 'products', Product);
27
+ addPropertyTo(this, 'shipments', Shipment);
28
+ addPropertyTo(this, 'themes', Theme);
29
+ addPropertyTo(this, 'users', User)
30
+
31
+ this.create = function (success, error, embed, domainId) {
32
+ var data = serialise(this),
33
+ self = this;
34
+ function handleResponse(result) {
35
+ success(fromJson(self, result[self.json]));
36
+ }
37
+ create({resource: this.resource,
38
+ parameters: data[0],
39
+ files: enumerateFiles(data[1]),
40
+ success: handleResponse,
41
+ error: error,
42
+ embed: embed,
43
+ as_domain: domainId});
44
+ };
45
+
46
+ this.get = function (success, error) {
47
+ var self = this;
48
+ function handleResponse(result) {
49
+ success(fromJson(self, result[self.json],
50
+ {makesDirty: false}));
51
+ }
52
+ getOne({resource: this.resource,
53
+ id: this.id(),
54
+ success: handleResponse,
55
+ error: error});
56
+ };
57
+
58
+ this.patch = function (success, error, embed) {
59
+ var self = this,
60
+ data = serialise(this)[0];
61
+ function handleResponse(result) {
62
+ success(fromJson(self, result[self.json],
63
+ {makesDirty: false}));
64
+ }
65
+ patchOne({resource: this.resource,
66
+ id: this.id(),
67
+ success: handleResponse,
68
+ error: error,
69
+ data: data,
70
+ embed: embed});
71
+ };
72
+
73
+ this.destroy = function (success, error) {
74
+ deleteOne(this.resource + "/" + this.id(), success, error);
75
+ };
76
+ }
77
+
78
+ export function InternalTags() {
79
+ this.resource = '/internal_tags';
80
+ this.json = 'internalTags';
81
+ this.single = InternalTag;
82
+
83
+ this.get = function (success, error, parameters) {
84
+ var self = this;
85
+ function handleResponse(result) {
86
+ success(fromJsonList(self, result, {makesDirty: false}));
87
+ }
88
+ getList(this.resource, handleResponse, error, parameters);
89
+ };
90
+ }
@@ -0,0 +1,99 @@
1
+ import { generateUUID } from './uuid.js';
2
+ import { addPropertyTo, serialise, fromJson, create, getOne, deleteOne,
3
+ patchOne, fromJsonList, getList, enumerateFiles } from './model.js';
4
+ import { Address } from './address.js';
5
+ import { InventoryUnitVariation } from './inventory_unit_variation.js';
6
+ import { Product } from './product.js';
7
+
8
+ export function Inventory() {
9
+ this.resource = '/inventories';
10
+ this.json = 'inventory';
11
+ this.temporaryId = generateUUID();
12
+
13
+ addPropertyTo(this, 'id');
14
+ addPropertyTo(this, 'name');
15
+ addPropertyTo(this, 'notes');
16
+ addPropertyTo(this, 'quantity');
17
+ addPropertyTo(this, 'product', Product);
18
+ addPropertyTo(this, 'address', Address);
19
+ addPropertyTo(this, 'inventoryUnitVariations',
20
+ InventoryUnitVariation);
21
+
22
+ this.create = function (success, error, embed, domainId) {
23
+ var data = serialise(this),
24
+ self = this;
25
+ function handleResponse(result) {
26
+ success(fromJson(self, result[self.json]));
27
+ }
28
+ create({resource: this.resource,
29
+ parameters: data[0],
30
+ files: enumerateFiles(data[1]),
31
+ success: handleResponse,
32
+ error: error,
33
+ embed: embed,
34
+ as_domain: domainId});
35
+ };
36
+
37
+ this.get = function (success, error) {
38
+ var self = this;
39
+ function handleResponse(result) {
40
+ success(fromJson(self, result[self.json],
41
+ {makesDirty: false}));
42
+ }
43
+ getOne({resource: this.resource,
44
+ id: this.id(),
45
+ success: handleResponse,
46
+ error: error});
47
+ };
48
+
49
+ this.destroy = function (success, error) {
50
+ deleteOne(this.resource + "/" + this.id(), success, error);
51
+ };
52
+
53
+ this.patch = function (success, error, embed) {
54
+ var self = this,
55
+ data = serialise(this)[0];
56
+ function handleResponse(result) {
57
+ success(fromJson(self, result[self.json]));
58
+ }
59
+ patchOne({resource: this.resource,
60
+ id: this.id(),
61
+ success: handleResponse,
62
+ error: error,
63
+ data: data,
64
+ embed: embed});
65
+ };
66
+
67
+ this.update = function (success, error, embed) {
68
+ this.patch(success, error,
69
+ serialise(this, undefined, undefined, undefined,
70
+ {excludeOld: true})[0], embed);
71
+ };
72
+
73
+
74
+ this.isVariationFieldOptionSelected = function (option) {
75
+ var selectedVariations = this.inventoryUnitVariations() ?
76
+ this.inventoryUnitVariations() : [];
77
+ for (var i = 0; i < selectedVariations.length; i++) {
78
+ if (selectedVariations[i].optionId() === option.id()) {
79
+ return true;
80
+ }
81
+ }
82
+ return false;
83
+ };
84
+
85
+ }
86
+
87
+ export function Inventories() {
88
+ this.resource = '/inventories';
89
+ this.json = 'inventories';
90
+ this.single = Inventory;
91
+
92
+ this.get = function (success, error, parameters) {
93
+ var self = this;
94
+ function handleResponse(result) {
95
+ success(fromJsonList(self, result, {makesDirty: false}));
96
+ }
97
+ getList(this.resource, handleResponse, error, parameters);
98
+ };
99
+ }
@@ -0,0 +1,18 @@
1
+ import { addPropertyTo } from './model.js';
2
+ import { Inventory } from './inventory.js';
3
+ import { VariationFieldsOption } from './variation_fields_option.js';
4
+
5
+ export function InventoryUnitVariation() {
6
+ this.resource = '/inventory_unit_variations';
7
+ this.json = 'inventoryUnitVariation';
8
+
9
+ addPropertyTo(this, 'id');
10
+ addPropertyTo(this, 'inventory', Inventory);
11
+ addPropertyTo(
12
+ this, 'variationFieldsOption', VariationFieldsOption
13
+ );
14
+
15
+ this.optionId = function () {
16
+ return this.variationFieldsOption().id();
17
+ };
18
+ }