merchi_sdk_ts 1.0.7-a → 1.0.7
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.
- package/dist/entities/job.js +36 -25
- package/dist/entities/product.js +22 -16
- package/dist/request.js +3 -5
- package/package.json +1 -1
- package/src/entities/category.test.ts +2 -2
- package/src/entities/job.test.ts +2 -2
- package/src/entities/job.ts +75 -54
- package/src/entities/product.test.ts +15 -15
- package/src/entities/product.ts +75 -55
package/dist/entities/job.js
CHANGED
|
@@ -22,7 +22,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
22
22
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
23
23
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
24
24
|
};
|
|
25
|
+
import { Address } from './address.js';
|
|
26
|
+
import { Assignment } from './assignment.js';
|
|
27
|
+
import { Company } from './company.js';
|
|
28
|
+
import { CountryTax } from './country_tax.js';
|
|
29
|
+
import { Domain } from './domain.js';
|
|
30
|
+
import { EmailAddress } from './email_address.js';
|
|
25
31
|
import { Entity } from '../entity.js';
|
|
32
|
+
import { Invoice } from './invoice.js';
|
|
33
|
+
import { PhoneNumber } from './phone_number.js';
|
|
34
|
+
import { Product } from './product.js';
|
|
35
|
+
import { Shipment } from './shipment.js';
|
|
36
|
+
import { User } from './user.js';
|
|
37
|
+
import { InventoryStatus } from '../constants/inventory_statuses.js';
|
|
26
38
|
var Job = /** @class */ (function (_super) {
|
|
27
39
|
__extends(Job, _super);
|
|
28
40
|
function Job() {
|
|
@@ -34,10 +46,9 @@ var Job = /** @class */ (function (_super) {
|
|
|
34
46
|
fetchOptions.query = [];
|
|
35
47
|
fetchOptions.query.push(['skip_rights', 'y']);
|
|
36
48
|
// insert product id to query for debug purposes
|
|
37
|
-
var product = _this.product;
|
|
38
49
|
fetchOptions.query.push([
|
|
39
50
|
'product_id',
|
|
40
|
-
product.id ? product.id.toString() : 'null'
|
|
51
|
+
_this.product.id ? _this.product.id.toString() : 'null'
|
|
41
52
|
]);
|
|
42
53
|
return _this.merchi.authenticatedFetch(resource, fetchOptions).
|
|
43
54
|
then(function (data) {
|
|
@@ -257,7 +268,7 @@ var Job = /** @class */ (function (_super) {
|
|
|
257
268
|
], Job.prototype, "totalCost", void 0);
|
|
258
269
|
__decorate([
|
|
259
270
|
Job.property({ embeddedByDefault: false }),
|
|
260
|
-
__metadata("design:type",
|
|
271
|
+
__metadata("design:type", Number)
|
|
261
272
|
], Job.prototype, "inventoriesStatus", void 0);
|
|
262
273
|
__decorate([
|
|
263
274
|
Job.property({ embeddedByDefault: false }),
|
|
@@ -312,44 +323,44 @@ var Job = /** @class */ (function (_super) {
|
|
|
312
323
|
__metadata("design:type", Array)
|
|
313
324
|
], Job.prototype, "comments", void 0);
|
|
314
325
|
__decorate([
|
|
315
|
-
Job.property(
|
|
316
|
-
__metadata("design:type",
|
|
326
|
+
Job.property(),
|
|
327
|
+
__metadata("design:type", User)
|
|
317
328
|
], Job.prototype, "client", void 0);
|
|
318
329
|
__decorate([
|
|
319
|
-
Job.property({ type:
|
|
330
|
+
Job.property({ type: User }),
|
|
320
331
|
__metadata("design:type", Object)
|
|
321
332
|
], Job.prototype, "manager", void 0);
|
|
322
333
|
__decorate([
|
|
323
|
-
Job.property({ type:
|
|
334
|
+
Job.property({ type: User }),
|
|
324
335
|
__metadata("design:type", Object)
|
|
325
336
|
], Job.prototype, "designer", void 0);
|
|
326
337
|
__decorate([
|
|
327
|
-
Job.property({ type:
|
|
338
|
+
Job.property({ type: Company }),
|
|
328
339
|
__metadata("design:type", Object)
|
|
329
340
|
], Job.prototype, "clientCompany", void 0);
|
|
330
341
|
__decorate([
|
|
331
|
-
Job.property({ type:
|
|
342
|
+
Job.property({ type: PhoneNumber }),
|
|
332
343
|
__metadata("design:type", Object)
|
|
333
344
|
], Job.prototype, "clientPhone", void 0);
|
|
334
345
|
__decorate([
|
|
335
|
-
Job.property({ type:
|
|
346
|
+
Job.property({ type: EmailAddress }),
|
|
336
347
|
__metadata("design:type", Object)
|
|
337
348
|
], Job.prototype, "clientEmail", void 0);
|
|
338
349
|
__decorate([
|
|
339
|
-
Job.property({ type:
|
|
350
|
+
Job.property({ type: PhoneNumber }),
|
|
340
351
|
__metadata("design:type", Object)
|
|
341
352
|
], Job.prototype, "clientCompanyPhone", void 0);
|
|
342
353
|
__decorate([
|
|
343
|
-
Job.property({ type:
|
|
354
|
+
Job.property({ type: EmailAddress }),
|
|
344
355
|
__metadata("design:type", Object)
|
|
345
356
|
], Job.prototype, "clientCompanyEmail", void 0);
|
|
346
357
|
__decorate([
|
|
347
|
-
Job.property(
|
|
348
|
-
__metadata("design:type",
|
|
358
|
+
Job.property(),
|
|
359
|
+
__metadata("design:type", Product)
|
|
349
360
|
], Job.prototype, "product", void 0);
|
|
350
361
|
__decorate([
|
|
351
|
-
Job.property(
|
|
352
|
-
__metadata("design:type",
|
|
362
|
+
Job.property(),
|
|
363
|
+
__metadata("design:type", Product)
|
|
353
364
|
], Job.prototype, "supplyChainRequestProduct", void 0);
|
|
354
365
|
__decorate([
|
|
355
366
|
Job.property({ arrayType: 'DraftComment' }),
|
|
@@ -360,7 +371,7 @@ var Job = /** @class */ (function (_super) {
|
|
|
360
371
|
__metadata("design:type", Number)
|
|
361
372
|
], Job.prototype, "preDraftCommentsCount", void 0);
|
|
362
373
|
__decorate([
|
|
363
|
-
Job.property({ type:
|
|
374
|
+
Job.property({ type: CountryTax }),
|
|
364
375
|
__metadata("design:type", Object)
|
|
365
376
|
], Job.prototype, "taxType", void 0);
|
|
366
377
|
__decorate([
|
|
@@ -376,19 +387,19 @@ var Job = /** @class */ (function (_super) {
|
|
|
376
387
|
__metadata("design:type", Array)
|
|
377
388
|
], Job.prototype, "createdProducts", void 0);
|
|
378
389
|
__decorate([
|
|
379
|
-
Job.property({ type:
|
|
390
|
+
Job.property({ type: Address }),
|
|
380
391
|
__metadata("design:type", Object)
|
|
381
392
|
], Job.prototype, "shipping", void 0);
|
|
382
393
|
__decorate([
|
|
383
|
-
Job.property({ type:
|
|
394
|
+
Job.property({ type: Address }),
|
|
384
395
|
__metadata("design:type", Object)
|
|
385
396
|
], Job.prototype, "productionShippingAddress", void 0);
|
|
386
397
|
__decorate([
|
|
387
|
-
Job.property(
|
|
388
|
-
__metadata("design:type",
|
|
398
|
+
Job.property(),
|
|
399
|
+
__metadata("design:type", Domain)
|
|
389
400
|
], Job.prototype, "domain", void 0);
|
|
390
401
|
__decorate([
|
|
391
|
-
Job.property({ type:
|
|
402
|
+
Job.property({ type: Invoice }),
|
|
392
403
|
__metadata("design:type", Object)
|
|
393
404
|
], Job.prototype, "invoice", void 0);
|
|
394
405
|
__decorate([
|
|
@@ -400,7 +411,7 @@ var Job = /** @class */ (function (_super) {
|
|
|
400
411
|
__metadata("design:type", Array)
|
|
401
412
|
], Job.prototype, "clientFiles", void 0);
|
|
402
413
|
__decorate([
|
|
403
|
-
Job.property({ type:
|
|
414
|
+
Job.property({ type: Shipment }),
|
|
404
415
|
__metadata("design:type", Object)
|
|
405
416
|
], Job.prototype, "shipment", void 0);
|
|
406
417
|
__decorate([
|
|
@@ -424,8 +435,8 @@ var Job = /** @class */ (function (_super) {
|
|
|
424
435
|
__metadata("design:type", Array)
|
|
425
436
|
], Job.prototype, "assignments", void 0);
|
|
426
437
|
__decorate([
|
|
427
|
-
Job.property(
|
|
428
|
-
__metadata("design:type",
|
|
438
|
+
Job.property(),
|
|
439
|
+
__metadata("design:type", Assignment)
|
|
429
440
|
], Job.prototype, "supplyAssignment", void 0);
|
|
430
441
|
__decorate([
|
|
431
442
|
Job.property(),
|
package/dist/entities/product.js
CHANGED
|
@@ -34,7 +34,13 @@ var __values = (this && this.__values) || function(o) {
|
|
|
34
34
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
35
35
|
};
|
|
36
36
|
import * as _ from 'lodash';
|
|
37
|
+
import { Component } from './component.js';
|
|
38
|
+
import { CountryTax } from './country_tax.js';
|
|
39
|
+
import { Domain } from './domain.js';
|
|
37
40
|
import { Entity } from '../entity.js';
|
|
41
|
+
import { MerchiFile } from './file.js';
|
|
42
|
+
import { Job } from './job.js';
|
|
43
|
+
import { AutoAssignProductionOnAction } from '../constants/auto_assign_production_on_actions.js';
|
|
38
44
|
var Product = /** @class */ (function (_super) {
|
|
39
45
|
__extends(Product, _super);
|
|
40
46
|
function Product() {
|
|
@@ -178,19 +184,19 @@ var Product = /** @class */ (function (_super) {
|
|
|
178
184
|
__metadata("design:type", Number)
|
|
179
185
|
], Product.prototype, "id", void 0);
|
|
180
186
|
__decorate([
|
|
181
|
-
|
|
187
|
+
Component.property({ type: Date }),
|
|
182
188
|
__metadata("design:type", Date)
|
|
183
189
|
], Product.prototype, "created", void 0);
|
|
184
190
|
__decorate([
|
|
185
|
-
|
|
191
|
+
Component.property({ type: Date }),
|
|
186
192
|
__metadata("design:type", Date)
|
|
187
193
|
], Product.prototype, "updated", void 0);
|
|
188
194
|
__decorate([
|
|
189
|
-
|
|
195
|
+
Component.property({ type: 'User' }),
|
|
190
196
|
__metadata("design:type", Object)
|
|
191
197
|
], Product.prototype, "createdBy", void 0);
|
|
192
198
|
__decorate([
|
|
193
|
-
|
|
199
|
+
Component.property({ type: 'User' }),
|
|
194
200
|
__metadata("design:type", Object)
|
|
195
201
|
], Product.prototype, "updatedBy", void 0);
|
|
196
202
|
__decorate([
|
|
@@ -402,23 +408,23 @@ var Product = /** @class */ (function (_super) {
|
|
|
402
408
|
__metadata("design:type", Array)
|
|
403
409
|
], Product.prototype, "discountGroups", void 0);
|
|
404
410
|
__decorate([
|
|
405
|
-
Product.property(
|
|
406
|
-
__metadata("design:type",
|
|
411
|
+
Product.property(),
|
|
412
|
+
__metadata("design:type", Domain)
|
|
407
413
|
], Product.prototype, "domain", void 0);
|
|
408
414
|
__decorate([
|
|
409
|
-
Product.property({ type:
|
|
415
|
+
Product.property({ type: CountryTax }),
|
|
410
416
|
__metadata("design:type", Object)
|
|
411
417
|
], Product.prototype, "taxType", void 0);
|
|
412
418
|
__decorate([
|
|
413
|
-
Product.property({ type:
|
|
419
|
+
Product.property({ type: Product }),
|
|
414
420
|
__metadata("design:type", Object)
|
|
415
421
|
], Product.prototype, "originalProduct", void 0);
|
|
416
422
|
__decorate([
|
|
417
|
-
Product.property({ type:
|
|
423
|
+
Product.property({ type: Product }),
|
|
418
424
|
__metadata("design:type", Object)
|
|
419
425
|
], Product.prototype, "clonedFromProduct", void 0);
|
|
420
426
|
__decorate([
|
|
421
|
-
Product.property({ type:
|
|
427
|
+
Product.property({ type: Product }),
|
|
422
428
|
__metadata("design:type", Object)
|
|
423
429
|
], Product.prototype, "chainedSupplierProduct", void 0);
|
|
424
430
|
__decorate([
|
|
@@ -426,7 +432,7 @@ var Product = /** @class */ (function (_super) {
|
|
|
426
432
|
__metadata("design:type", Array)
|
|
427
433
|
], Product.prototype, "chainedSellerProducts", void 0);
|
|
428
434
|
__decorate([
|
|
429
|
-
Product.property({ type:
|
|
435
|
+
Product.property({ type: Product }),
|
|
430
436
|
__metadata("design:type", Object)
|
|
431
437
|
], Product.prototype, "chainedInventorySupplierProduct", void 0);
|
|
432
438
|
__decorate([
|
|
@@ -434,7 +440,7 @@ var Product = /** @class */ (function (_super) {
|
|
|
434
440
|
__metadata("design:type", Array)
|
|
435
441
|
], Product.prototype, "chainedInventorySellerProducts", void 0);
|
|
436
442
|
__decorate([
|
|
437
|
-
Product.property({ type:
|
|
443
|
+
Product.property({ type: Component }),
|
|
438
444
|
__metadata("design:type", Object)
|
|
439
445
|
], Product.prototype, "component", void 0);
|
|
440
446
|
__decorate([
|
|
@@ -470,7 +476,7 @@ var Product = /** @class */ (function (_super) {
|
|
|
470
476
|
__metadata("design:type", Array)
|
|
471
477
|
], Product.prototype, "seoDomainPages", void 0);
|
|
472
478
|
__decorate([
|
|
473
|
-
Product.property({ type:
|
|
479
|
+
Product.property({ type: MerchiFile }),
|
|
474
480
|
__metadata("design:type", Object)
|
|
475
481
|
], Product.prototype, "featureImage", void 0);
|
|
476
482
|
__decorate([
|
|
@@ -479,7 +485,7 @@ var Product = /** @class */ (function (_super) {
|
|
|
479
485
|
], Product.prototype, "createdByJob", void 0);
|
|
480
486
|
__decorate([
|
|
481
487
|
Product.property({ type: 'Job' }),
|
|
482
|
-
__metadata("design:type",
|
|
488
|
+
__metadata("design:type", Job)
|
|
483
489
|
], Product.prototype, "defaultJob", void 0);
|
|
484
490
|
__decorate([
|
|
485
491
|
Product.property({ arrayType: 'Company', jsonName: 'saved_by_companies' }),
|
|
@@ -490,8 +496,8 @@ var Product = /** @class */ (function (_super) {
|
|
|
490
496
|
__metadata("design:type", Array)
|
|
491
497
|
], Product.prototype, "suppliedByDomains", void 0);
|
|
492
498
|
__decorate([
|
|
493
|
-
Product.property(
|
|
494
|
-
__metadata("design:type",
|
|
499
|
+
Product.property(),
|
|
500
|
+
__metadata("design:type", Number)
|
|
495
501
|
], Product.prototype, "autoAssignProductionOnAction", void 0);
|
|
496
502
|
__decorate([
|
|
497
503
|
Product.property({ arrayType: 'SupplyDomain' }),
|
package/dist/request.js
CHANGED
|
@@ -50,14 +50,12 @@ export function backendFetch(resource, options) {
|
|
|
50
50
|
var _b;
|
|
51
51
|
var defaultBackendUri = 'https://api.merchi.co/';
|
|
52
52
|
// backend uri as defined on the window element takes priority
|
|
53
|
-
var clientBackendUri = typeof window !== 'undefined'
|
|
54
|
-
window.merchiBackendUri ?
|
|
53
|
+
var clientBackendUri = typeof window !== 'undefined' ?
|
|
55
54
|
window.merchiBackendUri : undefined;
|
|
56
55
|
// backend uri as defined on env
|
|
57
|
-
var envBackendUri = typeof process !== 'undefined'
|
|
58
|
-
process.env.MERCHI_BACKEND_URI ?
|
|
56
|
+
var envBackendUri = typeof process !== 'undefined' ?
|
|
59
57
|
process.env.MERCHI_BACKEND_URI : undefined;
|
|
60
|
-
var server = (_b =
|
|
58
|
+
var server = (_b = clientBackendUri !== null && clientBackendUri !== void 0 ? clientBackendUri : envBackendUri) !== null && _b !== void 0 ? _b : defaultBackendUri;
|
|
61
59
|
var url = new URL(server + version + resource);
|
|
62
60
|
if (options && options.query) {
|
|
63
61
|
try {
|
package/package.json
CHANGED
|
@@ -24,8 +24,8 @@ test('can get and set product', () => {
|
|
|
24
24
|
const merchi = new Merchi();
|
|
25
25
|
const c1 = new merchi.Category();
|
|
26
26
|
const c2 = new merchi.Category();
|
|
27
|
-
const p1
|
|
28
|
-
const p2
|
|
27
|
+
const p1 = new merchi.Product();
|
|
28
|
+
const p2 = new merchi.Product();
|
|
29
29
|
const cs = [c1, c2];
|
|
30
30
|
const ps = [p1, p2];
|
|
31
31
|
c1.products = ps;
|
package/src/entities/job.test.ts
CHANGED
|
@@ -35,7 +35,7 @@ test('Job deadline serialised from milliseconds in JSON', () => {
|
|
|
35
35
|
|
|
36
36
|
test('add two files to job', () => {
|
|
37
37
|
const merchi = new Merchi();
|
|
38
|
-
const job
|
|
38
|
+
const job = new merchi.Job();
|
|
39
39
|
const f1 = new merchi.MerchiFile();
|
|
40
40
|
f1.fromFormFile(new File([''], '1'));
|
|
41
41
|
const f2 = new merchi.MerchiFile();
|
|
@@ -70,7 +70,7 @@ test('Get quote update job cost', () => {
|
|
|
70
70
|
|
|
71
71
|
test('test deduct job inventory', () => {
|
|
72
72
|
const merchi = new Merchi();
|
|
73
|
-
const job
|
|
73
|
+
const job = new merchi.Job();
|
|
74
74
|
const inventory = new merchi.Inventory();
|
|
75
75
|
inventory.id = 1;
|
|
76
76
|
job.id = 1;
|
package/src/entities/job.ts
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
|
+
import { Address } from './address.js';
|
|
2
|
+
import { Assignment } from './assignment.js';
|
|
3
|
+
import { Company } from './company.js';
|
|
4
|
+
import { CountryTax } from './country_tax.js';
|
|
5
|
+
import { Domain } from './domain.js';
|
|
6
|
+
import { DomainTag } from './domain_tag.js';
|
|
7
|
+
import { Draft } from './draft.js';
|
|
8
|
+
import { DraftComment } from './draft_comment.js';
|
|
9
|
+
import { EmailAddress } from './email_address.js';
|
|
1
10
|
import { Entity } from '../entity.js';
|
|
11
|
+
import { MerchiFile } from './file.js';
|
|
12
|
+
import { MatchingInventory } from './matching_inventory.js';
|
|
13
|
+
import { InternalTag } from './internal_tag.js';
|
|
14
|
+
import { Invoice } from './invoice.js';
|
|
15
|
+
import { JobComment } from './job_comment.js';
|
|
16
|
+
import { Notification } from './notification.js';
|
|
17
|
+
import { PhoneNumber } from './phone_number.js';
|
|
18
|
+
import { Product } from './product.js';
|
|
2
19
|
import { RequestOptions } from '../request.js';
|
|
20
|
+
import { Shipment } from './shipment.js';
|
|
21
|
+
import { User } from './user.js';
|
|
22
|
+
import { Variation } from './variation.js';
|
|
23
|
+
import { VariationsGroup } from './variations_group.js';
|
|
24
|
+
import { InventoryStatus } from '../constants/inventory_statuses.js';
|
|
3
25
|
|
|
4
26
|
|
|
5
27
|
export class Job extends Entity {
|
|
@@ -143,7 +165,7 @@ export class Job extends Entity {
|
|
|
143
165
|
public totalCost?: number | null;
|
|
144
166
|
|
|
145
167
|
@Job.property({embeddedByDefault: false})
|
|
146
|
-
public inventoriesStatus?:
|
|
168
|
+
public inventoriesStatus?: InventoryStatus;
|
|
147
169
|
|
|
148
170
|
@Job.property({embeddedByDefault: false})
|
|
149
171
|
public unreadNotificationsCount?: number;
|
|
@@ -173,103 +195,103 @@ export class Job extends Entity {
|
|
|
173
195
|
public inventorySufficient?: boolean;
|
|
174
196
|
|
|
175
197
|
@Job.property({arrayType: 'Draft'})
|
|
176
|
-
public drafts?:
|
|
198
|
+
public drafts?: Draft[];
|
|
177
199
|
|
|
178
200
|
@Job.property({arrayType: 'Draft'})
|
|
179
|
-
public sharedDrafts?:
|
|
201
|
+
public sharedDrafts?: Draft[];
|
|
180
202
|
|
|
181
203
|
@Job.property({arrayType: 'Draft'})
|
|
182
|
-
public ownDrafts?:
|
|
204
|
+
public ownDrafts?: Draft[];
|
|
183
205
|
|
|
184
206
|
@Job.property({arrayType: 'JobComment'})
|
|
185
|
-
public comments?:
|
|
207
|
+
public comments?: JobComment[];
|
|
186
208
|
|
|
187
|
-
@Job.property(
|
|
188
|
-
public client?:
|
|
209
|
+
@Job.property()
|
|
210
|
+
public client?: User;
|
|
189
211
|
|
|
190
|
-
@Job.property({type:
|
|
191
|
-
public manager?:
|
|
212
|
+
@Job.property({type: User})
|
|
213
|
+
public manager?: User | null;
|
|
192
214
|
|
|
193
|
-
@Job.property({type:
|
|
194
|
-
public designer?:
|
|
215
|
+
@Job.property({type: User})
|
|
216
|
+
public designer?: User | null;
|
|
195
217
|
|
|
196
|
-
@Job.property({type:
|
|
197
|
-
public clientCompany?:
|
|
218
|
+
@Job.property({type: Company})
|
|
219
|
+
public clientCompany?: Company | null;
|
|
198
220
|
|
|
199
|
-
@Job.property({type:
|
|
200
|
-
public clientPhone?:
|
|
221
|
+
@Job.property({type: PhoneNumber})
|
|
222
|
+
public clientPhone?: PhoneNumber | null;
|
|
201
223
|
|
|
202
|
-
@Job.property({type:
|
|
203
|
-
public clientEmail?:
|
|
224
|
+
@Job.property({type: EmailAddress})
|
|
225
|
+
public clientEmail?: EmailAddress | null;
|
|
204
226
|
|
|
205
|
-
@Job.property({type:
|
|
206
|
-
public clientCompanyPhone?:
|
|
227
|
+
@Job.property({type: PhoneNumber})
|
|
228
|
+
public clientCompanyPhone?: PhoneNumber | null;
|
|
207
229
|
|
|
208
|
-
@Job.property({type:
|
|
209
|
-
public clientCompanyEmail?:
|
|
230
|
+
@Job.property({type: EmailAddress})
|
|
231
|
+
public clientCompanyEmail?: EmailAddress | null;
|
|
210
232
|
|
|
211
|
-
@Job.property(
|
|
212
|
-
public product?:
|
|
233
|
+
@Job.property()
|
|
234
|
+
public product?: Product;
|
|
213
235
|
|
|
214
|
-
@Job.property(
|
|
215
|
-
public supplyChainRequestProduct?:
|
|
236
|
+
@Job.property()
|
|
237
|
+
public supplyChainRequestProduct?: Product;
|
|
216
238
|
|
|
217
239
|
@Job.property({arrayType: 'DraftComment'})
|
|
218
|
-
public draftComments?:
|
|
240
|
+
public draftComments?: DraftComment[];
|
|
219
241
|
|
|
220
242
|
@Job.property()
|
|
221
243
|
public preDraftCommentsCount?: number;
|
|
222
244
|
|
|
223
|
-
@Job.property({type:
|
|
224
|
-
public taxType?:
|
|
245
|
+
@Job.property({type: CountryTax})
|
|
246
|
+
public taxType?: CountryTax | null;
|
|
225
247
|
|
|
226
248
|
@Job.property({arrayType: 'InternalTag'})
|
|
227
|
-
public internalTags?:
|
|
249
|
+
public internalTags?: InternalTag[];
|
|
228
250
|
|
|
229
251
|
@Job.property({arrayType: 'DomainTag'})
|
|
230
|
-
public tags?:
|
|
252
|
+
public tags?: DomainTag[];
|
|
231
253
|
|
|
232
254
|
@Job.property({arrayType: 'Product'})
|
|
233
|
-
public createdProducts?:
|
|
255
|
+
public createdProducts?: Product[];
|
|
234
256
|
|
|
235
|
-
@Job.property({type:
|
|
236
|
-
public shipping?:
|
|
257
|
+
@Job.property({type: Address})
|
|
258
|
+
public shipping?: Address | null;
|
|
237
259
|
|
|
238
|
-
@Job.property({type:
|
|
239
|
-
public productionShippingAddress?:
|
|
260
|
+
@Job.property({type: Address})
|
|
261
|
+
public productionShippingAddress?: Address | null;
|
|
240
262
|
|
|
241
|
-
@Job.property(
|
|
242
|
-
public domain?:
|
|
263
|
+
@Job.property()
|
|
264
|
+
public domain?: Domain;
|
|
243
265
|
|
|
244
|
-
@Job.property({type:
|
|
245
|
-
public invoice?:
|
|
266
|
+
@Job.property({type: Invoice})
|
|
267
|
+
public invoice?: Invoice | null;
|
|
246
268
|
|
|
247
269
|
@Job.property({arrayType: 'MerchiFile'})
|
|
248
|
-
public productionFiles?:
|
|
270
|
+
public productionFiles?: MerchiFile[];
|
|
249
271
|
|
|
250
272
|
@Job.property({arrayType: 'MerchiFile'})
|
|
251
|
-
public clientFiles?:
|
|
273
|
+
public clientFiles?: MerchiFile[];
|
|
252
274
|
|
|
253
|
-
@Job.property({type:
|
|
254
|
-
public shipment?:
|
|
275
|
+
@Job.property({type: Shipment})
|
|
276
|
+
public shipment?: Shipment | null;
|
|
255
277
|
|
|
256
278
|
@Job.property({arrayType: 'MatchingInventory'})
|
|
257
|
-
public matchingInventories?:
|
|
279
|
+
public matchingInventories?: MatchingInventory[];
|
|
258
280
|
|
|
259
281
|
@Job.property({arrayType: 'VariationsGroup'})
|
|
260
|
-
public variationsGroups?:
|
|
282
|
+
public variationsGroups?: VariationsGroup[];
|
|
261
283
|
|
|
262
284
|
@Job.property({arrayType: 'Variation'})
|
|
263
|
-
public variations?:
|
|
285
|
+
public variations?: Variation[];
|
|
264
286
|
|
|
265
287
|
@Job.property({arrayType: 'Notification'})
|
|
266
|
-
public notifications?:
|
|
288
|
+
public notifications?: Notification[];
|
|
267
289
|
|
|
268
290
|
@Job.property({arrayType: 'Assignment'})
|
|
269
|
-
public assignments?:
|
|
291
|
+
public assignments?: Assignment[];
|
|
270
292
|
|
|
271
|
-
@Job.property(
|
|
272
|
-
public supplyAssignment?:
|
|
293
|
+
@Job.property()
|
|
294
|
+
public supplyAssignment?: Assignment;
|
|
273
295
|
|
|
274
296
|
@Job.property()
|
|
275
297
|
public supplyJob?: Job;
|
|
@@ -287,10 +309,9 @@ export class Job extends Entity {
|
|
|
287
309
|
fetchOptions.query = [];
|
|
288
310
|
fetchOptions.query.push(['skip_rights', 'y']);
|
|
289
311
|
// insert product id to query for debug purposes
|
|
290
|
-
const product: any = this.product;
|
|
291
312
|
fetchOptions.query.push([
|
|
292
313
|
'product_id',
|
|
293
|
-
product!.id ? product!.id!.toString() : 'null'
|
|
314
|
+
this.product!.id ? this.product!.id!.toString() : 'null'
|
|
294
315
|
]);
|
|
295
316
|
|
|
296
317
|
return this.merchi.authenticatedFetch(resource, fetchOptions).
|
|
@@ -298,10 +319,10 @@ export class Job extends Entity {
|
|
|
298
319
|
return this;});
|
|
299
320
|
};
|
|
300
321
|
|
|
301
|
-
public deduct = (matchingInventories:
|
|
322
|
+
public deduct = (matchingInventories: MatchingInventory[]) => {
|
|
302
323
|
const resource = `/jobs/${this.id}/deduct/`;
|
|
303
324
|
const inventoriesNeedToBeDeducted = matchingInventories.map(
|
|
304
|
-
matchingInventory =>
|
|
325
|
+
matchingInventory => matchingInventory.inventory!.id);
|
|
305
326
|
const embed = {matchingInventories: {inventory: {}, group: {}}};
|
|
306
327
|
const data = new FormData();
|
|
307
328
|
data.append('inventories', JSON.stringify(inventoriesNeedToBeDeducted));
|
|
@@ -29,7 +29,7 @@ test('can get and set name', () => {
|
|
|
29
29
|
|
|
30
30
|
test('can get and set featureImage', () => {
|
|
31
31
|
const merchi = new Merchi();
|
|
32
|
-
const product
|
|
32
|
+
const product = new merchi.Product();
|
|
33
33
|
const file = new merchi.MerchiFile();
|
|
34
34
|
product.featureImage = file;
|
|
35
35
|
expect(product.featureImage).toBe(file);
|
|
@@ -37,7 +37,7 @@ test('can get and set featureImage', () => {
|
|
|
37
37
|
|
|
38
38
|
test('can get and set domain', () => {
|
|
39
39
|
const merchi = new Merchi();
|
|
40
|
-
const product
|
|
40
|
+
const product = new merchi.Product();
|
|
41
41
|
const domain = new merchi.Domain();
|
|
42
42
|
product.domain = domain;
|
|
43
43
|
expect(product.domain).toBe(domain);
|
|
@@ -448,7 +448,7 @@ test('can list products from server with category', () => {
|
|
|
448
448
|
test('can save product', () => {
|
|
449
449
|
const merchi = new Merchi();
|
|
450
450
|
const c1 = new merchi.Category();
|
|
451
|
-
const p
|
|
451
|
+
const p = new merchi.Product();
|
|
452
452
|
const c2 = new merchi.Category();
|
|
453
453
|
const d = new merchi.Domain();
|
|
454
454
|
p.categories = [c2];
|
|
@@ -474,7 +474,7 @@ test('can save product', () => {
|
|
|
474
474
|
test('can serialise product to form data understood by backend', () => {
|
|
475
475
|
const merchi = new Merchi();
|
|
476
476
|
const c1 = new merchi.Category();
|
|
477
|
-
const p
|
|
477
|
+
const p = new merchi.Product();
|
|
478
478
|
const c2 = new merchi.Category();
|
|
479
479
|
const d = new merchi.Domain();
|
|
480
480
|
p.categories = [c2];
|
|
@@ -502,7 +502,7 @@ test('undefined data will not be serialised', () => {
|
|
|
502
502
|
|
|
503
503
|
test('can convert product data json format', () => {
|
|
504
504
|
const merchi = new Merchi();
|
|
505
|
-
const p
|
|
505
|
+
const p = new merchi.Product();
|
|
506
506
|
const d = new merchi.Domain();
|
|
507
507
|
const c1 = new merchi.Category();
|
|
508
508
|
c1.name = 'category 1';
|
|
@@ -522,7 +522,7 @@ test('can convert product data json format', () => {
|
|
|
522
522
|
|
|
523
523
|
test('can clean dirty on purpose', () => {
|
|
524
524
|
const merchi = new Merchi();
|
|
525
|
-
const p
|
|
525
|
+
const p = new merchi.Product();
|
|
526
526
|
const d = new merchi.Domain();
|
|
527
527
|
const c1 = new merchi.Category();
|
|
528
528
|
c1.name = 'category 1';
|
|
@@ -567,7 +567,7 @@ test('use from json to merge json into entity', () => {
|
|
|
567
567
|
categories: [{name: 'c1'}, {name: 'c2'}]
|
|
568
568
|
};
|
|
569
569
|
const merchi = new Merchi();
|
|
570
|
-
const p
|
|
570
|
+
const p = new merchi.Product();
|
|
571
571
|
p.fromJson(json);
|
|
572
572
|
|
|
573
573
|
const updatedJson = {
|
|
@@ -614,7 +614,7 @@ test('primary key always serialised', () => {
|
|
|
614
614
|
|
|
615
615
|
test('orderable attribute request', () => {
|
|
616
616
|
const merchi = new Merchi();
|
|
617
|
-
const product
|
|
617
|
+
const product = new merchi.Product();
|
|
618
618
|
const f = new merchi.MerchiFile();
|
|
619
619
|
f.id = 24;
|
|
620
620
|
product.id = 42;
|
|
@@ -640,7 +640,7 @@ test('duplicate', () => {
|
|
|
640
640
|
|
|
641
641
|
test('primaryImage', () => {
|
|
642
642
|
const merchi = new Merchi();
|
|
643
|
-
const product
|
|
643
|
+
const product = new merchi.Product();
|
|
644
644
|
const i1 = new merchi.MerchiFile();
|
|
645
645
|
const i2 = new merchi.MerchiFile();
|
|
646
646
|
expect(product.primaryImage).toThrow();
|
|
@@ -656,7 +656,7 @@ test('primaryImage', () => {
|
|
|
656
656
|
|
|
657
657
|
test('hasGroupVariationFields', () => {
|
|
658
658
|
const merchi = new Merchi();
|
|
659
|
-
const product
|
|
659
|
+
const product = new merchi.Product();
|
|
660
660
|
expect(product.hasGroupVariationFields).toThrow();
|
|
661
661
|
product.groupVariationFields = [];
|
|
662
662
|
expect(product.hasGroupVariationFields()).toBe(false);
|
|
@@ -666,7 +666,7 @@ test('hasGroupVariationFields', () => {
|
|
|
666
666
|
|
|
667
667
|
test('hasIndependentVariationFields', () => {
|
|
668
668
|
const merchi = new Merchi();
|
|
669
|
-
const product
|
|
669
|
+
const product = new merchi.Product();
|
|
670
670
|
expect(product.hasIndependentVariationFields).toThrow();
|
|
671
671
|
product.independentVariationFields = [];
|
|
672
672
|
expect(product.hasIndependentVariationFields()).toBe(false);
|
|
@@ -676,7 +676,7 @@ test('hasIndependentVariationFields', () => {
|
|
|
676
676
|
|
|
677
677
|
test('allVariationFields', () => {
|
|
678
678
|
const merchi = new Merchi();
|
|
679
|
-
const product
|
|
679
|
+
const product = new merchi.Product();
|
|
680
680
|
const vf1 = new merchi.VariationField();
|
|
681
681
|
const vf2 = new merchi.VariationField();
|
|
682
682
|
expect(product.allVariationFields).toThrow();
|
|
@@ -688,7 +688,7 @@ test('allVariationFields', () => {
|
|
|
688
688
|
|
|
689
689
|
test('removeVariationField', () => {
|
|
690
690
|
const merchi = new Merchi();
|
|
691
|
-
const product
|
|
691
|
+
const product = new merchi.Product();
|
|
692
692
|
const vf = new merchi.VariationField();
|
|
693
693
|
expect(() => product.removeVariationField(vf)).toThrow();
|
|
694
694
|
vf.independent = false;
|
|
@@ -708,7 +708,7 @@ test('removeVariationField', () => {
|
|
|
708
708
|
|
|
709
709
|
test('buildEmptyVariations', () => {
|
|
710
710
|
const merchi = new Merchi();
|
|
711
|
-
const product
|
|
711
|
+
const product = new merchi.Product();
|
|
712
712
|
expect(product.buildEmptyVariations).toThrow();
|
|
713
713
|
product.independentVariationFields = [];
|
|
714
714
|
expect(product.buildEmptyVariations()).toEqual([]);
|
|
@@ -722,7 +722,7 @@ test('buildEmptyVariations', () => {
|
|
|
722
722
|
|
|
723
723
|
test('buildEmptyVariationGroup', () => {
|
|
724
724
|
const merchi = new Merchi();
|
|
725
|
-
const product
|
|
725
|
+
const product = new merchi.Product();
|
|
726
726
|
expect(product.buildEmptyVariationGroup).toThrow();
|
|
727
727
|
product.groupVariationFields = [new merchi.VariationField()];
|
|
728
728
|
product.groupVariationFields[0].defaultValue = '';
|
package/src/entities/product.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import * as _ from 'lodash';
|
|
2
|
+
import { CartItem } from './cart_item.js';
|
|
3
|
+
import { Category } from './category.js';
|
|
4
|
+
import { Company } from './company.js';
|
|
5
|
+
import { Component } from './component.js';
|
|
6
|
+
import { CountryTax } from './country_tax.js';
|
|
7
|
+
import { DiscountGroup } from './discount_group.js';
|
|
8
|
+
import { Domain } from './domain.js';
|
|
9
|
+
import { DomainTag } from './domain_tag.js';
|
|
10
|
+
import { DraftTemplate } from './draft_template.js';
|
|
2
11
|
import { Entity } from '../entity.js';
|
|
12
|
+
import { MerchiFile } from './file.js';
|
|
13
|
+
import { InternalTag } from './internal_tag.js';
|
|
14
|
+
import { Inventory } from './inventory.js';
|
|
15
|
+
import { SupplyDomain } from './supply_domain.js';
|
|
16
|
+
import { User } from './user.js';
|
|
17
|
+
import { VariationField } from './variation_field.js';
|
|
18
|
+
import { SeoDomainPage } from './seo_domain_page.js';
|
|
19
|
+
import { ShipmentMethod } from './shipment_method.js';
|
|
20
|
+
import {
|
|
21
|
+
AutoAssignProductionOnAction
|
|
22
|
+
} from '../constants/auto_assign_production_on_actions.js';
|
|
3
23
|
|
|
4
24
|
export class Product extends Entity {
|
|
5
25
|
protected static resourceName = 'products';
|
|
@@ -12,17 +32,17 @@ export class Product extends Entity {
|
|
|
12
32
|
@Product.property()
|
|
13
33
|
public id?: number;
|
|
14
34
|
|
|
15
|
-
@
|
|
35
|
+
@Component.property({type: Date})
|
|
16
36
|
public created?: Date;
|
|
17
37
|
|
|
18
|
-
@
|
|
38
|
+
@Component.property({type: Date})
|
|
19
39
|
public updated?: Date;
|
|
20
40
|
|
|
21
|
-
@
|
|
22
|
-
public createdBy?:
|
|
41
|
+
@Component.property({type: 'User'})
|
|
42
|
+
public createdBy?: User | null;
|
|
23
43
|
|
|
24
|
-
@
|
|
25
|
-
public updatedBy?:
|
|
44
|
+
@Component.property({type: 'User'})
|
|
45
|
+
public updatedBy?: User | null;
|
|
26
46
|
|
|
27
47
|
@Product.property()
|
|
28
48
|
public productType?: number;
|
|
@@ -43,10 +63,10 @@ export class Product extends Entity {
|
|
|
43
63
|
public buyUnitPrice?: number;
|
|
44
64
|
|
|
45
65
|
@Product.property({type: 'DiscountGroup'})
|
|
46
|
-
public unitPriceDiscountGroup?:
|
|
66
|
+
public unitPriceDiscountGroup?: DiscountGroup | null;
|
|
47
67
|
|
|
48
68
|
@Product.property({arrayType: 'ShipmentMethod'})
|
|
49
|
-
public shipmentMethods?:
|
|
69
|
+
public shipmentMethods?: ShipmentMethod[];
|
|
50
70
|
|
|
51
71
|
@Product.property()
|
|
52
72
|
public margin?: number;
|
|
@@ -172,67 +192,67 @@ export class Product extends Entity {
|
|
|
172
192
|
public unitVolume?: number;
|
|
173
193
|
|
|
174
194
|
@Product.property({arrayType: 'Category'})
|
|
175
|
-
public categories?:
|
|
195
|
+
public categories?: Category[];
|
|
176
196
|
|
|
177
197
|
@Product.property({arrayType: 'Category'})
|
|
178
|
-
public platformCategories?:
|
|
198
|
+
public platformCategories?: Category[];
|
|
179
199
|
|
|
180
200
|
@Product.property({arrayType: 'DiscountGroup'})
|
|
181
|
-
public discountGroups?:
|
|
201
|
+
public discountGroups?: DiscountGroup[];
|
|
182
202
|
|
|
183
|
-
@Product.property(
|
|
184
|
-
public domain?:
|
|
203
|
+
@Product.property()
|
|
204
|
+
public domain?: Domain;
|
|
185
205
|
|
|
186
|
-
@Product.property({type:
|
|
187
|
-
public taxType?:
|
|
206
|
+
@Product.property({type: CountryTax})
|
|
207
|
+
public taxType?: CountryTax | null;
|
|
188
208
|
|
|
189
|
-
@Product.property({type:
|
|
190
|
-
public originalProduct?:
|
|
209
|
+
@Product.property({type: Product})
|
|
210
|
+
public originalProduct?: Product | null;
|
|
191
211
|
|
|
192
|
-
@Product.property({type:
|
|
193
|
-
public clonedFromProduct?:
|
|
212
|
+
@Product.property({type: Product})
|
|
213
|
+
public clonedFromProduct?: Product | null;
|
|
194
214
|
|
|
195
|
-
@Product.property({type:
|
|
196
|
-
public chainedSupplierProduct?:
|
|
215
|
+
@Product.property({type: Product})
|
|
216
|
+
public chainedSupplierProduct?: Product | null;
|
|
197
217
|
|
|
198
218
|
@Product.property({arrayType: 'Product'})
|
|
199
|
-
public chainedSellerProducts?:
|
|
219
|
+
public chainedSellerProducts?: Product[];
|
|
200
220
|
|
|
201
|
-
@Product.property({type:
|
|
202
|
-
public chainedInventorySupplierProduct?:
|
|
221
|
+
@Product.property({type: Product})
|
|
222
|
+
public chainedInventorySupplierProduct?: Product | null;
|
|
203
223
|
|
|
204
224
|
@Product.property({arrayType: 'Product'})
|
|
205
|
-
public chainedInventorySellerProducts?:
|
|
225
|
+
public chainedInventorySellerProducts?: Product[];
|
|
206
226
|
|
|
207
|
-
@Product.property({type:
|
|
208
|
-
public component?:
|
|
227
|
+
@Product.property({type: Component})
|
|
228
|
+
public component?: Component | null;
|
|
209
229
|
|
|
210
230
|
@Product.property({arrayType: 'MerchiFile'})
|
|
211
|
-
public images?:
|
|
231
|
+
public images?: MerchiFile[];
|
|
212
232
|
|
|
213
233
|
@Product.property({arrayType: 'MerchiFile'})
|
|
214
|
-
public publicFiles?:
|
|
234
|
+
public publicFiles?: MerchiFile[];
|
|
215
235
|
|
|
216
236
|
@Product.property({arrayType: 'MerchiFile'})
|
|
217
|
-
public productionFiles?:
|
|
237
|
+
public productionFiles?: MerchiFile[];
|
|
218
238
|
|
|
219
239
|
@Product.property({arrayType: 'VariationField'})
|
|
220
|
-
public groupVariationFields?:
|
|
240
|
+
public groupVariationFields?: VariationField[];
|
|
221
241
|
|
|
222
242
|
@Product.property({arrayType: 'VariationField'})
|
|
223
|
-
public independentVariationFields?:
|
|
243
|
+
public independentVariationFields?: VariationField[];
|
|
224
244
|
|
|
225
245
|
@Product.property({arrayType: 'DomainTag'})
|
|
226
|
-
public tags?:
|
|
246
|
+
public tags?: DomainTag[];
|
|
227
247
|
|
|
228
248
|
@Product.property({arrayType: 'InternalTag'})
|
|
229
|
-
public internalTags?:
|
|
249
|
+
public internalTags?: InternalTag[];
|
|
230
250
|
|
|
231
251
|
@Product.property({arrayType: 'SeoDomainPage'})
|
|
232
|
-
public seoDomainPages?:
|
|
252
|
+
public seoDomainPages?: SeoDomainPage[];
|
|
233
253
|
|
|
234
|
-
@Product.property({type:
|
|
235
|
-
public featureImage?:
|
|
254
|
+
@Product.property({type: MerchiFile})
|
|
255
|
+
public featureImage?: MerchiFile | null;
|
|
236
256
|
|
|
237
257
|
@Product.property({type: 'Job'})
|
|
238
258
|
public createdByJob?: 'Job' | null;
|
|
@@ -241,16 +261,16 @@ export class Product extends Entity {
|
|
|
241
261
|
public defaultJob?: 'Job';
|
|
242
262
|
|
|
243
263
|
@Product.property({arrayType: 'Company', jsonName: 'saved_by_companies'})
|
|
244
|
-
public savedByCompanies?:
|
|
264
|
+
public savedByCompanies?: Company[];
|
|
245
265
|
|
|
246
266
|
@Product.property({arrayType: 'SupplyDomain'})
|
|
247
|
-
public suppliedByDomains?:
|
|
267
|
+
public suppliedByDomains?: SupplyDomain[];
|
|
248
268
|
|
|
249
|
-
@Product.property(
|
|
250
|
-
public autoAssignProductionOnAction?:
|
|
269
|
+
@Product.property()
|
|
270
|
+
public autoAssignProductionOnAction?: AutoAssignProductionOnAction;
|
|
251
271
|
|
|
252
272
|
@Product.property({arrayType: 'SupplyDomain'})
|
|
253
|
-
public supplyDomains?:
|
|
273
|
+
public supplyDomains?: SupplyDomain[];
|
|
254
274
|
|
|
255
275
|
@Product.property()
|
|
256
276
|
public inventoriesOpen?: boolean;
|
|
@@ -259,10 +279,10 @@ export class Product extends Entity {
|
|
|
259
279
|
public supplyChainDisabled?: boolean;
|
|
260
280
|
|
|
261
281
|
@Product.property({arrayType: 'Inventory'})
|
|
262
|
-
public inventories?:
|
|
282
|
+
public inventories?: Inventory[];
|
|
263
283
|
|
|
264
284
|
@Product.property({arrayType: 'CartItem'})
|
|
265
|
-
public cartItems?:
|
|
285
|
+
public cartItems?: CartItem[];
|
|
266
286
|
|
|
267
287
|
@Product.property({arrayType: 'Job'})
|
|
268
288
|
public jobs?: 'Job'[];
|
|
@@ -271,13 +291,13 @@ export class Product extends Entity {
|
|
|
271
291
|
public supplyChainRequestJobs?: 'Job'[];
|
|
272
292
|
|
|
273
293
|
@Product.property({arrayType: 'User', jsonName: 'saved_by_users'})
|
|
274
|
-
public savedByUsers?:
|
|
294
|
+
public savedByUsers?: User[];
|
|
275
295
|
|
|
276
296
|
@Product.property({arrayType: 'User'})
|
|
277
|
-
public suppliers?:
|
|
297
|
+
public suppliers?: User[];
|
|
278
298
|
|
|
279
299
|
@Product.property({arrayType: 'DraftTemplate'})
|
|
280
|
-
public draftTemplates?:
|
|
300
|
+
public draftTemplates?: DraftTemplate[];
|
|
281
301
|
|
|
282
302
|
public duplicate = () => {
|
|
283
303
|
/* create a clone of this product on the backend, returning it. */
|
|
@@ -339,9 +359,9 @@ export class Product extends Entity {
|
|
|
339
359
|
' embed it?';
|
|
340
360
|
throw new Error(err);
|
|
341
361
|
}
|
|
342
|
-
const result:
|
|
343
|
-
return result.concat(
|
|
344
|
-
|
|
362
|
+
const result: VariationField[] = [];
|
|
363
|
+
return result.concat(this.groupVariationFields,
|
|
364
|
+
this.independentVariationFields);
|
|
345
365
|
};
|
|
346
366
|
|
|
347
367
|
public buildEmptyVariations = () => {
|
|
@@ -350,8 +370,8 @@ export class Product extends Entity {
|
|
|
350
370
|
' embed it?';
|
|
351
371
|
throw new Error(err);
|
|
352
372
|
}
|
|
353
|
-
const iVF:
|
|
354
|
-
_.orderBy(
|
|
373
|
+
const iVF: VariationField[] =
|
|
374
|
+
_.orderBy(this.independentVariationFields, ['position'], ['asc']);
|
|
355
375
|
return iVF.map(field => field.buildEmptyVariation());
|
|
356
376
|
};
|
|
357
377
|
|
|
@@ -368,7 +388,7 @@ export class Product extends Entity {
|
|
|
368
388
|
this.groupVariationFields, ['position'], ['asc']);
|
|
369
389
|
result.quantity = 0;
|
|
370
390
|
for (const variationField of sortedFields) {
|
|
371
|
-
const empty =
|
|
391
|
+
const empty = variationField.buildEmptyVariation();
|
|
372
392
|
variations.push(empty);
|
|
373
393
|
cost += empty.cost as number;
|
|
374
394
|
}
|
|
@@ -377,7 +397,7 @@ export class Product extends Entity {
|
|
|
377
397
|
return result;
|
|
378
398
|
};
|
|
379
399
|
|
|
380
|
-
public removeVariationField = (variationField:
|
|
400
|
+
public removeVariationField = (variationField: VariationField) => {
|
|
381
401
|
if (variationField.independent === undefined) {
|
|
382
402
|
throw new Error('variation.independent is undefined, did you ' +
|
|
383
403
|
'forget to embed it?');
|
|
@@ -392,7 +412,7 @@ export class Product extends Entity {
|
|
|
392
412
|
' it?';
|
|
393
413
|
throw new Error(err);
|
|
394
414
|
}
|
|
395
|
-
const variationFields
|
|
415
|
+
const variationFields = variationField.independent ?
|
|
396
416
|
this.independentVariationFields : this.groupVariationFields;
|
|
397
417
|
const index = variationFields.findIndex(v => {
|
|
398
418
|
if (v.id === undefined) {
|