|
1
|
import { |
|
2
|
CartDTO, |
|
3
|
CartTypes, |
|
4
|
Context, |
|
5
|
DAL, |
|
6
|
FindConfig, |
|
7
|
ICartModuleService, |
|
8
|
InferEntityType, |
|
9
|
InternalModuleDeclaration, |
|
10
|
ModulesSdkTypes, |
|
11
|
} from "@medusajs/framework/types" |
|
12
|
import { |
|
13
|
createRawPropertiesFromBigNumber, |
|
14
|
decorateCartTotals, |
|
15
|
deduplicate, |
|
16
|
EmitEvents, |
|
17
|
generateEntityId, |
|
18
|
InjectManager, |
|
19
|
InjectTransactionManager, |
|
20
|
isObject, |
|
21
|
isString, |
|
22
|
MedusaContext, |
|
23
|
MedusaError, |
|
24
|
ModulesSdkUtils, |
|
25
|
promiseAll, |
|
26
|
normalizeCurrencyCode, |
|
27
|
} from "@medusajs/framework/utils" |
|
28
|
import { |
|
29
|
Address, |
|
30
|
Cart, |
|
31
|
CreditLine, |
|
32
|
LineItem, |
|
33
|
LineItemAdjustment, |
|
34
|
LineItemTaxLine, |
|
35
|
ShippingMethod, |
|
36
|
ShippingMethodAdjustment, |
|
37
|
ShippingMethodTaxLine, |
|
38
|
} from "@models" |
|
39
|
import { |
|
40
|
CreateLineItemDTO, |
|
41
|
CreateShippingMethodDTO, |
|
42
|
UpdateLineItemDTO, |
|
43
|
UpdateShippingMethodTaxLineDTO, |
|
44
|
} from "@types" |
|
45
|
|
|
46
|
type InjectedDependencies = { |
|
47
|
baseRepository: DAL.RepositoryService |
|
48
|
cartService: ModulesSdkTypes.IMedusaInternalService<any> |
|
49
|
addressService: ModulesSdkTypes.IMedusaInternalService<any> |
|
50
|
lineItemService: ModulesSdkTypes.IMedusaInternalService<any> |
|
51
|
shippingMethodAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any> |
|
52
|
shippingMethodService: ModulesSdkTypes.IMedusaInternalService<any> |
|
53
|
lineItemAdjustmentService: ModulesSdkTypes.IMedusaInternalService<any> |
|
54
|
lineItemTaxLineService: ModulesSdkTypes.IMedusaInternalService<any> |
|
55
|
shippingMethodTaxLineService: ModulesSdkTypes.IMedusaInternalService<any> |
|
56
|
} |
|
57
|
|
|
58
|
const generateMethodForModels = { |
|
59
|
Cart, |
|
60
|
CreditLine, |
|
61
|
Address, |
|
62
|
LineItem, |
|
63
|
LineItemAdjustment, |
|
64
|
LineItemTaxLine, |
|
65
|
ShippingMethod, |
|
66
|
ShippingMethodAdjustment, |
|
67
|
ShippingMethodTaxLine, |
|
68
|
} |
|
69
|
|
|
70
|
export default class CartModuleService |
|
71
|
extends ModulesSdkUtils.MedusaService<{ |
|
72
|
Cart: { dto: CartTypes.CartDTO } |
|
73
|
CreditLine: { dto: CartTypes.CartCreditLineDTO } |
|
74
|
Address: { dto: CartTypes.CartAddressDTO } |
|
75
|
LineItem: { dto: CartTypes.CartLineItemDTO } |
|
76
|
LineItemAdjustment: { dto: CartTypes.LineItemAdjustmentDTO } |
|
77
|
LineItemTaxLine: { dto: CartTypes.LineItemTaxLineDTO } |
|
78
|
ShippingMethod: { dto: CartTypes.CartShippingMethodDTO } |
|
79
|
ShippingMethodAdjustment: { dto: CartTypes.ShippingMethodAdjustmentDTO } |
|
80
|
ShippingMethodTaxLine: { dto: CartTypes.ShippingMethodTaxLineDTO } |
|
81
|
}>(generateMethodForModels) |
|
82
|
implements ICartModuleService |
|
83
|
{ |
|
84
|
protected baseRepository_: DAL.RepositoryService |
|
85
|
protected cartService_: ModulesSdkTypes.IMedusaInternalService< |
|
86
|
InferEntityType<typeof Cart> |
|
87
|
> |
|
88
|
protected addressService_: ModulesSdkTypes.IMedusaInternalService< |
|
89
|
InferEntityType<typeof Address> |
|
90
|
> |
|
91
|
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService< |
|
92
|
InferEntityType<typeof LineItem> |
|
93
|
> |
|
94
|
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService< |
|
95
|
InferEntityType<typeof ShippingMethodAdjustment> |
|
96
|
> |
|
97
|
protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService< |
|
98
|
InferEntityType<typeof ShippingMethod> |
|
99
|
> |
|
100
|
protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService< |
|
101
|
InferEntityType<typeof LineItemAdjustment> |
|
102
|
> |
|
103
|
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService< |
|
104
|
InferEntityType<typeof LineItemTaxLine> |
|
105
|
> |
|
106
|
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService< |
|
107
|
InferEntityType<typeof ShippingMethodTaxLine> |
|
108
|
> |
|
109
|
|
|
110
|
constructor( |
|
111
|
{ |
|
112
|
baseRepository, |
|
113
|
cartService, |
|
114
|
addressService, |
|
115
|
lineItemService, |
|
116
|
shippingMethodAdjustmentService, |
|
117
|
shippingMethodService, |
|
118
|
lineItemAdjustmentService, |
|
119
|
shippingMethodTaxLineService, |
|
120
|
lineItemTaxLineService, |
|
121
|
}: InjectedDependencies, |
|
122
|
protected readonly moduleDeclaration: InternalModuleDeclaration |
|
123
|
) { |
|
124
|
// @ts-ignore |
|
125
|
super(...arguments) |
|
126
|
|
|
127
|
this.baseRepository_ = baseRepository |
|
128
|
this.cartService_ = cartService |
|
129
|
this.addressService_ = addressService |
|
130
|
this.lineItemService_ = lineItemService |
|
131
|
this.shippingMethodAdjustmentService_ = shippingMethodAdjustmentService |
|
132
|
this.shippingMethodService_ = shippingMethodService |
|
133
|
this.lineItemAdjustmentService_ = lineItemAdjustmentService |
|
134
|
this.shippingMethodTaxLineService_ = shippingMethodTaxLineService |
|
135
|
this.lineItemTaxLineService_ = lineItemTaxLineService |
|
136
|
} |
|
137
|
|
|
138
|
private shouldIncludeTotals(config: FindConfig<any>): boolean { |
|
139
|
const totalFields = [ |
|
140
|
"*", |
|
141
|
"total", |
|
142
|
"subtotal", |
|
143
|
"tax_total", |
|
144
|
"discount_total", |
|
145
|
"discount_tax_total", |
|
146
|
"original_total", |
|
147
|
"original_tax_total", |
|
148
|
"item_total", |
|
149
|
"item_subtotal", |
|
150
|
"item_tax_total", |
|
151
|
"original_item_total", |
|
152
|
"original_item_subtotal", |
|
153
|
"original_item_tax_total", |
|
154
|
"shipping_total", |
|
155
|
"shipping_subtotal", |
|
156
|
"shipping_tax_total", |
|
157
|
"original_shipping_tax_total", |
|
158
|
"original_shipping_subtotal", |
|
159
|
"original_shipping_total", |
|
160
|
] |
|
161
|
|
|
162
|
const includeTotals = (config?.select ?? ["*"]).some((field) => |
|
163
|
totalFields.includes(field as string) |
|
164
|
) |
|
165
|
|
|
166
|
if (includeTotals) { |
|
167
|
this.addRelationsToCalculateTotals(config, totalFields) |
|
168
|
} |
|
169
|
|
|
170
|
return includeTotals |
|
171
|
} |
|
172
|
|
|
173
|
private addRelationsToCalculateTotals(config: FindConfig<any>, totalFields) { |
|
174
|
config.relations ??= [] |
|
175
|
|
|
176
|
const requiredFieldsForTotals = [ |
|
177
|
"items", |
|
178
|
"credit_lines", |
|
179
|
"items.tax_lines", |
|
180
|
"items.adjustments", |
|
181
|
"shipping_methods", |
|
182
|
"shipping_methods.tax_lines", |
|
183
|
"shipping_methods.adjustments", |
|
184
|
] |
|
185
|
config.relations = deduplicate([ |
|
186
|
...config.relations, |
|
187
|
...requiredFieldsForTotals, |
|
188
|
]) |
|
189
|
|
|
190
|
config.select = config.select?.filter((field) => { |
|
191
|
return ( |
|
192
|
!requiredFieldsForTotals.some((val) => |
|
193
|
(field as string).startsWith(val) |
|
194
|
) && !totalFields.includes(field) |
|
195
|
) |
|
196
|
}) |
|
197
|
} |
|
198
|
|
|
199
|
// @ts-expect-error |
|
200
|
async retrieveCart( |
|
201
|
id: string, |
|
202
|
config?: FindConfig<any> | undefined, |
|
203
|
sharedContext?: Context | undefined |
|
204
|
): Promise<CartDTO> { |
|
205
|
config ??= {} |
|
206
|
const includeTotals = this.shouldIncludeTotals(config) |
|
207
|
|
|
208
|
const cart = await super.retrieveCart(id, config, sharedContext) |
|
209
|
|
|
210
|
if (includeTotals) { |
|
211
|
createRawPropertiesFromBigNumber(decorateCartTotals(cart)) |
|
212
|
} |
|
213
|
|
|
214
|
return cart |
|
215
|
} |
|
216
|
|
|
217
|
// @ts-expect-error |
|
218
|
async listCarts( |
|
219
|
filters?: any, |
|
220
|
config?: FindConfig<any> | undefined, |
|
221
|
sharedContext?: Context | undefined |
|
222
|
): Promise<CartDTO[]> { |
|
223
|
config ??= {} |
|
224
|
const includeTotals = this.shouldIncludeTotals(config) |
|
225
|
|
|
226
|
const carts = await super.listCarts(filters, config, sharedContext) |
|
227
|
|
|
228
|
if (includeTotals) { |
|
229
|
carts.forEach((cart) => { |
|
230
|
createRawPropertiesFromBigNumber(decorateCartTotals(cart)) |
|
231
|
}) |
|
232
|
} |
|
233
|
|
|
234
|
return carts |
|
235
|
} |
|
236
|
|
|
237
|
// @ts-expect-error |
|
238
|
async listAndCountCarts( |
|
239
|
filters?: any, |
|
240
|
config?: FindConfig<any> | undefined, |
|
241
|
sharedContext?: Context | undefined |
|
242
|
): Promise<[CartDTO[], number]> { |
|
243
|
config ??= {} |
|
244
|
const includeTotals = this.shouldIncludeTotals(config) |
|
245
|
|
|
246
|
const [carts, count] = await super.listAndCountCarts( |
|
247
|
filters, |
|
248
|
config, |
|
249
|
sharedContext |
|
250
|
) |
|
251
|
|
|
252
|
if (includeTotals) { |
|
253
|
carts.forEach((cart) => { |
|
254
|
createRawPropertiesFromBigNumber(decorateCartTotals(cart)) |
|
255
|
}) |
|
256
|
} |
|
257
|
|
|
258
|
return [carts, count] |
|
259
|
} |
|
260
|
|
|
261
|
// @ts-expect-error |
|
262
|
async createCarts( |
|
263
|
data: CartTypes.CreateCartDTO[], |
|
264
|
sharedContext?: Context |
|
265
|
): Promise<CartTypes.CartDTO[]> |
|
266
|
|
|
267
|
// @ts-expect-error |
|
268
|
async createCarts( |
|
269
|
data: CartTypes.CreateCartDTO, |
|
270
|
sharedContext?: Context |
|
271
|
): Promise<CartTypes.CartDTO> |
|
272
|
|
|
273
|
@InjectManager() |
|
274
|
@EmitEvents() |
|
275
|
// @ts-expect-error |
|
276
|
async createCarts( |
|
277
|
data: CartTypes.CreateCartDTO[] | CartTypes.CreateCartDTO, |
|
278
|
@MedusaContext() sharedContext: Context = {} |
|
279
|
): Promise<CartTypes.CartDTO[] | CartTypes.CartDTO> { |
|
280
|
const input = Array.isArray(data) ? data : [data] |
|
281
|
|
|
282
|
const carts = await this.createCarts_(input, sharedContext) |
|
283
|
|
|
284
|
const result = await this.baseRepository_.serialize<CartTypes.CartDTO[]>( |
|
285
|
carts |
|
286
|
) |
|
287
|
|
|
288
|
return (Array.isArray(data) ? result : result[0]) as |
|
289
|
| CartTypes.CartDTO |
|
290
|
| CartTypes.CartDTO[] |
|
291
|
} |
|
292
|
|
|
293
|
@InjectTransactionManager() |
|
294
|
protected async createCarts_( |
|
295
|
data: CartTypes.CreateCartDTO[], |
|
296
|
@MedusaContext() sharedContext: Context = {} |
|
297
|
): Promise<InferEntityType<typeof Cart>[]> { |
|
298
|
const cartsWithItems = data.map(({ items, ...cart }) => { |
|
299
|
const cartId = generateEntityId((cart as any).id, "cart") |
|
300
|
return { |
|
301
|
cart: { |
|
302
|
...cart, |
|
303
|
currency_code: cart.currency_code |
|
304
|
? normalizeCurrencyCode(cart.currency_code) |
|
305
|
: cart.currency_code, |
|
306
|
id: cartId, |
|
307
|
}, |
|
308
|
items: items || [], |
|
309
|
} |
|
310
|
}) |
|
311
|
|
|
312
|
// Batch create all carts a once instead of sequentially |
|
313
|
const createdCarts = await this.cartService_.create( |
|
314
|
cartsWithItems.map((c) => c.cart), |
|
315
|
sharedContext |
|
316
|
) |
|
317
|
|
|
318
|
const lineItemsToCreate: CreateLineItemDTO[] = [] |
|
319
|
for (const { cart, items } of cartsWithItems) { |
|
320
|
if (items.length) { |
|
321
|
lineItemsToCreate.push( |
|
322
|
...items.map((item) => ({ |
|
323
|
...item, |
|
324
|
cart_id: cart.id, |
|
325
|
})) |
|
326
|
) |
|
327
|
} |
|
328
|
} |
|
329
|
|
|
330
|
if (lineItemsToCreate.length) { |
|
331
|
await this.addLineItemsBulk_(lineItemsToCreate, sharedContext) |
|
332
|
} |
|
333
|
|
|
334
|
const fullCarts = await this.cartService_.list( |
|
335
|
{ id: createdCarts.map((c) => c.id) }, |
|
336
|
{ |
|
337
|
relations: ["shipping_address", "billing_address"], |
|
338
|
}, |
|
339
|
sharedContext |
|
340
|
) |
|
341
|
|
|
342
|
// Return in the same input order |
|
343
|
const orderedInputId = cartsWithItems.map((c) => c.cart.id) |
|
344
|
return orderedInputId.map((id) => |
|
345
|
fullCarts.find((c) => c.id === id) |
|
346
|
) as InferEntityType<typeof Cart>[] |
|
347
|
} |
|
348
|
|
|
349
|
// @ts-expect-error |
|
350
|
async updateCarts( |
|
351
|
data: CartTypes.UpdateCartDTO[] |
|
352
|
): Promise<CartTypes.CartDTO[]> |
|
353
|
// @ts-expect-error |
|
354
|
async updateCarts( |
|
355
|
cartId: string, |
|
356
|
data: CartTypes.UpdateCartDataDTO, |
|
357
|
sharedContext?: Context |
|
358
|
): Promise<CartTypes.CartDTO> |
|
359
|
// @ts-expect-error |
|
360
|
async updateCarts( |
|
361
|
selector: Partial<CartTypes.CartDTO>, |
|
362
|
data: CartTypes.UpdateCartDataDTO, |
|
363
|
sharedContext?: Context |
|
364
|
): Promise<CartTypes.CartDTO[]> |
|
365
|
|
|
366
|
@InjectManager() |
|
367
|
@EmitEvents() |
|
368
|
// @ts-expect-error |
|
369
|
async updateCarts( |
|
370
|
dataOrIdOrSelector: |
|
371
|
| CartTypes.UpdateCartDTO[] |
|
372
|
| string |
|
373
|
| Partial<CartTypes.CartDTO>, |
|
374
|
data?: CartTypes.UpdateCartDataDTO, |
|
375
|
@MedusaContext() sharedContext: Context = {} |
|
376
|
): Promise<CartTypes.CartDTO[] | CartTypes.CartDTO> { |
|
377
|
const result = await this.updateCarts_( |
|
378
|
dataOrIdOrSelector, |
|
379
|
data, |
|
380
|
sharedContext |
|
381
|
) |
|
382
|
|
|
383
|
const serializedResult = await this.baseRepository_.serialize< |
|
384
|
CartTypes.CartDTO[] |
|
385
|
>(result) |
|
386
|
|
|
387
|
return isString(dataOrIdOrSelector) ? serializedResult[0] : serializedResult |
|
388
|
} |
|
389
|
|
|
390
|
@InjectTransactionManager() |
|
391
|
protected async updateCarts_( |
|
392
|
dataOrIdOrSelector: |
|
393
|
| CartTypes.UpdateCartDTO[] |
|
394
|
| string |
|
395
|
| Partial<CartTypes.CartDTO>, |
|
396
|
data?: CartTypes.UpdateCartDataDTO, |
|
397
|
@MedusaContext() sharedContext: Context = {} |
|
398
|
) { |
|
399
|
let toUpdate: CartTypes.UpdateCartDTO[] = [] |
|
400
|
if (isString(dataOrIdOrSelector)) { |
|
401
|
toUpdate = [ |
|
402
|
{ |
|
403
|
id: dataOrIdOrSelector, |
|
404
|
...data, |
|
405
|
...(data?.currency_code |
|
406
|
? { currency_code: normalizeCurrencyCode(data.currency_code) } |
|
407
|
: {}), |
|
408
|
}, |
|
409
|
] |
|
410
|
} else if (Array.isArray(dataOrIdOrSelector)) { |
|
411
|
toUpdate = dataOrIdOrSelector.map((d) => ({ |
|
412
|
...d, |
|
413
|
...(d.currency_code |
|
414
|
? { currency_code: normalizeCurrencyCode(d.currency_code) } |
|
415
|
: {}), |
|
416
|
})) |
|
417
|
} else { |
|
418
|
const carts = await this.cartService_.list( |
|
419
|
{ ...dataOrIdOrSelector }, |
|
420
|
{ select: ["id"] }, |
|
421
|
sharedContext |
|
422
|
) |
|
423
|
|
|
424
|
toUpdate = carts.map((cart) => { |
|
425
|
return { |
|
426
|
...data, |
|
427
|
id: cart.id, |
|
428
|
...(data?.currency_code |
|
429
|
? { currency_code: normalizeCurrencyCode(data.currency_code) } |
|
430
|
: {}), |
|
431
|
} |
|
432
|
}) |
|
433
|
} |
|
434
|
|
|
435
|
const result = await this.cartService_.update(toUpdate, sharedContext) |
|
436
|
return result |
|
437
|
} |
|
438
|
|
|
439
|
@InjectManager() |
|
440
|
// @ts-expect-error |
|
441
|
async updateShippingMethods( |
|
442
|
data: CartTypes.UpdateShippingMethodDTO[], |
|
443
|
sharedContext?: Context |
|
444
|
): Promise<CartTypes.CartShippingMethodDTO[]> { |
|
445
|
return super.updateShippingMethods( |
|
446
|
data as unknown as CartTypes.CartShippingMethodDTO[], |
|
447
|
sharedContext |
|
448
|
) as unknown as Promise<CartTypes.CartShippingMethodDTO[]> |
|
449
|
} |
|
450
|
|
|
451
|
addLineItems( |
|
452
|
data: CartTypes.CreateLineItemForCartDTO |
|
453
|
): Promise<CartTypes.CartLineItemDTO[]> |
|
454
|
addLineItems( |
|
455
|
data: CartTypes.CreateLineItemForCartDTO[] |
|
456
|
): Promise<CartTypes.CartLineItemDTO[]> |
|
457
|
addLineItems( |
|
458
|
cartId: string, |
|
459
|
items: CartTypes.CreateLineItemDTO[], |
|
460
|
sharedContext?: Context |
|
461
|
): Promise<CartTypes.CartLineItemDTO[]> |
|
462
|
|
|
463
|
@InjectManager() |
|
464
|
@EmitEvents() |
|
465
|
async addLineItems( |
|
466
|
cartIdOrData: |
|
467
|
| string |
|
468
|
| CartTypes.CreateLineItemForCartDTO[] |
|
469
|
| CartTypes.CreateLineItemForCartDTO, |
|
470
|
data?: CartTypes.CreateLineItemDTO[] | CartTypes.CreateLineItemDTO, |
|
471
|
@MedusaContext() sharedContext: Context = {} |
|
472
|
): Promise<CartTypes.CartLineItemDTO[]> { |
|
473
|
let items: InferEntityType<typeof LineItem>[] = [] |
|
474
|
if (isString(cartIdOrData)) { |
|
475
|
items = await this.addLineItems_( |
|
476
|
cartIdOrData, |
|
477
|
data as CartTypes.CreateLineItemDTO[], |
|
478
|
sharedContext |
|
479
|
) |
|
480
|
} else { |
|
481
|
const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData] |
|
482
|
items = await this.addLineItemsBulk_(data, sharedContext) |
|
483
|
} |
|
484
|
|
|
485
|
return await this.baseRepository_.serialize<CartTypes.CartLineItemDTO[]>( |
|
486
|
items |
|
487
|
) |
|
488
|
} |
|
489
|
|
|
490
|
@InjectTransactionManager() |
|
491
|
protected async addLineItems_( |
|
492
|
cartId: string, |
|
493
|
items: CartTypes.CreateLineItemDTO[], |
|
494
|
@MedusaContext() sharedContext: Context = {} |
|
495
|
): Promise<InferEntityType<typeof LineItem>[]> { |
|
496
|
const cart = await this.cartService_.retrieve( |
|
497
|
cartId, |
|
498
|
{ select: ["id"] }, |
|
499
|
sharedContext |
|
500
|
) |
|
501
|
|
|
502
|
const toUpdate: CreateLineItemDTO[] = items.map((item) => { |
|
503
|
return { |
|
504
|
...item, |
|
505
|
cart_id: cart.id, |
|
506
|
} |
|
507
|
}) |
|
508
|
|
|
509
|
return await this.addLineItemsBulk_(toUpdate, sharedContext) |
|
510
|
} |
|
511
|
|
|
512
|
@InjectTransactionManager() |
|
513
|
protected async addLineItemsBulk_( |
|
514
|
data: CreateLineItemDTO[], |
|
515
|
@MedusaContext() sharedContext: Context = {} |
|
516
|
): Promise<InferEntityType<typeof LineItem>[]> { |
|
517
|
return await this.lineItemService_.create(data, sharedContext) |
|
518
|
} |
|
519
|
|
|
520
|
// @ts-ignore |
|
521
|
updateLineItems( |
|
522
|
data: CartTypes.UpdateLineItemWithSelectorDTO[] |
|
523
|
): Promise<CartTypes.CartLineItemDTO[]> |
|
524
|
|
|
525
|
// @ts-ignore |
|
526
|
updateLineItems( |
|
527
|
data: (Partial<CartTypes.UpdateLineItemDTO> & { id: string })[] |
|
528
|
): Promise<CartTypes.CartLineItemDTO[]> |
|
529
|
|
|
530
|
// @ts-expect-error |
|
531
|
updateLineItems( |
|
532
|
selector: Partial<CartTypes.CartLineItemDTO>, |
|
533
|
data: CartTypes.UpdateLineItemDTO, |
|
534
|
sharedContext?: Context |
|
535
|
): Promise<CartTypes.CartLineItemDTO[]> |
|
536
|
// @ts-expect-error |
|
537
|
updateLineItems( |
|
538
|
lineItemId: string, |
|
539
|
data: Partial<CartTypes.UpdateLineItemDTO>, |
|
540
|
sharedContext?: Context |
|
541
|
): Promise<CartTypes.CartLineItemDTO> |
|
542
|
|
|
543
|
@InjectManager() |
|
544
|
@EmitEvents() |
|
545
|
// @ts-expect-error |
|
546
|
async updateLineItems( |
|
547
|
lineItemIdOrDataOrSelector: |
|
548
|
| string |
|
549
|
| CartTypes.UpdateLineItemWithSelectorDTO[] |
|
550
|
| Partial<CartTypes.CartLineItemDTO> |
|
551
|
| (Partial<CartTypes.UpdateLineItemDTO> & { id: string })[], |
|
552
|
data?: CartTypes.UpdateLineItemDTO | Partial<CartTypes.UpdateLineItemDTO>, |
|
553
|
@MedusaContext() sharedContext: Context = {} |
|
554
|
): Promise<CartTypes.CartLineItemDTO[] | CartTypes.CartLineItemDTO> { |
|
555
|
let items: InferEntityType<typeof LineItem>[] = [] |
|
556
|
if (isString(lineItemIdOrDataOrSelector)) { |
|
557
|
const item = await this.updateLineItem_( |
|
558
|
lineItemIdOrDataOrSelector, |
|
559
|
data as Partial<CartTypes.UpdateLineItemDTO>, |
|
560
|
sharedContext |
|
561
|
) |
|
562
|
|
|
563
|
return await this.baseRepository_.serialize<CartTypes.CartLineItemDTO>( |
|
564
|
item |
|
565
|
) |
|
566
|
} else if (Array.isArray(lineItemIdOrDataOrSelector) && !data) { |
|
567
|
// We received an array of data including the ids |
|
568
|
const items = await this.lineItemService_.update( |
|
569
|
lineItemIdOrDataOrSelector, |
|
570
|
sharedContext |
|
571
|
) |
|
572
|
|
|
573
|
return await this.baseRepository_.serialize<CartTypes.CartLineItemDTO[]>( |
|
574
|
items |
|
575
|
) |
|
576
|
} |
|
577
|
|
|
578
|
const toUpdate = Array.isArray(lineItemIdOrDataOrSelector) |
|
579
|
? lineItemIdOrDataOrSelector |
|
580
|
: [ |
|
581
|
{ |
|
582
|
selector: lineItemIdOrDataOrSelector, |
|
583
|
data: data, |
|
584
|
} as CartTypes.UpdateLineItemWithSelectorDTO, |
|
585
|
] |
|
586
|
|
|
587
|
items = await this.updateLineItemsWithSelector_( |
|
588
|
toUpdate as CartTypes.UpdateLineItemWithSelectorDTO[], |
|
589
|
sharedContext |
|
590
|
) |
|
591
|
|
|
592
|
return await this.baseRepository_.serialize<CartTypes.CartLineItemDTO[]>( |
|
593
|
items |
|
594
|
) |
|
595
|
} |
|
596
|
|
|
597
|
@InjectTransactionManager() |
|
598
|
protected async updateLineItem_( |
|
599
|
lineItemId: string, |
|
600
|
data: Partial<CartTypes.UpdateLineItemDTO>, |
|
601
|
@MedusaContext() sharedContext: Context = {} |
|
602
|
): Promise<InferEntityType<typeof LineItem>> { |
|
603
|
const [item] = await this.lineItemService_.update( |
|
604
|
[{ id: lineItemId, ...data }], |
|
605
|
sharedContext |
|
606
|
) |
|
607
|
|
|
608
|
return item |
|
609
|
} |
|
610
|
|
|
611
|
@InjectTransactionManager() |
|
612
|
protected async updateLineItemsWithSelector_( |
|
613
|
updates: CartTypes.UpdateLineItemWithSelectorDTO[], |
|
614
|
@MedusaContext() sharedContext: Context = {} |
|
615
|
): Promise<InferEntityType<typeof LineItem>[]> { |
|
616
|
let toUpdate: UpdateLineItemDTO[] = [] |
|
617
|
for (const { selector, data } of updates) { |
|
618
|
const items = await this.lineItemService_.list( |
|
619
|
{ ...selector }, |
|
620
|
{}, |
|
621
|
sharedContext |
|
622
|
) |
|
623
|
|
|
624
|
items.forEach((item) => { |
|
625
|
toUpdate.push({ |
|
626
|
...data, |
|
627
|
id: item.id, |
|
628
|
}) |
|
629
|
}) |
|
630
|
} |
|
631
|
|
|
632
|
return await this.lineItemService_.update(toUpdate, sharedContext) |
|
633
|
} |
|
634
|
|
|
635
|
// @ts-ignore |
|
636
|
async createAddresses( |
|
637
|
data: CartTypes.CreateAddressDTO, |
|
638
|
sharedContext?: Context |
|
639
|
): Promise<CartTypes.CartAddressDTO> |
|
640
|
// @ts-expect-error |
|
641
|
async createAddresses( |
|
642
|
data: CartTypes.CreateAddressDTO[], |
|
643
|
sharedContext?: Context |
|
644
|
): Promise<CartTypes.CartAddressDTO[]> |
|
645
|
|
|
646
|
@InjectManager() |
|
647
|
@EmitEvents() |
|
648
|
// @ts-expect-error |
|
649
|
async createAddresses( |
|
650
|
data: CartTypes.CreateAddressDTO[] | CartTypes.CreateAddressDTO, |
|
651
|
@MedusaContext() sharedContext: Context = {} |
|
652
|
): Promise<CartTypes.CartAddressDTO | CartTypes.CartAddressDTO[]> { |
|
653
|
const input = Array.isArray(data) ? data : [data] |
|
654
|
const addresses = await this.createAddresses_(input, sharedContext) |
|
655
|
|
|
656
|
const result = await this.listAddresses( |
|
657
|
{ id: addresses.map((p) => p.id) }, |
|
658
|
{}, |
|
659
|
sharedContext |
|
660
|
) |
|
661
|
|
|
662
|
return (Array.isArray(data) ? result : result[0]) as |
|
663
|
| CartTypes.CartAddressDTO |
|
664
|
| CartTypes.CartAddressDTO[] |
|
665
|
} |
|
666
|
|
|
667
|
@InjectTransactionManager() |
|
668
|
protected async createAddresses_( |
|
669
|
data: CartTypes.CreateAddressDTO[], |
|
670
|
@MedusaContext() sharedContext: Context = {} |
|
671
|
) { |
|
672
|
return await this.addressService_.create(data, sharedContext) |
|
673
|
} |
|
674
|
|
|
675
|
// @ts-ignore |
|
676
|
async updateAddresses( |
|
677
|
data: CartTypes.UpdateAddressDTO, |
|
678
|
sharedContext?: Context |
|
679
|
): Promise<CartTypes.CartAddressDTO> |
|
680
|
// @ts-expect-error |
|
681
|
async updateAddresses( |
|
682
|
data: CartTypes.UpdateAddressDTO[], |
|
683
|
sharedContext?: Context |
|
684
|
): Promise<CartTypes.CartAddressDTO[]> |
|
685
|
|
|
686
|
@InjectManager() |
|
687
|
@EmitEvents() |
|
688
|
// @ts-expect-error |
|
689
|
async updateAddresses( |
|
690
|
data: CartTypes.UpdateAddressDTO[] | CartTypes.UpdateAddressDTO, |
|
691
|
@MedusaContext() sharedContext: Context = {} |
|
692
|
): Promise<CartTypes.CartAddressDTO | CartTypes.CartAddressDTO[]> { |
|
693
|
const input = Array.isArray(data) ? data : [data] |
|
694
|
const addresses = await this.updateAddresses_(input, sharedContext) |
|
695
|
|
|
696
|
const result = await this.listAddresses( |
|
697
|
{ id: addresses.map((p) => p.id) }, |
|
698
|
{}, |
|
699
|
sharedContext |
|
700
|
) |
|
701
|
|
|
702
|
return (Array.isArray(data) ? result : result[0]) as |
|
703
|
| CartTypes.CartAddressDTO |
|
704
|
| CartTypes.CartAddressDTO[] |
|
705
|
} |
|
706
|
|
|
707
|
@InjectTransactionManager() |
|
708
|
protected async updateAddresses_( |
|
709
|
data: CartTypes.UpdateAddressDTO[], |
|
710
|
@MedusaContext() sharedContext: Context = {} |
|
711
|
) { |
|
712
|
return await this.addressService_.update(data, sharedContext) |
|
713
|
} |
|
714
|
|
|
715
|
async addShippingMethods( |
|
716
|
data: CartTypes.CreateShippingMethodDTO |
|
717
|
): Promise<CartTypes.CartShippingMethodDTO> |
|
718
|
async addShippingMethods( |
|
719
|
data: CartTypes.CreateShippingMethodDTO[] |
|
720
|
): Promise<CartTypes.CartShippingMethodDTO[]> |
|
721
|
async addShippingMethods( |
|
722
|
cartId: string, |
|
723
|
methods: CartTypes.CreateShippingMethodForSingleCartDTO[], |
|
724
|
sharedContext?: Context |
|
725
|
): Promise<CartTypes.CartShippingMethodDTO[]> |
|
726
|
|
|
727
|
@InjectManager() |
|
728
|
@EmitEvents() |
|
729
|
async addShippingMethods( |
|
730
|
cartIdOrData: |
|
731
|
| string |
|
732
|
| CartTypes.CreateShippingMethodDTO[] |
|
733
|
| CartTypes.CreateShippingMethodDTO, |
|
734
|
data?: |
|
735
|
| CartTypes.CreateShippingMethodDTO[] |
|
736
|
| CartTypes.CreateShippingMethodForSingleCartDTO[], |
|
737
|
@MedusaContext() sharedContext: Context = {} |
|
738
|
): Promise< |
|
739
|
CartTypes.CartShippingMethodDTO[] | CartTypes.CartShippingMethodDTO |
|
740
|
> { |
|
741
|
let methods: InferEntityType<typeof ShippingMethod>[] |
|
742
|
if (isString(cartIdOrData)) { |
|
743
|
methods = await this.addShippingMethods_( |
|
744
|
cartIdOrData, |
|
745
|
data as CartTypes.CreateShippingMethodForSingleCartDTO[], |
|
746
|
sharedContext |
|
747
|
) |
|
748
|
} else { |
|
749
|
const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData] |
|
750
|
methods = await this.addShippingMethodsBulk_( |
|
751
|
data as CartTypes.CreateShippingMethodDTO[], |
|
752
|
sharedContext |
|
753
|
) |
|
754
|
} |
|
755
|
|
|
756
|
return await this.baseRepository_.serialize< |
|
757
|
CartTypes.CartShippingMethodDTO[] |
|
758
|
>(methods) |
|
759
|
} |
|
760
|
|
|
761
|
@InjectTransactionManager() |
|
762
|
protected async addShippingMethods_( |
|
763
|
cartId: string, |
|
764
|
data: CartTypes.CreateShippingMethodForSingleCartDTO[], |
|
765
|
@MedusaContext() sharedContext: Context = {} |
|
766
|
): Promise<InferEntityType<typeof ShippingMethod>[]> { |
|
767
|
const cart = await this.cartService_.retrieve( |
|
768
|
cartId, |
|
769
|
{ select: ["id"] }, |
|
770
|
sharedContext |
|
771
|
) |
|
772
|
|
|
773
|
const methods = data.map((method) => { |
|
774
|
return { |
|
775
|
...method, |
|
776
|
cart_id: cart.id, |
|
777
|
} |
|
778
|
}) |
|
779
|
|
|
780
|
return await this.addShippingMethodsBulk_(methods, sharedContext) |
|
781
|
} |
|
782
|
|
|
783
|
@InjectTransactionManager() |
|
784
|
protected async addShippingMethodsBulk_( |
|
785
|
data: CartTypes.CreateShippingMethodDTO[], |
|
786
|
@MedusaContext() sharedContext: Context = {} |
|
787
|
): Promise<InferEntityType<typeof ShippingMethod>[]> { |
|
788
|
return await this.shippingMethodService_.create( |
|
789
|
data as unknown as CreateShippingMethodDTO[], |
|
790
|
sharedContext |
|
791
|
) |
|
792
|
} |
|
793
|
|
|
794
|
async addLineItemAdjustments( |
|
795
|
adjustments: CartTypes.CreateLineItemAdjustmentDTO[] |
|
796
|
): Promise<CartTypes.LineItemAdjustmentDTO[]> |
|
797
|
async addLineItemAdjustments( |
|
798
|
adjustment: CartTypes.CreateLineItemAdjustmentDTO |
|
799
|
): Promise<CartTypes.LineItemAdjustmentDTO[]> |
|
800
|
async addLineItemAdjustments( |
|
801
|
cartId: string, |
|
802
|
adjustments: CartTypes.CreateLineItemAdjustmentDTO[], |
|
803
|
sharedContext?: Context |
|
804
|
): Promise<CartTypes.LineItemAdjustmentDTO[]> |
|
805
|
|
|
806
|
@InjectManager() |
|
807
|
@EmitEvents() |
|
808
|
async addLineItemAdjustments( |
|
809
|
cartIdOrData: |
|
810
|
| string |
|
811
|
| CartTypes.CreateLineItemAdjustmentDTO[] |
|
812
|
| CartTypes.CreateLineItemAdjustmentDTO, |
|
813
|
adjustments?: CartTypes.CreateLineItemAdjustmentDTO[], |
|
814
|
@MedusaContext() sharedContext: Context = {} |
|
815
|
): Promise<CartTypes.LineItemAdjustmentDTO[]> { |
|
816
|
const result = await this.addLineItemAdjustments_( |
|
817
|
cartIdOrData, |
|
818
|
adjustments, |
|
819
|
sharedContext |
|
820
|
) |
|
821
|
|
|
822
|
return await this.baseRepository_.serialize< |
|
823
|
CartTypes.LineItemAdjustmentDTO[] |
|
824
|
>(result) |
|
825
|
} |
|
826
|
|
|
827
|
@InjectTransactionManager() |
|
828
|
protected async addLineItemAdjustments_( |
|
829
|
cartIdOrData: |
|
830
|
| string |
|
831
|
| CartTypes.CreateLineItemAdjustmentDTO[] |
|
832
|
| CartTypes.CreateLineItemAdjustmentDTO, |
|
833
|
adjustments?: CartTypes.CreateLineItemAdjustmentDTO[], |
|
834
|
@MedusaContext() sharedContext: Context = {} |
|
835
|
): Promise<InferEntityType<typeof LineItemAdjustment>[]> { |
|
836
|
let addedAdjustments: InferEntityType<typeof LineItemAdjustment>[] = [] |
|
837
|
if (isString(cartIdOrData)) { |
|
838
|
const cart = await this.cartService_.retrieve( |
|
839
|
cartIdOrData, |
|
840
|
{ select: ["id"], relations: ["items"] }, |
|
841
|
sharedContext |
|
842
|
) |
|
843
|
|
|
844
|
const lineIds = cart.items?.map((item) => item.id) |
|
845
|
|
|
846
|
for (const adj of adjustments || []) { |
|
847
|
if (!lineIds?.includes(adj.item_id)) { |
|
848
|
throw new MedusaError( |
|
849
|
MedusaError.Types.INVALID_DATA, |
|
850
|
`Line item with id ${adj.item_id} does not exist on cart with id ${cartIdOrData}` |
|
851
|
) |
|
852
|
} |
|
853
|
} |
|
854
|
|
|
855
|
addedAdjustments = await this.lineItemAdjustmentService_.create( |
|
856
|
adjustments as CartTypes.CreateLineItemAdjustmentDTO[], |
|
857
|
sharedContext |
|
858
|
) |
|
859
|
} else { |
|
860
|
const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData] |
|
861
|
|
|
862
|
addedAdjustments = await this.lineItemAdjustmentService_.create( |
|
863
|
data as CartTypes.CreateLineItemAdjustmentDTO[], |
|
864
|
sharedContext |
|
865
|
) |
|
866
|
} |
|
867
|
|
|
868
|
return addedAdjustments |
|
869
|
} |
|
870
|
|
|
871
|
@InjectManager() |
|
872
|
@EmitEvents() |
|
873
|
async upsertLineItemTaxLines( |
|
874
|
taxLines: ( |
|
875
|
| CartTypes.CreateLineItemTaxLineDTO |
|
876
|
| CartTypes.UpdateLineItemTaxLineDTO |
|
877
|
)[], |
|
878
|
@MedusaContext() sharedContext: Context = {} |
|
879
|
): Promise<CartTypes.LineItemTaxLineDTO[]> { |
|
880
|
const result = await this.lineItemTaxLineService_.upsert( |
|
881
|
taxLines as CartTypes.UpdateLineItemTaxLineDTO[], |
|
882
|
sharedContext |
|
883
|
) |
|
884
|
|
|
885
|
return await this.baseRepository_.serialize<CartTypes.LineItemTaxLineDTO[]>( |
|
886
|
result |
|
887
|
) |
|
888
|
} |
|
889
|
|
|
890
|
@InjectTransactionManager() |
|
891
|
protected async upsertLineItemTaxLines_( |
|
892
|
taxLines: ( |
|
893
|
| CartTypes.CreateLineItemTaxLineDTO |
|
894
|
| CartTypes.UpdateLineItemTaxLineDTO |
|
895
|
)[], |
|
896
|
@MedusaContext() sharedContext: Context = {} |
|
897
|
): Promise<InferEntityType<typeof LineItemTaxLine>[]> { |
|
898
|
const result = await this.lineItemTaxLineService_.upsert( |
|
899
|
taxLines as CartTypes.UpdateLineItemTaxLineDTO[], |
|
900
|
sharedContext |
|
901
|
) |
|
902
|
|
|
903
|
return result |
|
904
|
} |
|
905
|
|
|
906
|
@InjectManager() |
|
907
|
@EmitEvents() |
|
908
|
async upsertLineItemAdjustments( |
|
909
|
adjustments: ( |
|
910
|
| CartTypes.CreateLineItemAdjustmentDTO |
|
911
|
| CartTypes.UpdateLineItemAdjustmentDTO |
|
912
|
)[], |
|
913
|
@MedusaContext() sharedContext: Context = {} |
|
914
|
): Promise<CartTypes.LineItemAdjustmentDTO[]> { |
|
915
|
const result = await this.upsertLineItemAdjustments_( |
|
916
|
adjustments, |
|
917
|
sharedContext |
|
918
|
) |
|
919
|
|
|
920
|
return await this.baseRepository_.serialize< |
|
921
|
CartTypes.LineItemAdjustmentDTO[] |
|
922
|
>(result) |
|
923
|
} |
|
924
|
|
|
925
|
@InjectTransactionManager() |
|
926
|
protected async upsertLineItemAdjustments_( |
|
927
|
adjustments: ( |
|
928
|
| CartTypes.CreateLineItemAdjustmentDTO |
|
929
|
| CartTypes.UpdateLineItemAdjustmentDTO |
|
930
|
)[], |
|
931
|
@MedusaContext() sharedContext: Context = {} |
|
932
|
): Promise<InferEntityType<typeof LineItemAdjustment>[]> { |
|
933
|
let result = await this.lineItemAdjustmentService_.upsert( |
|
934
|
adjustments, |
|
935
|
sharedContext |
|
936
|
) |
|
937
|
|
|
938
|
return result |
|
939
|
} |
|
940
|
|
|
941
|
@InjectManager() |
|
942
|
@EmitEvents() |
|
943
|
async upsertShippingMethodTaxLines( |
|
944
|
taxLines: ( |
|
945
|
| CartTypes.CreateShippingMethodTaxLineDTO |
|
946
|
| CartTypes.UpdateShippingMethodTaxLineDTO |
|
947
|
)[], |
|
948
|
@MedusaContext() sharedContext: Context = {} |
|
949
|
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> { |
|
950
|
const result = await this.upsertShippingMethodTaxLines_( |
|
951
|
taxLines, |
|
952
|
sharedContext |
|
953
|
) |
|
954
|
|
|
955
|
return await this.baseRepository_.serialize< |
|
956
|
CartTypes.ShippingMethodTaxLineDTO[] |
|
957
|
>(result) |
|
958
|
} |
|
959
|
|
|
960
|
@InjectTransactionManager() |
|
961
|
protected async upsertShippingMethodTaxLines_( |
|
962
|
taxLines: ( |
|
963
|
| CartTypes.CreateShippingMethodTaxLineDTO |
|
964
|
| CartTypes.UpdateShippingMethodTaxLineDTO |
|
965
|
)[], |
|
966
|
@MedusaContext() sharedContext: Context = {} |
|
967
|
): Promise<InferEntityType<typeof ShippingMethodTaxLine>[]> { |
|
968
|
const result = await this.shippingMethodTaxLineService_.upsert( |
|
969
|
taxLines as UpdateShippingMethodTaxLineDTO[], |
|
970
|
sharedContext |
|
971
|
) |
|
972
|
|
|
973
|
return result |
|
974
|
} |
|
975
|
|
|
976
|
@InjectManager() |
|
977
|
@EmitEvents() |
|
978
|
async upsertShippingMethodAdjustments( |
|
979
|
adjustments: ( |
|
980
|
| CartTypes.CreateShippingMethodAdjustmentDTO |
|
981
|
| CartTypes.UpdateShippingMethodAdjustmentDTO |
|
982
|
)[], |
|
983
|
@MedusaContext() sharedContext: Context = {} |
|
984
|
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> { |
|
985
|
const result = await this.upsertShippingMethodAdjustments_( |
|
986
|
adjustments, |
|
987
|
sharedContext |
|
988
|
) |
|
989
|
|
|
990
|
return await this.baseRepository_.serialize< |
|
991
|
CartTypes.ShippingMethodAdjustmentDTO[] |
|
992
|
>(result) |
|
993
|
} |
|
994
|
|
|
995
|
@InjectTransactionManager() |
|
996
|
protected async upsertShippingMethodAdjustments_( |
|
997
|
adjustments: ( |
|
998
|
| CartTypes.CreateShippingMethodAdjustmentDTO |
|
999
|
| CartTypes.UpdateShippingMethodAdjustmentDTO |
|
1000
|
)[], |
|
1001
|
@MedusaContext() sharedContext: Context = {} |
|
1002
|
): Promise<InferEntityType<typeof ShippingMethodAdjustment>[]> { |
|
1003
|
const result = await this.shippingMethodAdjustmentService_.upsert( |
|
1004
|
adjustments, |
|
1005
|
sharedContext |
|
1006
|
) |
|
1007
|
|
|
1008
|
return result |
|
1009
|
} |
|
1010
|
|
|
1011
|
@InjectManager() |
|
1012
|
@EmitEvents() |
|
1013
|
async setLineItemAdjustments( |
|
1014
|
cartId: string, |
|
1015
|
adjustments: ( |
|
1016
|
| CartTypes.CreateLineItemAdjustmentDTO |
|
1017
|
| CartTypes.UpdateLineItemAdjustmentDTO |
|
1018
|
)[], |
|
1019
|
@MedusaContext() sharedContext: Context = {} |
|
1020
|
): Promise<CartTypes.LineItemAdjustmentDTO[]> { |
|
1021
|
const result = await this.setLineItemAdjustments_( |
|
1022
|
cartId, |
|
1023
|
adjustments, |
|
1024
|
sharedContext |
|
1025
|
) |
|
1026
|
|
|
1027
|
return await this.baseRepository_.serialize< |
|
1028
|
CartTypes.LineItemAdjustmentDTO[] |
|
1029
|
>(result) |
|
1030
|
} |
|
1031
|
|
|
1032
|
@InjectTransactionManager() |
|
1033
|
protected async setLineItemAdjustments_( |
|
1034
|
cartId: string, |
|
1035
|
adjustments: ( |
|
1036
|
| CartTypes.CreateLineItemAdjustmentDTO |
|
1037
|
| CartTypes.UpdateLineItemAdjustmentDTO |
|
1038
|
)[], |
|
1039
|
@MedusaContext() sharedContext: Context = {} |
|
1040
|
): Promise<InferEntityType<typeof LineItemAdjustment>[]> { |
|
1041
|
const cart = await this.cartService_.retrieve( |
|
1042
|
cartId, |
|
1043
|
{ select: ["id"], relations: ["items.adjustments"] }, |
|
1044
|
sharedContext |
|
1045
|
) |
|
1046
|
|
|
1047
|
const existingAdjustments = await this.lineItemAdjustmentService_.list( |
|
1048
|
{ item: { cart_id: cart.id } }, |
|
1049
|
{ select: ["id"] }, |
|
1050
|
sharedContext |
|
1051
|
) |
|
1052
|
|
|
1053
|
const adjustmentsSet = new Set( |
|
1054
|
adjustments |
|
1055
|
.map((a) => (a as CartTypes.UpdateLineItemAdjustmentDTO).id) |
|
1056
|
.filter(Boolean) |
|
1057
|
) |
|
1058
|
|
|
1059
|
const toDelete: InferEntityType<typeof LineItemAdjustment>[] = [] |
|
1060
|
|
|
1061
|
// From the existing adjustments, find the ones that are not passed in adjustments |
|
1062
|
existingAdjustments.forEach( |
|
1063
|
(adj: InferEntityType<typeof LineItemAdjustment>) => { |
|
1064
|
if (!adjustmentsSet.has(adj.id)) { |
|
1065
|
toDelete.push(adj) |
|
1066
|
} |
|
1067
|
} |
|
1068
|
) |
|
1069
|
|
|
1070
|
if (toDelete.length) { |
|
1071
|
await this.lineItemAdjustmentService_.softDelete( |
|
1072
|
toDelete.map((adj) => adj!.id), |
|
1073
|
sharedContext |
|
1074
|
) |
|
1075
|
} |
|
1076
|
|
|
1077
|
let result = await this.lineItemAdjustmentService_.upsert( |
|
1078
|
adjustments, |
|
1079
|
sharedContext |
|
1080
|
) |
|
1081
|
|
|
1082
|
return result |
|
1083
|
} |
|
1084
|
|
|
1085
|
@InjectManager() |
|
1086
|
@EmitEvents() |
|
1087
|
async setShippingMethodAdjustments( |
|
1088
|
cartId: string, |
|
1089
|
adjustments: ( |
|
1090
|
| CartTypes.CreateShippingMethodAdjustmentDTO |
|
1091
|
| CartTypes.UpdateShippingMethodAdjustmentDTO |
|
1092
|
)[], |
|
1093
|
@MedusaContext() sharedContext: Context = {} |
|
1094
|
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> { |
|
1095
|
const result = await this.setShippingMethodAdjustments_( |
|
1096
|
cartId, |
|
1097
|
adjustments, |
|
1098
|
sharedContext |
|
1099
|
) |
|
1100
|
|
|
1101
|
return await this.baseRepository_.serialize< |
|
1102
|
CartTypes.ShippingMethodAdjustmentDTO[] |
|
1103
|
>(result) |
|
1104
|
} |
|
1105
|
|
|
1106
|
@InjectTransactionManager() |
|
1107
|
protected async setShippingMethodAdjustments_( |
|
1108
|
cartId: string, |
|
1109
|
adjustments: ( |
|
1110
|
| CartTypes.CreateShippingMethodAdjustmentDTO |
|
1111
|
| CartTypes.UpdateShippingMethodAdjustmentDTO |
|
1112
|
)[], |
|
1113
|
@MedusaContext() sharedContext: Context = {} |
|
1114
|
): Promise<InferEntityType<typeof ShippingMethodAdjustment>[]> { |
|
1115
|
const cart = await this.cartService_.retrieve( |
|
1116
|
cartId, |
|
1117
|
{ select: ["id"], relations: ["shipping_methods.adjustments"] }, |
|
1118
|
sharedContext |
|
1119
|
) |
|
1120
|
|
|
1121
|
const existingAdjustments = |
|
1122
|
await this.shippingMethodAdjustmentService_.list( |
|
1123
|
{ shipping_method: { cart_id: cart.id } }, |
|
1124
|
{ select: ["id"] }, |
|
1125
|
sharedContext |
|
1126
|
) |
|
1127
|
|
|
1128
|
const adjustmentsSet = new Set( |
|
1129
|
adjustments |
|
1130
|
.map((a) => (a as CartTypes.UpdateShippingMethodAdjustmentDTO)?.id) |
|
1131
|
.filter(Boolean) |
|
1132
|
) |
|
1133
|
|
|
1134
|
const toDelete: InferEntityType<typeof ShippingMethodAdjustment>[] = [] |
|
1135
|
|
|
1136
|
// From the existing adjustments, find the ones that are not passed in adjustments |
|
1137
|
existingAdjustments.forEach( |
|
1138
|
(adj: InferEntityType<typeof ShippingMethodAdjustment>) => { |
|
1139
|
if (!adjustmentsSet.has(adj.id)) { |
|
1140
|
toDelete.push(adj) |
|
1141
|
} |
|
1142
|
} |
|
1143
|
) |
|
1144
|
|
|
1145
|
if (toDelete.length) { |
|
1146
|
await this.shippingMethodAdjustmentService_.softDelete( |
|
1147
|
toDelete.map((adj) => adj!.id), |
|
1148
|
sharedContext |
|
1149
|
) |
|
1150
|
} |
|
1151
|
|
|
1152
|
const result = await this.shippingMethodAdjustmentService_.upsert( |
|
1153
|
adjustments, |
|
1154
|
sharedContext |
|
1155
|
) |
|
1156
|
|
|
1157
|
return result |
|
1158
|
} |
|
1159
|
|
|
1160
|
async addShippingMethodAdjustments( |
|
1161
|
adjustments: CartTypes.CreateShippingMethodAdjustmentDTO[] |
|
1162
|
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> |
|
1163
|
async addShippingMethodAdjustments( |
|
1164
|
adjustment: CartTypes.CreateShippingMethodAdjustmentDTO |
|
1165
|
): Promise<CartTypes.ShippingMethodAdjustmentDTO> |
|
1166
|
async addShippingMethodAdjustments( |
|
1167
|
cartId: string, |
|
1168
|
adjustments: CartTypes.CreateShippingMethodAdjustmentDTO[], |
|
1169
|
sharedContext?: Context |
|
1170
|
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> |
|
1171
|
|
|
1172
|
@InjectManager() |
|
1173
|
@EmitEvents() |
|
1174
|
async addShippingMethodAdjustments( |
|
1175
|
cartIdOrData: |
|
1176
|
| string |
|
1177
|
| CartTypes.CreateShippingMethodAdjustmentDTO[] |
|
1178
|
| CartTypes.CreateShippingMethodAdjustmentDTO, |
|
1179
|
adjustments?: CartTypes.CreateShippingMethodAdjustmentDTO[], |
|
1180
|
@MedusaContext() sharedContext: Context = {} |
|
1181
|
): Promise< |
|
1182
|
| CartTypes.ShippingMethodAdjustmentDTO[] |
|
1183
|
| CartTypes.ShippingMethodAdjustmentDTO |
|
1184
|
> { |
|
1185
|
const result = await this.addShippingMethodAdjustments_( |
|
1186
|
cartIdOrData, |
|
1187
|
adjustments, |
|
1188
|
sharedContext |
|
1189
|
) |
|
1190
|
|
|
1191
|
return await this.baseRepository_.serialize< |
|
1192
|
| CartTypes.ShippingMethodAdjustmentDTO[] |
|
1193
|
| CartTypes.ShippingMethodAdjustmentDTO |
|
1194
|
>(result) |
|
1195
|
} |
|
1196
|
|
|
1197
|
@InjectTransactionManager() |
|
1198
|
protected async addShippingMethodAdjustments_( |
|
1199
|
cartIdOrData: |
|
1200
|
| string |
|
1201
|
| CartTypes.CreateShippingMethodAdjustmentDTO[] |
|
1202
|
| CartTypes.CreateShippingMethodAdjustmentDTO, |
|
1203
|
adjustments?: CartTypes.CreateShippingMethodAdjustmentDTO[], |
|
1204
|
@MedusaContext() sharedContext: Context = {} |
|
1205
|
): Promise< |
|
1206
|
| InferEntityType<typeof ShippingMethodAdjustment>[] |
|
1207
|
| InferEntityType<typeof ShippingMethodAdjustment> |
|
1208
|
> { |
|
1209
|
let addedAdjustments: InferEntityType<typeof ShippingMethodAdjustment>[] = |
|
1210
|
[] |
|
1211
|
if (isString(cartIdOrData)) { |
|
1212
|
const cart = await this.cartService_.retrieve( |
|
1213
|
cartIdOrData, |
|
1214
|
{ select: ["id"], relations: ["shipping_methods"] }, |
|
1215
|
sharedContext |
|
1216
|
) |
|
1217
|
|
|
1218
|
const methodIds = cart.shipping_methods?.map((method) => method.id) |
|
1219
|
|
|
1220
|
for (const adj of adjustments || []) { |
|
1221
|
if (!methodIds?.includes(adj.shipping_method_id)) { |
|
1222
|
throw new MedusaError( |
|
1223
|
MedusaError.Types.INVALID_DATA, |
|
1224
|
`Shipping method with id ${adj.shipping_method_id} does not exist on cart with id ${cartIdOrData}` |
|
1225
|
) |
|
1226
|
} |
|
1227
|
} |
|
1228
|
|
|
1229
|
addedAdjustments = await this.shippingMethodAdjustmentService_.create( |
|
1230
|
adjustments as CartTypes.CreateShippingMethodAdjustmentDTO[], |
|
1231
|
sharedContext |
|
1232
|
) |
|
1233
|
} else { |
|
1234
|
const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData] |
|
1235
|
|
|
1236
|
addedAdjustments = await this.shippingMethodAdjustmentService_.create( |
|
1237
|
data as CartTypes.CreateShippingMethodAdjustmentDTO[], |
|
1238
|
sharedContext |
|
1239
|
) |
|
1240
|
} |
|
1241
|
|
|
1242
|
if (isObject(cartIdOrData)) { |
|
1243
|
return addedAdjustments[0] |
|
1244
|
} |
|
1245
|
|
|
1246
|
return addedAdjustments |
|
1247
|
} |
|
1248
|
|
|
1249
|
async addLineItemTaxLines( |
|
1250
|
taxLines: CartTypes.CreateLineItemTaxLineDTO[] |
|
1251
|
): Promise<CartTypes.LineItemTaxLineDTO[]> |
|
1252
|
addLineItemTaxLines( |
|
1253
|
taxLine: CartTypes.CreateLineItemTaxLineDTO |
|
1254
|
): Promise<CartTypes.LineItemTaxLineDTO> |
|
1255
|
addLineItemTaxLines( |
|
1256
|
cartId: string, |
|
1257
|
taxLines: |
|
1258
|
| CartTypes.CreateLineItemTaxLineDTO[] |
|
1259
|
| CartTypes.CreateShippingMethodTaxLineDTO, |
|
1260
|
sharedContext?: Context |
|
1261
|
): Promise<CartTypes.LineItemTaxLineDTO[]> |
|
1262
|
|
|
1263
|
@InjectManager() |
|
1264
|
@EmitEvents() |
|
1265
|
async addLineItemTaxLines( |
|
1266
|
cartIdOrData: |
|
1267
|
| string |
|
1268
|
| CartTypes.CreateLineItemTaxLineDTO[] |
|
1269
|
| CartTypes.CreateLineItemTaxLineDTO, |
|
1270
|
taxLines?: |
|
1271
|
| CartTypes.CreateLineItemTaxLineDTO[] |
|
1272
|
| CartTypes.CreateLineItemTaxLineDTO, |
|
1273
|
@MedusaContext() sharedContext: Context = {} |
|
1274
|
): Promise<CartTypes.LineItemTaxLineDTO[] | CartTypes.LineItemTaxLineDTO> { |
|
1275
|
const result = await this.addLineItemTaxLines_( |
|
1276
|
cartIdOrData, |
|
1277
|
taxLines, |
|
1278
|
sharedContext |
|
1279
|
) |
|
1280
|
|
|
1281
|
return await this.baseRepository_.serialize< |
|
1282
|
CartTypes.LineItemTaxLineDTO[] | CartTypes.LineItemTaxLineDTO |
|
1283
|
>(result) |
|
1284
|
} |
|
1285
|
|
|
1286
|
@InjectTransactionManager() |
|
1287
|
protected async addLineItemTaxLines_( |
|
1288
|
cartIdOrData: |
|
1289
|
| string |
|
1290
|
| CartTypes.CreateLineItemTaxLineDTO[] |
|
1291
|
| CartTypes.CreateLineItemTaxLineDTO, |
|
1292
|
taxLines?: |
|
1293
|
| CartTypes.CreateLineItemTaxLineDTO[] |
|
1294
|
| CartTypes.CreateLineItemTaxLineDTO, |
|
1295
|
@MedusaContext() sharedContext: Context = {} |
|
1296
|
): Promise< |
|
1297
|
| InferEntityType<typeof LineItemTaxLine>[] |
|
1298
|
| InferEntityType<typeof LineItemTaxLine> |
|
1299
|
> { |
|
1300
|
let addedTaxLines: InferEntityType<typeof LineItemTaxLine>[] |
|
1301
|
if (isString(cartIdOrData)) { |
|
1302
|
// existence check |
|
1303
|
const cart = await this.cartService_.retrieve( |
|
1304
|
cartIdOrData, |
|
1305
|
{ select: ["id"] }, |
|
1306
|
sharedContext |
|
1307
|
) |
|
1308
|
|
|
1309
|
if (!cart) { |
|
1310
|
throw new MedusaError( |
|
1311
|
MedusaError.Types.INVALID_DATA, |
|
1312
|
`Cart with id ${cartIdOrData} does not exist` |
|
1313
|
) |
|
1314
|
} |
|
1315
|
|
|
1316
|
const lines = Array.isArray(taxLines) ? taxLines : [taxLines] |
|
1317
|
|
|
1318
|
addedTaxLines = await this.lineItemTaxLineService_.create( |
|
1319
|
lines, |
|
1320
|
sharedContext |
|
1321
|
) |
|
1322
|
} else { |
|
1323
|
const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData] |
|
1324
|
|
|
1325
|
addedTaxLines = await this.lineItemTaxLineService_.create( |
|
1326
|
data, |
|
1327
|
sharedContext |
|
1328
|
) |
|
1329
|
} |
|
1330
|
|
|
1331
|
if (isObject(cartIdOrData)) { |
|
1332
|
return addedTaxLines[0] |
|
1333
|
} |
|
1334
|
|
|
1335
|
return addedTaxLines |
|
1336
|
} |
|
1337
|
|
|
1338
|
@InjectManager() |
|
1339
|
@EmitEvents() |
|
1340
|
async setLineItemTaxLines( |
|
1341
|
cartId: string, |
|
1342
|
taxLines: ( |
|
1343
|
| CartTypes.CreateLineItemTaxLineDTO |
|
1344
|
| CartTypes.UpdateLineItemTaxLineDTO |
|
1345
|
)[], |
|
1346
|
@MedusaContext() sharedContext: Context = {} |
|
1347
|
): Promise<CartTypes.LineItemTaxLineDTO[]> { |
|
1348
|
const result = await this.setLineItemTaxLines_( |
|
1349
|
cartId, |
|
1350
|
taxLines, |
|
1351
|
sharedContext |
|
1352
|
) |
|
1353
|
|
|
1354
|
return await this.baseRepository_.serialize<CartTypes.LineItemTaxLineDTO[]>( |
|
1355
|
result |
|
1356
|
) |
|
1357
|
} |
|
1358
|
|
|
1359
|
@InjectTransactionManager() |
|
1360
|
protected async setLineItemTaxLines_( |
|
1361
|
cartId: string, |
|
1362
|
taxLines: ( |
|
1363
|
| CartTypes.CreateLineItemTaxLineDTO |
|
1364
|
| CartTypes.UpdateLineItemTaxLineDTO |
|
1365
|
)[], |
|
1366
|
@MedusaContext() sharedContext: Context = {} |
|
1367
|
): Promise<InferEntityType<typeof LineItemTaxLine>[]> { |
|
1368
|
const normalizedTaxLines = ( |
|
1369
|
taxLines as CartTypes.UpdateLineItemTaxLineDTO[] |
|
1370
|
).map((taxLine) => { |
|
1371
|
// Pre generate the id so that we can optimized the actions below |
|
1372
|
taxLine.id = generateEntityId(taxLine.id, "calitxl") |
|
1373
|
return taxLine |
|
1374
|
}) |
|
1375
|
|
|
1376
|
const taxLineIdsSet = new Set<string>( |
|
1377
|
normalizedTaxLines.map( |
|
1378
|
(taxLine) => (taxLine as CartTypes.UpdateLineItemTaxLineDTO)?.id |
|
1379
|
) |
|
1380
|
) |
|
1381
|
|
|
1382
|
const deleteConstraints: { |
|
1383
|
id?: { |
|
1384
|
$nin: string[] |
|
1385
|
} |
|
1386
|
item: { cart_id: string } |
|
1387
|
} = { |
|
1388
|
item: { cart_id: cartId }, |
|
1389
|
} |
|
1390
|
|
|
1391
|
if (taxLineIdsSet.size) { |
|
1392
|
deleteConstraints.id = { |
|
1393
|
$nin: Array.from(taxLineIdsSet), |
|
1394
|
} |
|
1395
|
} |
|
1396
|
|
|
1397
|
const [result] = await promiseAll([ |
|
1398
|
normalizedTaxLines.length |
|
1399
|
? this.lineItemTaxLineService_.upsert(normalizedTaxLines, sharedContext) |
|
1400
|
: [], |
|
1401
|
this.lineItemTaxLineService_.softDelete(deleteConstraints, sharedContext), |
|
1402
|
]) |
|
1403
|
|
|
1404
|
return result |
|
1405
|
} |
|
1406
|
|
|
1407
|
addShippingMethodTaxLines( |
|
1408
|
taxLines: CartTypes.CreateShippingMethodTaxLineDTO[] |
|
1409
|
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> |
|
1410
|
addShippingMethodTaxLines( |
|
1411
|
taxLine: CartTypes.CreateShippingMethodTaxLineDTO |
|
1412
|
): Promise<CartTypes.ShippingMethodTaxLineDTO> |
|
1413
|
addShippingMethodTaxLines( |
|
1414
|
cartId: string, |
|
1415
|
taxLines: |
|
1416
|
| CartTypes.CreateShippingMethodTaxLineDTO[] |
|
1417
|
| CartTypes.CreateShippingMethodTaxLineDTO, |
|
1418
|
sharedContext?: Context |
|
1419
|
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> |
|
1420
|
|
|
1421
|
@InjectManager() |
|
1422
|
@EmitEvents() |
|
1423
|
async addShippingMethodTaxLines( |
|
1424
|
cartIdOrData: |
|
1425
|
| string |
|
1426
|
| CartTypes.CreateShippingMethodTaxLineDTO[] |
|
1427
|
| CartTypes.CreateShippingMethodTaxLineDTO, |
|
1428
|
taxLines?: |
|
1429
|
| CartTypes.CreateShippingMethodTaxLineDTO[] |
|
1430
|
| CartTypes.CreateShippingMethodTaxLineDTO, |
|
1431
|
@MedusaContext() sharedContext: Context = {} |
|
1432
|
): Promise< |
|
1433
|
CartTypes.ShippingMethodTaxLineDTO[] | CartTypes.ShippingMethodTaxLineDTO |
|
1434
|
> { |
|
1435
|
const result = await this.addShippingMethodTaxLines_( |
|
1436
|
cartIdOrData, |
|
1437
|
taxLines, |
|
1438
|
sharedContext |
|
1439
|
) |
|
1440
|
|
|
1441
|
return await this.baseRepository_.serialize< |
|
1442
|
CartTypes.ShippingMethodTaxLineDTO[] | CartTypes.ShippingMethodTaxLineDTO |
|
1443
|
>(result) |
|
1444
|
} |
|
1445
|
|
|
1446
|
@InjectTransactionManager() |
|
1447
|
protected async addShippingMethodTaxLines_( |
|
1448
|
cartIdOrData: |
|
1449
|
| string |
|
1450
|
| CartTypes.CreateShippingMethodTaxLineDTO[] |
|
1451
|
| CartTypes.CreateShippingMethodTaxLineDTO, |
|
1452
|
taxLines?: |
|
1453
|
| CartTypes.CreateShippingMethodTaxLineDTO[] |
|
1454
|
| CartTypes.CreateShippingMethodTaxLineDTO, |
|
1455
|
@MedusaContext() sharedContext: Context = {} |
|
1456
|
): Promise< |
|
1457
|
| InferEntityType<typeof ShippingMethodTaxLine>[] |
|
1458
|
| InferEntityType<typeof ShippingMethodTaxLine> |
|
1459
|
> { |
|
1460
|
let addedTaxLines: InferEntityType<typeof ShippingMethodTaxLine>[] |
|
1461
|
if (isString(cartIdOrData)) { |
|
1462
|
// existence check |
|
1463
|
const cart = await this.cartService_.retrieve( |
|
1464
|
cartIdOrData, |
|
1465
|
{ select: ["id"] }, |
|
1466
|
sharedContext |
|
1467
|
) |
|
1468
|
|
|
1469
|
if (!cart) { |
|
1470
|
throw new MedusaError( |
|
1471
|
MedusaError.Types.INVALID_DATA, |
|
1472
|
`Cart with id ${cartIdOrData} does not exist` |
|
1473
|
) |
|
1474
|
} |
|
1475
|
|
|
1476
|
const lines = Array.isArray(taxLines) ? taxLines : [taxLines] |
|
1477
|
|
|
1478
|
addedTaxLines = await this.shippingMethodTaxLineService_.create( |
|
1479
|
lines, |
|
1480
|
sharedContext |
|
1481
|
) |
|
1482
|
} else { |
|
1483
|
const lines = Array.isArray(taxLines) ? taxLines : [taxLines] |
|
1484
|
|
|
1485
|
addedTaxLines = await this.shippingMethodTaxLineService_.create( |
|
1486
|
lines, |
|
1487
|
sharedContext |
|
1488
|
) |
|
1489
|
} |
|
1490
|
|
|
1491
|
if (isObject(cartIdOrData)) { |
|
1492
|
return addedTaxLines[0] |
|
1493
|
} |
|
1494
|
|
|
1495
|
return addedTaxLines |
|
1496
|
} |
|
1497
|
|
|
1498
|
@InjectManager() |
|
1499
|
@EmitEvents() |
|
1500
|
async setShippingMethodTaxLines( |
|
1501
|
cartId: string, |
|
1502
|
taxLines: ( |
|
1503
|
| CartTypes.CreateShippingMethodTaxLineDTO |
|
1504
|
| CartTypes.UpdateShippingMethodTaxLineDTO |
|
1505
|
)[], |
|
1506
|
@MedusaContext() sharedContext: Context = {} |
|
1507
|
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> { |
|
1508
|
const result = await this.setShippingMethodTaxLines_( |
|
1509
|
cartId, |
|
1510
|
taxLines, |
|
1511
|
sharedContext |
|
1512
|
) |
|
1513
|
|
|
1514
|
return await this.baseRepository_.serialize< |
|
1515
|
CartTypes.ShippingMethodTaxLineDTO[] |
|
1516
|
>(result) |
|
1517
|
} |
|
1518
|
|
|
1519
|
@InjectTransactionManager() |
|
1520
|
protected async setShippingMethodTaxLines_( |
|
1521
|
cartId: string, |
|
1522
|
taxLines: ( |
|
1523
|
| CartTypes.CreateShippingMethodTaxLineDTO |
|
1524
|
| CartTypes.UpdateShippingMethodTaxLineDTO |
|
1525
|
)[], |
|
1526
|
@MedusaContext() sharedContext: Context = {} |
|
1527
|
): Promise<InferEntityType<typeof ShippingMethodTaxLine>[]> { |
|
1528
|
const normalizedTaxLines = ( |
|
1529
|
taxLines as CartTypes.UpdateShippingMethodTaxLineDTO[] |
|
1530
|
).map((taxLine) => { |
|
1531
|
taxLine.id = generateEntityId(taxLine.id, "casmtxl") |
|
1532
|
return taxLine |
|
1533
|
}) |
|
1534
|
|
|
1535
|
const taxLineIdsSet = new Set( |
|
1536
|
normalizedTaxLines.map( |
|
1537
|
(taxLine) => (taxLine as CartTypes.UpdateShippingMethodTaxLineDTO)?.id |
|
1538
|
) |
|
1539
|
) |
|
1540
|
|
|
1541
|
const deleteConstraints: { |
|
1542
|
id?: { |
|
1543
|
$nin: string[] |
|
1544
|
} |
|
1545
|
shipping_method: { cart_id: string } |
|
1546
|
} = { |
|
1547
|
shipping_method: { cart_id: cartId }, |
|
1548
|
} |
|
1549
|
|
|
1550
|
if (taxLineIdsSet.size) { |
|
1551
|
deleteConstraints.id = { |
|
1552
|
$nin: Array.from(taxLineIdsSet), |
|
1553
|
} |
|
1554
|
} |
|
1555
|
|
|
1556
|
const [result] = await promiseAll([ |
|
1557
|
taxLines.length |
|
1558
|
? this.shippingMethodTaxLineService_.upsert(taxLines, sharedContext) |
|
1559
|
: [], |
|
1560
|
this.shippingMethodTaxLineService_.softDelete( |
|
1561
|
deleteConstraints, |
|
1562
|
sharedContext |
|
1563
|
), |
|
1564
|
]) |
|
1565
|
|
|
1566
|
return result |
|
1567
|
} |
|
1568
|
} |