merchi_sdk_ts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/.babelrc +13 -0
  2. package/.eslintrc.cjs +43 -0
  3. package/LICENSE +21 -0
  4. package/README.md +2 -0
  5. package/jest.config.js +17 -0
  6. package/package.json +44 -0
  7. package/src/constants/auto_assign_production_on_actions.ts +6 -0
  8. package/src/constants/call_to_actions.test.ts +5 -0
  9. package/src/constants/call_to_actions.ts +14 -0
  10. package/src/constants/discount_types.test.ts +5 -0
  11. package/src/constants/discount_types.ts +3 -0
  12. package/src/constants/domain_types.test.ts +5 -0
  13. package/src/constants/domain_types.ts +12 -0
  14. package/src/constants/errors.ts +32 -0
  15. package/src/constants/event_types.test.ts +5 -0
  16. package/src/constants/event_types.ts +5 -0
  17. package/src/constants/field_types.test.ts +5 -0
  18. package/src/constants/field_types.ts +13 -0
  19. package/src/constants/input_types.test.ts +5 -0
  20. package/src/constants/input_types.ts +13 -0
  21. package/src/constants/inventory_status.test.ts +5 -0
  22. package/src/constants/inventory_statuses.ts +6 -0
  23. package/src/constants/invoice_types.test.ts +5 -0
  24. package/src/constants/invoice_types.ts +5 -0
  25. package/src/constants/item_types.test.ts +5 -0
  26. package/src/constants/item_types.ts +5 -0
  27. package/src/constants/job/drafting_status.test.ts +5 -0
  28. package/src/constants/job/drafting_status.ts +7 -0
  29. package/src/constants/job/payment_status.test.ts +5 -0
  30. package/src/constants/job/payment_status.ts +7 -0
  31. package/src/constants/job/production_status.test.ts +5 -0
  32. package/src/constants/job/production_status.ts +12 -0
  33. package/src/constants/job/shipment_status.test.ts +5 -0
  34. package/src/constants/job/shipment_status.ts +11 -0
  35. package/src/constants/job/supply_chain_request_status.test.ts +5 -0
  36. package/src/constants/job/supply_chain_request_status.ts +6 -0
  37. package/src/constants/job_priorities.test.ts +5 -0
  38. package/src/constants/job_priorities.ts +6 -0
  39. package/src/constants/job_status.test.ts +5 -0
  40. package/src/constants/job_status.ts +49 -0
  41. package/src/constants/job_types.test.ts +5 -0
  42. package/src/constants/job_types.ts +15 -0
  43. package/src/constants/notification_sections.test.ts +5 -0
  44. package/src/constants/notification_sections.ts +13 -0
  45. package/src/constants/notification_types.test.ts +5 -0
  46. package/src/constants/notification_types.ts +97 -0
  47. package/src/constants/notification_urgencies.test.ts +5 -0
  48. package/src/constants/notification_urgencies.ts +7 -0
  49. package/src/constants/payment_types.test.ts +5 -0
  50. package/src/constants/payment_types.ts +10 -0
  51. package/src/constants/platform.test.ts +15 -0
  52. package/src/constants/platform.ts +6 -0
  53. package/src/constants/product_types.test.ts +6 -0
  54. package/src/constants/product_types.ts +25 -0
  55. package/src/constants/rights.test.ts +5 -0
  56. package/src/constants/rights.ts +5 -0
  57. package/src/constants/robots_meta_directives.test.ts +5 -0
  58. package/src/constants/robots_meta_directives.ts +11 -0
  59. package/src/constants/roles.test.ts +5 -0
  60. package/src/constants/roles.ts +38 -0
  61. package/src/constants/shipment_companies.test.ts +5 -0
  62. package/src/constants/shipment_companies.ts +18 -0
  63. package/src/constants/shipment_services.test.ts +5 -0
  64. package/src/constants/shipment_services.ts +3 -0
  65. package/src/constants/system_roles.test.ts +5 -0
  66. package/src/constants/system_roles.ts +3 -0
  67. package/src/constants/theme_foundations.test.ts +5 -0
  68. package/src/constants/theme_foundations.ts +6 -0
  69. package/src/constants/theme_status.test.ts +5 -0
  70. package/src/constants/theme_status.ts +5 -0
  71. package/src/constants/user_types.test.ts +5 -0
  72. package/src/constants/user_types.ts +17 -0
  73. package/src/constants/white_label_accessibilities.test.ts +5 -0
  74. package/src/constants/white_label_accessibilities.ts +6 -0
  75. package/src/cookie.test.ts +11 -0
  76. package/src/cookie.ts +16 -0
  77. package/src/entities/address.test.ts +7 -0
  78. package/src/entities/address.ts +65 -0
  79. package/src/entities/assignment.test.ts +39 -0
  80. package/src/entities/assignment.ts +92 -0
  81. package/src/entities/automatic_payment_relationship.test.ts +8 -0
  82. package/src/entities/automatic_payment_relationship.ts +26 -0
  83. package/src/entities/backup.test.ts +7 -0
  84. package/src/entities/backup.ts +14 -0
  85. package/src/entities/bank.test.ts +7 -0
  86. package/src/entities/bank.ts +45 -0
  87. package/src/entities/cart.test.ts +50 -0
  88. package/src/entities/cart.ts +89 -0
  89. package/src/entities/cart_item.test.ts +33 -0
  90. package/src/entities/cart_item.ts +77 -0
  91. package/src/entities/cart_shipment_group.ts +21 -0
  92. package/src/entities/cart_shipment_quote.ts +33 -0
  93. package/src/entities/category.test.ts +57 -0
  94. package/src/entities/category.ts +37 -0
  95. package/src/entities/company.test.ts +7 -0
  96. package/src/entities/company.ts +275 -0
  97. package/src/entities/company_invitation.test.ts +7 -0
  98. package/src/entities/company_invitation.ts +33 -0
  99. package/src/entities/component.test.ts +14 -0
  100. package/src/entities/component.ts +92 -0
  101. package/src/entities/component_tag.test.ts +7 -0
  102. package/src/entities/component_tag.ts +17 -0
  103. package/src/entities/component_version.test.ts +7 -0
  104. package/src/entities/component_version.ts +30 -0
  105. package/src/entities/country_tax.test.ts +13 -0
  106. package/src/entities/country_tax.ts +46 -0
  107. package/src/entities/discount.test.ts +18 -0
  108. package/src/entities/discount.ts +34 -0
  109. package/src/entities/discount_group.test.ts +7 -0
  110. package/src/entities/discount_group.ts +28 -0
  111. package/src/entities/domain.test.ts +79 -0
  112. package/src/entities/domain.ts +246 -0
  113. package/src/entities/domain_invitation.test.ts +7 -0
  114. package/src/entities/domain_invitation.ts +36 -0
  115. package/src/entities/domain_tag.test.ts +7 -0
  116. package/src/entities/domain_tag.ts +42 -0
  117. package/src/entities/draft.test.ts +43 -0
  118. package/src/entities/draft.ts +88 -0
  119. package/src/entities/draft_comment.test.ts +7 -0
  120. package/src/entities/draft_comment.ts +54 -0
  121. package/src/entities/draft_template.test.ts +7 -0
  122. package/src/entities/draft_template.ts +40 -0
  123. package/src/entities/email_address.test.ts +7 -0
  124. package/src/entities/email_address.ts +24 -0
  125. package/src/entities/email_counter.test.ts +7 -0
  126. package/src/entities/email_counter.ts +20 -0
  127. package/src/entities/enrolled_domain.test.ts +7 -0
  128. package/src/entities/enrolled_domain.ts +40 -0
  129. package/src/entities/exchange_rate.test.ts +7 -0
  130. package/src/entities/exchange_rate.ts +22 -0
  131. package/src/entities/file.test.ts +43 -0
  132. package/src/entities/file.ts +172 -0
  133. package/src/entities/internal_tag.test.ts +7 -0
  134. package/src/entities/internal_tag.ts +51 -0
  135. package/src/entities/inventory.test.ts +28 -0
  136. package/src/entities/inventory.ts +56 -0
  137. package/src/entities/inventory_unit_variation.test.ts +7 -0
  138. package/src/entities/inventory_unit_variation.ts +29 -0
  139. package/src/entities/invoice.test.ts +43 -0
  140. package/src/entities/invoice.ts +179 -0
  141. package/src/entities/item.test.ts +19 -0
  142. package/src/entities/item.ts +44 -0
  143. package/src/entities/job.test.ts +95 -0
  144. package/src/entities/job.ts +349 -0
  145. package/src/entities/job_comment.test.ts +7 -0
  146. package/src/entities/job_comment.ts +50 -0
  147. package/src/entities/matching_inventory.ts +29 -0
  148. package/src/entities/menu.test.ts +7 -0
  149. package/src/entities/menu.ts +30 -0
  150. package/src/entities/menu_item.test.ts +7 -0
  151. package/src/entities/menu_item.ts +29 -0
  152. package/src/entities/notification.test.ts +7 -0
  153. package/src/entities/notification.ts +99 -0
  154. package/src/entities/page.test.ts +7 -0
  155. package/src/entities/page.ts +32 -0
  156. package/src/entities/payment.test.ts +19 -0
  157. package/src/entities/payment.ts +65 -0
  158. package/src/entities/payment_device.test.ts +7 -0
  159. package/src/entities/payment_device.ts +30 -0
  160. package/src/entities/phone_number.test.ts +7 -0
  161. package/src/entities/phone_number.ts +36 -0
  162. package/src/entities/product.test.ts +750 -0
  163. package/src/entities/product.ts +427 -0
  164. package/src/entities/production_comment.test.ts +7 -0
  165. package/src/entities/production_comment.ts +50 -0
  166. package/src/entities/quote.test.ts +98 -0
  167. package/src/entities/quote.ts +140 -0
  168. package/src/entities/quote_item.test.ts +50 -0
  169. package/src/entities/quote_item.ts +71 -0
  170. package/src/entities/seo_domain_page.test.ts +7 -0
  171. package/src/entities/seo_domain_page.ts +33 -0
  172. package/src/entities/session.test.ts +7 -0
  173. package/src/entities/session.ts +28 -0
  174. package/src/entities/shipment.test.ts +24 -0
  175. package/src/entities/shipment.ts +185 -0
  176. package/src/entities/shipment_item.test.ts +7 -0
  177. package/src/entities/shipment_item.ts +15 -0
  178. package/src/entities/shipment_item_fulfillment.test.ts +8 -0
  179. package/src/entities/shipment_item_fulfillment.ts +15 -0
  180. package/src/entities/shipment_method.test.ts +7 -0
  181. package/src/entities/shipment_method.ts +61 -0
  182. package/src/entities/shipment_method_variation.test.ts +7 -0
  183. package/src/entities/shipment_method_variation.ts +39 -0
  184. package/src/entities/short_url.test.ts +7 -0
  185. package/src/entities/short_url.ts +36 -0
  186. package/src/entities/subscription_plan.test.ts +7 -0
  187. package/src/entities/subscription_plan.ts +73 -0
  188. package/src/entities/supply_domain.test.ts +7 -0
  189. package/src/entities/supply_domain.ts +27 -0
  190. package/src/entities/system_role.test.ts +7 -0
  191. package/src/entities/system_role.ts +17 -0
  192. package/src/entities/theme.test.ts +38 -0
  193. package/src/entities/theme.ts +267 -0
  194. package/src/entities/theme_css_setting.test.ts +7 -0
  195. package/src/entities/theme_css_setting.ts +23 -0
  196. package/src/entities/user.test.ts +154 -0
  197. package/src/entities/user.ts +394 -0
  198. package/src/entities/user_company.test.ts +7 -0
  199. package/src/entities/user_company.ts +27 -0
  200. package/src/entities/variation.test.ts +7 -0
  201. package/src/entities/variation.ts +61 -0
  202. package/src/entities/variation_field.test.ts +76 -0
  203. package/src/entities/variation_field.ts +169 -0
  204. package/src/entities/variation_fields_option.test.ts +46 -0
  205. package/src/entities/variation_fields_option.ts +95 -0
  206. package/src/entities/variation_option.test.ts +7 -0
  207. package/src/entities/variation_option.ts +52 -0
  208. package/src/entities/variations_group.test.ts +7 -0
  209. package/src/entities/variations_group.ts +41 -0
  210. package/src/entity.ts +1002 -0
  211. package/src/merchi.test.ts +25 -0
  212. package/src/merchi.ts +379 -0
  213. package/src/request.test.ts +43 -0
  214. package/src/request.ts +124 -0
  215. package/src/test_util.ts +18 -0
  216. package/src/toasts.test.ts +38 -0
  217. package/src/toasts.ts +34 -0
  218. package/src/util/float.ts +12 -0
  219. package/src/util/query_string.test.ts +7 -0
  220. package/src/util/query_string.ts +11 -0
  221. package/src/util/validation.test.ts +16 -0
  222. package/src/util/validation.ts +2 -0
  223. package/src/uuid.test.ts +15 -0
  224. package/src/uuid.ts +8 -0
  225. package/tsconfig.json +23 -0
  226. package/webpack.config.cjs +27 -0
@@ -0,0 +1,427 @@
1
+ import * as _ from 'lodash';
2
+ import { CartItem } from './cart_item';
3
+ import { Category } from './category';
4
+ import { Company } from './company';
5
+ import { Component } from './component';
6
+ import { CountryTax } from './country_tax';
7
+ import { DiscountGroup } from './discount_group';
8
+ import { Domain } from './domain';
9
+ import { DomainTag } from './domain_tag';
10
+ import { DraftTemplate } from './draft_template';
11
+ import { Entity } from '../entity';
12
+ import { MerchiFile } from './file';
13
+ import { InternalTag } from './internal_tag';
14
+ import { Inventory } from './inventory';
15
+ import { Job } from './job';
16
+ import { SupplyDomain } from './supply_domain';
17
+ import { User } from './user';
18
+ import { VariationField } from './variation_field';
19
+ import { SeoDomainPage } from './seo_domain_page';
20
+ import { ShipmentMethod } from './shipment_method';
21
+ import {
22
+ AutoAssignProductionOnAction
23
+ } from '../constants/auto_assign_production_on_actions';
24
+
25
+ export class Product extends Entity {
26
+ protected static resourceName = 'products';
27
+ protected static singularName = 'product';
28
+ protected static pluralName = 'products';
29
+
30
+ @Product.property({type: Date})
31
+ public archived?: Date | null;
32
+
33
+ @Product.property()
34
+ public id?: number;
35
+
36
+ @Component.property({type: Date})
37
+ public created?: Date;
38
+
39
+ @Component.property({type: Date})
40
+ public updated?: Date;
41
+
42
+ @Component.property({type: 'User'})
43
+ public createdBy?: User | null;
44
+
45
+ @Component.property({type: 'User'})
46
+ public updatedBy?: User | null;
47
+
48
+ @Product.property()
49
+ public productType?: number;
50
+
51
+ @Product.property()
52
+ public minimum?: number;
53
+
54
+ @Product.property()
55
+ public minimumPerGroup?: boolean;
56
+
57
+ @Product.property()
58
+ public deliveryDaysNormal?: number;
59
+
60
+ @Product.property()
61
+ public unitPrice?: number;
62
+
63
+ @Product.property({embeddedByDefault: false})
64
+ public buyUnitPrice?: number;
65
+
66
+ @Product.property({type: 'DiscountGroup'})
67
+ public unitPriceDiscountGroup?: DiscountGroup | null;
68
+
69
+ @Product.property({arrayType: 'ShipmentMethod'})
70
+ public shipmentMethods?: ShipmentMethod[];
71
+
72
+ @Product.property()
73
+ public margin?: number;
74
+
75
+ @Product.property({type: Number})
76
+ public unitWeight?: number | null;
77
+
78
+ @Product.property({type: Number})
79
+ public unitHeight?: number | null;
80
+
81
+ @Product.property({type: Number})
82
+ public unitWidth?: number | null;
83
+
84
+ @Product.property({type: Number})
85
+ public unitDepth?: number | null;
86
+
87
+ @Product.property()
88
+ public name?: string;
89
+
90
+ @Product.property()
91
+ public country?: string;
92
+
93
+ @Product.property()
94
+ public currency?: string;
95
+
96
+ @Product.property({type: String})
97
+ public description?: string | null;
98
+
99
+ @Product.property({type: String})
100
+ public notes?: string | null;
101
+
102
+ @Product.property({type: String})
103
+ public internalUseNotes?: string;
104
+
105
+ @Product.property({type: String})
106
+ public internalUseAiContext?: string;
107
+
108
+ @Product.property({type: String})
109
+ public aiContext?: string;
110
+
111
+ @Product.property({type: String})
112
+ public shopifyProductId?: string | null;
113
+
114
+ @Product.property()
115
+ public useCompanyShipmentMethods?: boolean;
116
+
117
+ @Product.property()
118
+ public dropShipment?: boolean;
119
+
120
+ @Product.property()
121
+ public needsDrafting?: boolean;
122
+
123
+ @Product.property()
124
+ public needsProduction?: boolean;
125
+
126
+ @Product.property()
127
+ public needsShipping?: boolean;
128
+
129
+ @Product.property()
130
+ public needsInvoicing?: boolean;
131
+
132
+ @Product.property()
133
+ public needsInventory?: boolean;
134
+
135
+ @Product.property({type: Date})
136
+ public featureDeadline?: Date;
137
+
138
+ @Product.property()
139
+ public showFeatureDeadline?: boolean;
140
+
141
+ @Product.property()
142
+ public showPublic?: boolean;
143
+
144
+ @Product.property()
145
+ public showGroupBuyStatus?: boolean;
146
+
147
+ @Product.property({type: Number})
148
+ public groupBuyStatus?: number | null;
149
+
150
+ @Product.property()
151
+ public acceptSquare?: boolean;
152
+
153
+ @Product.property()
154
+ public acceptStripe?: boolean;
155
+
156
+ @Product.property()
157
+ public acceptPaypal?: boolean;
158
+
159
+ @Product.property()
160
+ public acceptUtrust?: boolean;
161
+
162
+ @Product.property()
163
+ public acceptBankTransfer?: boolean;
164
+
165
+ @Product.property()
166
+ public acceptPhonePayment?: boolean;
167
+
168
+ @Product.property()
169
+ public allowAutomaticPaymentSupply?: boolean;
170
+
171
+ @Product.property()
172
+ public allowGroupBuy?: boolean;
173
+
174
+ @Product.property()
175
+ public allowPaymentUpfront?: boolean;
176
+
177
+ @Product.property()
178
+ public allowQuotation?: boolean;
179
+
180
+ @Product.property()
181
+ public allowChainedInventoryCreation?: boolean;
182
+
183
+ @Product.property()
184
+ public allowClientDraftContribution?: boolean;
185
+
186
+ @Product.property()
187
+ public chainedInventoryHandlingUnitPrice?: number;
188
+
189
+ @Product.property()
190
+ public bestPrice?: number;
191
+
192
+ @Product.property()
193
+ public unitVolume?: number;
194
+
195
+ @Product.property({arrayType: 'Category'})
196
+ public categories?: Category[];
197
+
198
+ @Product.property({arrayType: 'Category'})
199
+ public platformCategories?: Category[];
200
+
201
+ @Product.property({arrayType: 'DiscountGroup'})
202
+ public discountGroups?: DiscountGroup[];
203
+
204
+ @Product.property()
205
+ public domain?: Domain;
206
+
207
+ @Product.property({type: CountryTax})
208
+ public taxType?: CountryTax | null;
209
+
210
+ @Product.property({type: Product})
211
+ public originalProduct?: Product | null;
212
+
213
+ @Product.property({type: Product})
214
+ public clonedFromProduct?: Product | null;
215
+
216
+ @Product.property({type: Product})
217
+ public chainedSupplierProduct?: Product | null;
218
+
219
+ @Product.property({arrayType: 'Product'})
220
+ public chainedSellerProducts?: Product[];
221
+
222
+ @Product.property({type: Product})
223
+ public chainedInventorySupplierProduct?: Product | null;
224
+
225
+ @Product.property({arrayType: 'Product'})
226
+ public chainedInventorySellerProducts?: Product[];
227
+
228
+ @Product.property({type: Component})
229
+ public component?: Component | null;
230
+
231
+ @Product.property({arrayType: 'MerchiFile'})
232
+ public images?: MerchiFile[];
233
+
234
+ @Product.property({arrayType: 'MerchiFile'})
235
+ public publicFiles?: MerchiFile[];
236
+
237
+ @Product.property({arrayType: 'MerchiFile'})
238
+ public productionFiles?: MerchiFile[];
239
+
240
+ @Product.property({arrayType: 'VariationField'})
241
+ public groupVariationFields?: VariationField[];
242
+
243
+ @Product.property({arrayType: 'VariationField'})
244
+ public independentVariationFields?: VariationField[];
245
+
246
+ @Product.property({arrayType: 'DomainTag'})
247
+ public tags?: DomainTag[];
248
+
249
+ @Product.property({arrayType: 'InternalTag'})
250
+ public internalTags?: InternalTag[];
251
+
252
+ @Product.property({arrayType: 'SeoDomainPage'})
253
+ public seoDomainPages?: SeoDomainPage[];
254
+
255
+ @Product.property({type: MerchiFile})
256
+ public featureImage?: MerchiFile | null;
257
+
258
+ @Product.property({type: 'Job'})
259
+ public createdByJob?: Job | null;
260
+
261
+ @Product.property({type: 'Job'})
262
+ public defaultJob?: Job;
263
+
264
+ @Product.property({arrayType: 'Company', jsonName: 'saved_by_companies'})
265
+ public savedByCompanies?: Company[];
266
+
267
+ @Product.property({arrayType: 'SupplyDomain'})
268
+ public suppliedByDomains?: SupplyDomain[];
269
+
270
+ @Product.property()
271
+ public autoAssignProductionOnAction?: AutoAssignProductionOnAction;
272
+
273
+ @Product.property({arrayType: 'SupplyDomain'})
274
+ public supplyDomains?: SupplyDomain[];
275
+
276
+ @Product.property()
277
+ public inventoriesOpen?: boolean;
278
+
279
+ @Product.property()
280
+ public supplyChainDisabled?: boolean;
281
+
282
+ @Product.property({arrayType: 'Inventory'})
283
+ public inventories?: Inventory[];
284
+
285
+ @Product.property({arrayType: 'CartItem'})
286
+ public cartItems?: CartItem[];
287
+
288
+ @Product.property({arrayType: 'Job'})
289
+ public jobs?: Job[];
290
+
291
+ @Product.property({arrayType: 'Job'})
292
+ public supplyChainRequestJobs?: Job[];
293
+
294
+ @Product.property({arrayType: 'User', jsonName: 'saved_by_users'})
295
+ public savedByUsers?: User[];
296
+
297
+ @Product.property({arrayType: 'User'})
298
+ public suppliers?: User[];
299
+
300
+ @Product.property({arrayType: 'DraftTemplate'})
301
+ public draftTemplates?: DraftTemplate[];
302
+
303
+ public duplicate = () => {
304
+ /* create a clone of this product on the backend, returning it. */
305
+ const constructor = this.constructor as typeof Product;
306
+ const resourceName = constructor.resourceName;
307
+ const singularName = constructor.singularName;
308
+ const resource = `/${resourceName}/${String(this.id)}/copy/`;
309
+ const fetchOptions = {method: 'POST'};
310
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
311
+ then((data: any) => {
312
+ const product = new this.merchi.Product();
313
+ product.fromJson(data[singularName]);
314
+ return product;
315
+ });
316
+ };
317
+
318
+ public primaryImage = () => {
319
+ if (this.featureImage === undefined) {
320
+ throw new Error('featureImage is undefined, did you forget to embed it?');
321
+ }
322
+ if (this.images === undefined) {
323
+ throw new Error('images is undefined, did you forget to embed it?');
324
+ }
325
+ if (this.featureImage !== null) {
326
+ return this.featureImage;
327
+ }
328
+ if (this.images.length > 0) {
329
+ return this.images[0];
330
+ }
331
+ return null;
332
+ };
333
+
334
+ public hasGroupVariationFields = () => {
335
+ if (this.groupVariationFields === undefined) {
336
+ const err = 'groupVariationFields is undefined, did you forget to embed' +
337
+ ' it?';
338
+ throw new Error(err);
339
+ }
340
+ return this.groupVariationFields.length > 0;
341
+ };
342
+
343
+ public hasIndependentVariationFields = () => {
344
+ if (this.independentVariationFields === undefined) {
345
+ const err = 'independentVariationFields is undefined, did you forget to' +
346
+ ' embed it?';
347
+ throw new Error(err);
348
+ }
349
+ return this.independentVariationFields.length > 0;
350
+ };
351
+
352
+ public allVariationFields = () => {
353
+ if (this.groupVariationFields === undefined) {
354
+ const err = 'groupVariationFields is undefined, did you forget to embed' +
355
+ ' it?';
356
+ throw new Error(err);
357
+ }
358
+ if (this.independentVariationFields === undefined) {
359
+ const err = 'independentVariationFields is undefined, did you forget to' +
360
+ ' embed it?';
361
+ throw new Error(err);
362
+ }
363
+ const result: VariationField[] = [];
364
+ return result.concat(this.groupVariationFields,
365
+ this.independentVariationFields);
366
+ };
367
+
368
+ public buildEmptyVariations = () => {
369
+ if (this.independentVariationFields === undefined) {
370
+ const err = 'independentVariationFields is undefined, did you forget to' +
371
+ ' embed it?';
372
+ throw new Error(err);
373
+ }
374
+ const iVF: VariationField[] =
375
+ _.orderBy(this.independentVariationFields, ['position'], ['asc']);
376
+ return iVF.map(field => field.buildEmptyVariation());
377
+ };
378
+
379
+ public buildEmptyVariationGroup = () => {
380
+ if (this.groupVariationFields === undefined) {
381
+ const err = 'groupVariationFields is undefined, did you forget to embed' +
382
+ ' it?';
383
+ throw new Error(err);
384
+ }
385
+ const result = new this.merchi.VariationsGroup();
386
+ const variations = [];
387
+ let cost = 0;
388
+ const sortedFields = _.orderBy(
389
+ this.groupVariationFields, ['position'], ['asc']);
390
+ result.quantity = 0;
391
+ for (const variationField of sortedFields) {
392
+ const empty = variationField.buildEmptyVariation();
393
+ variations.push(empty);
394
+ cost += empty.cost as number;
395
+ }
396
+ result.groupCost = cost;
397
+ result.variations = variations;
398
+ return result;
399
+ };
400
+
401
+ public removeVariationField = (variationField: VariationField) => {
402
+ if (variationField.independent === undefined) {
403
+ throw new Error('variation.independent is undefined, did you ' +
404
+ 'forget to embed it?');
405
+ }
406
+ if (this.independentVariationFields === undefined) {
407
+ const err = 'independentVariationFields is undefined, did you forget to' +
408
+ ' embed it?';
409
+ throw new Error(err);
410
+ }
411
+ if (this.groupVariationFields === undefined) {
412
+ const err = 'groupVariationFields is undefined, did you forget to embed' +
413
+ ' it?';
414
+ throw new Error(err);
415
+ }
416
+ const variationFields = variationField.independent ?
417
+ this.independentVariationFields : this.groupVariationFields;
418
+ const index = variationFields.findIndex(v => {
419
+ if (v.id === undefined) {
420
+ throw new Error('variation id is undefined, did you forget to ' +
421
+ 'embed it?');
422
+ }
423
+ return v.id === variationField.id;
424
+ });
425
+ return variationFields.splice(index, 1);
426
+ };
427
+ }
@@ -0,0 +1,7 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make ProductionComment', () => {
4
+ const merchi = new Merchi();
5
+ const productionComment = new merchi.ProductionComment();
6
+ expect(productionComment).toBeTruthy();
7
+ });
@@ -0,0 +1,50 @@
1
+ import { Assignment } from './assignment';
2
+ import { Entity } from '../entity';
3
+ import { MerchiFile } from './file';
4
+ import { Notification } from './notification';
5
+ import { User } from './user';
6
+
7
+ export class ProductionComment extends Entity {
8
+ protected static resourceName = 'production_comments';
9
+ protected static singularName = 'productionComment';
10
+ protected static pluralName = 'productionComments';
11
+
12
+ @ProductionComment.property({type: Date})
13
+ public archived?: Date | null;
14
+
15
+ @ProductionComment.property()
16
+ public id?: number;
17
+
18
+ @ProductionComment.property({type: Date})
19
+ public date?: Date | null;
20
+
21
+ @ProductionComment.property()
22
+ public urgency?: number;
23
+
24
+ @ProductionComment.property()
25
+ public text?: string;
26
+
27
+ @ProductionComment.property()
28
+ public isUrgentQuestion?: boolean;
29
+
30
+ @ProductionComment.property()
31
+ public sendSms?: boolean;
32
+
33
+ @ProductionComment.property()
34
+ public sendEmail?: boolean;
35
+
36
+ @ProductionComment.property({arrayType: "MerchiFile"})
37
+ public files?: MerchiFile[];
38
+
39
+ @ProductionComment.property()
40
+ public user?: User;
41
+
42
+ @ProductionComment.property({arrayType: 'User'})
43
+ public forwards?: User[];
44
+
45
+ @ProductionComment.property({arrayType: 'Notification'})
46
+ public notifications?: Notification[];
47
+
48
+ @ProductionComment.property()
49
+ public assignment?: Assignment;
50
+ }
@@ -0,0 +1,98 @@
1
+ import { Merchi } from '../merchi';
2
+
3
+ test('can make Quote', () => {
4
+ const merchi = new Merchi();
5
+ const quote = new merchi.Quote();
6
+ expect(quote).toBeTruthy();
7
+ });
8
+
9
+ test('calculation', () => {
10
+ const merchi = new Merchi();
11
+ const quote = new merchi.Quote();
12
+ const gst = new merchi.CountryTax();
13
+ gst.taxName = 'GST';
14
+ gst.taxPercent = 10;
15
+ const noTax = merchi.CountryTax.getNoTax();
16
+
17
+ // quote items did not filled before calculation seems like a embed issue
18
+ expect(quote.quoteTotal).toThrow();
19
+ expect(quote.calculateSubTotal).toThrow();
20
+ expect(quote.calculateTaxAmount).toThrow();
21
+
22
+ quote.quoteItems = [new merchi.QuoteItem(), new merchi.QuoteItem()];
23
+ quote.quoteItems[0].unitPrice = 400;
24
+ quote.quoteItems[0].quantity = 2;
25
+ quote.quoteItems[0].taxType = gst;
26
+ quote.quoteItems[1].unitPrice = 25;
27
+ quote.quoteItems[1].quantity = 2;
28
+ quote.quoteItems[1].taxType = noTax;
29
+
30
+ // shipments did not filled before calculation seems like a embed issue
31
+ expect(quote.quoteTotal).toThrow();
32
+ expect(quote.calculateSubTotal).toThrow();
33
+ expect(quote.calculateTaxAmount).toThrow();
34
+
35
+ quote.shipments = [new merchi.Shipment()];
36
+ quote.shipments[0].cost = 100;
37
+ quote.shipments[0].taxType = gst;
38
+
39
+ // 800 * 1.1 + 25 * 2 + 100 * 1.1 = 1040
40
+ expect(quote.quoteTotal()).toBe('1040.000');
41
+ expect(quote.quoteTotal({'strictEmbed': false})).toBe('1040.000');
42
+ expect(quote.calculateTotal()).toBe('1040.000');
43
+ expect(quote.calculateTotal({'strictEmbed': false})).toBe('1040.000');
44
+
45
+ // 800 + 25 * 2 + 100
46
+ expect(quote.calculateSubTotal()).toBe('950.000');
47
+ expect(quote.calculateSubTotal({'strictEmbed': false})).toBe('950.000');
48
+
49
+ // 800 * 0.1 + 100 * 0.1
50
+ expect(quote.calculateTaxAmount()).toBe('90.000');
51
+ expect(quote.calculateTaxAmount({'strictEmbed': false})).toBe('90.000');
52
+ });
53
+
54
+ test('findQuoteItemIndex', () => {
55
+ const merchi = new Merchi();
56
+ const quote = new merchi.Quote();
57
+ expect(() => quote.findQuoteItemIndex(43)).toThrow();
58
+ quote.quoteItems = [];
59
+ expect(quote.findQuoteItemIndex(43)).toEqual(-1);
60
+ quote.quoteItems = [new merchi.QuoteItem()];
61
+ quote.quoteItems[0].id = 43;
62
+ expect(quote.findQuoteItemIndex(43)).toEqual(0);
63
+ });
64
+
65
+ test('removeQuoteItem', () => {
66
+ const merchi = new Merchi();
67
+ const quote = new merchi.Quote();
68
+ const quoteItem = new merchi.QuoteItem();
69
+ quoteItem.id = 43;
70
+ expect(() => quote.removeQuoteItem(quoteItem)).toThrow();
71
+ quoteItem.id = undefined;
72
+ expect(() => quote.removeQuoteItem(quoteItem)).toThrow();
73
+ quoteItem.id = 43;
74
+ quote.quoteItems = [];
75
+ expect(quote.removeQuoteItem(quoteItem)).toBe(undefined);
76
+ expect(quote.quoteItems).toEqual([]);
77
+ quote.quoteItems = [quoteItem];
78
+ expect(quote.removeQuoteItem(quoteItem)).toBe(undefined);
79
+ expect(quote.quoteItems).toEqual([]);
80
+ quoteItem.id = undefined;
81
+ expect(() => quote.removeQuoteItem(quoteItem)).toThrow();
82
+ });
83
+
84
+ test('deadlineTimeDifference', () => {
85
+ const merchi = new Merchi();
86
+ const quote = new merchi.Quote();
87
+ expect(quote.deadlineTimeDifference).toThrow();
88
+ quote.agreedDeadline = null;
89
+ expect(quote.deadlineTimeDifference).toThrow();
90
+ quote.assignments = [];
91
+ expect(quote.deadlineTimeDifference()).toBe(null);
92
+ quote.assignments = [new merchi.Assignment()];
93
+ expect(quote.deadlineTimeDifference()).toBe(null);
94
+ quote.agreedDeadline = new Date(1);
95
+ expect(quote.deadlineTimeDifference).toThrow();
96
+ quote.assignments[0].productionDeadline = new Date(2);
97
+ expect(quote.deadlineTimeDifference()).toEqual(1);
98
+ });