@medusajs/order 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +1 -0
  2. package/dist/index.d.ts +8 -0
  3. package/dist/index.js +29 -0
  4. package/dist/joiner-config.d.ts +5 -0
  5. package/dist/joiner-config.js +23 -0
  6. package/dist/models/address.d.ts +24 -0
  7. package/dist/models/address.js +125 -0
  8. package/dist/models/adjustment-line.d.ts +21 -0
  9. package/dist/models/adjustment-line.js +73 -0
  10. package/dist/models/index.d.ts +8 -0
  11. package/dist/models/index.js +22 -0
  12. package/dist/models/line-item-adjustment.d.ts +8 -0
  13. package/dist/models/line-item-adjustment.js +57 -0
  14. package/dist/models/line-item-tax-line.d.ts +8 -0
  15. package/dist/models/line-item-tax-line.js +54 -0
  16. package/dist/models/line-item.d.ts +45 -0
  17. package/dist/models/line-item.js +241 -0
  18. package/dist/models/order.d.ts +32 -0
  19. package/dist/models/order.js +195 -0
  20. package/dist/models/shipping-method-adjustment.d.ts +8 -0
  21. package/dist/models/shipping-method-adjustment.js +55 -0
  22. package/dist/models/shipping-method-tax-line.d.ts +8 -0
  23. package/dist/models/shipping-method-tax-line.js +55 -0
  24. package/dist/models/shipping-method.d.ts +26 -0
  25. package/dist/models/shipping-method.js +157 -0
  26. package/dist/models/tax-line.d.ts +17 -0
  27. package/dist/models/tax-line.js +67 -0
  28. package/dist/module-definition.d.ts +2 -0
  29. package/dist/module-definition.js +58 -0
  30. package/dist/repositories/index.d.ts +1 -0
  31. package/dist/repositories/index.js +5 -0
  32. package/dist/scripts/bin/run-seed.d.ts +3 -0
  33. package/dist/scripts/bin/run-seed.js +48 -0
  34. package/dist/services/index.d.ts +1 -0
  35. package/dist/services/index.js +8 -0
  36. package/dist/services/order-module-service.d.ts +114 -0
  37. package/dist/services/order-module-service.js +671 -0
  38. package/dist/types/UpdateOrderShippingMethodDTO.d.ts +7 -0
  39. package/dist/types/UpdateOrderShippingMethodDTO.js +2 -0
  40. package/dist/types/address.d.ts +19 -0
  41. package/dist/types/address.js +2 -0
  42. package/dist/types/index.d.ts +13 -0
  43. package/dist/types/index.js +24 -0
  44. package/dist/types/line-item-adjustment.d.ts +12 -0
  45. package/dist/types/line-item-adjustment.js +2 -0
  46. package/dist/types/line-item-tax-line.d.ts +7 -0
  47. package/dist/types/line-item-tax-line.js +2 -0
  48. package/dist/types/line-item.d.ts +31 -0
  49. package/dist/types/line-item.js +2 -0
  50. package/dist/types/order.d.ts +24 -0
  51. package/dist/types/order.js +2 -0
  52. package/dist/types/shipping-method-adjustment.d.ts +17 -0
  53. package/dist/types/shipping-method-adjustment.js +2 -0
  54. package/dist/types/shipping-method-tax-line.d.ts +7 -0
  55. package/dist/types/shipping-method-tax-line.js +2 -0
  56. package/dist/types/shipping-method.d.ts +13 -0
  57. package/dist/types/shipping-method.js +2 -0
  58. package/dist/types/tax-line.d.ts +16 -0
  59. package/dist/types/tax-line.js +2 -0
  60. package/package.json +61 -0
@@ -0,0 +1,671 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const utils_1 = require("@medusajs/utils");
16
+ const _models_1 = require("../models");
17
+ const joiner_config_1 = require("../joiner-config");
18
+ const generateMethodForModels = [
19
+ _models_1.Address,
20
+ _models_1.LineItem,
21
+ _models_1.LineItemAdjustment,
22
+ _models_1.LineItemTaxLine,
23
+ _models_1.ShippingMethod,
24
+ _models_1.ShippingMethodAdjustment,
25
+ _models_1.ShippingMethodTaxLine,
26
+ ];
27
+ class OrderModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Order, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
28
+ constructor({ baseRepository, orderService, addressService, lineItemService, shippingMethodAdjustmentService, shippingMethodService, lineItemAdjustmentService, shippingMethodTaxLineService, lineItemTaxLineService, }, moduleDeclaration) {
29
+ // @ts-ignore
30
+ super(...arguments);
31
+ this.moduleDeclaration = moduleDeclaration;
32
+ this.baseRepository_ = baseRepository;
33
+ this.orderService_ = orderService;
34
+ this.addressService_ = addressService;
35
+ this.lineItemService_ = lineItemService;
36
+ this.shippingMethodAdjustmentService_ = shippingMethodAdjustmentService;
37
+ this.shippingMethodService_ = shippingMethodService;
38
+ this.lineItemAdjustmentService_ = lineItemAdjustmentService;
39
+ this.shippingMethodTaxLineService_ = shippingMethodTaxLineService;
40
+ this.lineItemTaxLineService_ = lineItemTaxLineService;
41
+ }
42
+ __joinerConfig() {
43
+ return joiner_config_1.joinerConfig;
44
+ }
45
+ async create(data, sharedContext = {}) {
46
+ const input = Array.isArray(data) ? data : [data];
47
+ const orders = await this.create_(input, sharedContext);
48
+ const result = await this.list({ id: orders.map((p) => p.id) }, {
49
+ relations: ["shipping_address", "billing_address"],
50
+ }, sharedContext);
51
+ return (Array.isArray(data) ? result : result[0]);
52
+ }
53
+ async create_(data, sharedContext = {}) {
54
+ const lineItemsToCreate = [];
55
+ const createdOrders = [];
56
+ for (const { items, ...order } of data) {
57
+ const [created] = await this.orderService_.create([order], sharedContext);
58
+ createdOrders.push(created);
59
+ if (items?.length) {
60
+ const orderItems = items.map((item) => {
61
+ return {
62
+ ...item,
63
+ order_id: created.id,
64
+ };
65
+ });
66
+ lineItemsToCreate.push(...orderItems);
67
+ }
68
+ }
69
+ if (lineItemsToCreate.length) {
70
+ await this.addLineItemsBulk_(lineItemsToCreate, sharedContext);
71
+ }
72
+ return createdOrders;
73
+ }
74
+ async update(data, sharedContext = {}) {
75
+ const input = Array.isArray(data) ? data : [data];
76
+ const orders = await this.update_(input, sharedContext);
77
+ const result = await this.list({ id: orders.map((p) => p.id) }, {
78
+ relations: ["shipping_address", "billing_address"],
79
+ }, sharedContext);
80
+ return (Array.isArray(data) ? result : result[0]);
81
+ }
82
+ async update_(data, sharedContext = {}) {
83
+ return await this.orderService_.update(data, sharedContext);
84
+ }
85
+ async addLineItems(orderIdOrData, data, sharedContext = {}) {
86
+ let items = [];
87
+ if ((0, utils_1.isString)(orderIdOrData)) {
88
+ items = await this.addLineItems_(orderIdOrData, data, sharedContext);
89
+ }
90
+ else {
91
+ const data = Array.isArray(orderIdOrData)
92
+ ? orderIdOrData
93
+ : [orderIdOrData];
94
+ items = await this.addLineItemsBulk_(data, sharedContext);
95
+ }
96
+ return await this.baseRepository_.serialize(items, {
97
+ populate: true,
98
+ });
99
+ }
100
+ async addLineItems_(orderId, items, sharedContext = {}) {
101
+ const order = await this.retrieve(orderId, { select: ["id"] }, sharedContext);
102
+ const toUpdate = items.map((item) => {
103
+ return {
104
+ ...item,
105
+ order_id: order.id,
106
+ };
107
+ });
108
+ return await this.addLineItemsBulk_(toUpdate, sharedContext);
109
+ }
110
+ async addLineItemsBulk_(data, sharedContext = {}) {
111
+ return await this.lineItemService_.create(data, sharedContext);
112
+ }
113
+ async updateLineItems(lineItemIdOrDataOrSelector, data, sharedContext = {}) {
114
+ let items = [];
115
+ if ((0, utils_1.isString)(lineItemIdOrDataOrSelector)) {
116
+ const item = await this.updateLineItem_(lineItemIdOrDataOrSelector, data, sharedContext);
117
+ return await this.baseRepository_.serialize(item, {
118
+ populate: true,
119
+ });
120
+ }
121
+ const toUpdate = Array.isArray(lineItemIdOrDataOrSelector)
122
+ ? lineItemIdOrDataOrSelector
123
+ : [
124
+ {
125
+ selector: lineItemIdOrDataOrSelector,
126
+ data: data,
127
+ },
128
+ ];
129
+ items = await this.updateLineItemsWithSelector_(toUpdate, sharedContext);
130
+ return await this.baseRepository_.serialize(items, {
131
+ populate: true,
132
+ });
133
+ }
134
+ async updateLineItem_(lineItemId, data, sharedContext = {}) {
135
+ const [item] = await this.lineItemService_.update([{ id: lineItemId, ...data }], sharedContext);
136
+ return item;
137
+ }
138
+ async updateLineItemsWithSelector_(updates, sharedContext = {}) {
139
+ let toUpdate = [];
140
+ for (const { selector, data } of updates) {
141
+ const items = await this.listLineItems({ ...selector }, {}, sharedContext);
142
+ items.forEach((item) => {
143
+ toUpdate.push({
144
+ ...data,
145
+ id: item.id,
146
+ });
147
+ });
148
+ }
149
+ return await this.lineItemService_.update(toUpdate, sharedContext);
150
+ }
151
+ async removeLineItems(itemIdsOrSelector, sharedContext = {}) {
152
+ let toDelete;
153
+ if ((0, utils_1.isObject)(itemIdsOrSelector)) {
154
+ const items = await this.listLineItems({ ...itemIdsOrSelector }, {}, sharedContext);
155
+ toDelete = items.map((item) => item.id);
156
+ }
157
+ else {
158
+ toDelete = Array.isArray(itemIdsOrSelector)
159
+ ? itemIdsOrSelector
160
+ : [itemIdsOrSelector];
161
+ }
162
+ await this.lineItemService_.delete(toDelete, sharedContext);
163
+ }
164
+ async createAddresses(data, sharedContext = {}) {
165
+ const input = Array.isArray(data) ? data : [data];
166
+ const addresses = await this.createAddresses_(input, sharedContext);
167
+ const result = await this.listAddresses({ id: addresses.map((p) => p.id) }, {}, sharedContext);
168
+ return (Array.isArray(data) ? result : result[0]);
169
+ }
170
+ async createAddresses_(data, sharedContext = {}) {
171
+ return await this.addressService_.create(data, sharedContext);
172
+ }
173
+ async updateAddresses(data, sharedContext = {}) {
174
+ const input = Array.isArray(data) ? data : [data];
175
+ const addresses = await this.updateAddresses_(input, sharedContext);
176
+ const result = await this.listAddresses({ id: addresses.map((p) => p.id) }, {}, sharedContext);
177
+ return (Array.isArray(data) ? result : result[0]);
178
+ }
179
+ async updateAddresses_(data, sharedContext = {}) {
180
+ return await this.addressService_.update(data, sharedContext);
181
+ }
182
+ async addShippingMethods(orderIdOrData, data, sharedContext = {}) {
183
+ let methods;
184
+ if ((0, utils_1.isString)(orderIdOrData)) {
185
+ methods = await this.addShippingMethods_(orderIdOrData, data, sharedContext);
186
+ }
187
+ else {
188
+ const data = Array.isArray(orderIdOrData)
189
+ ? orderIdOrData
190
+ : [orderIdOrData];
191
+ methods = await this.addShippingMethodsBulk_(data, sharedContext);
192
+ }
193
+ return await this.baseRepository_.serialize(methods, { populate: true });
194
+ }
195
+ async addShippingMethods_(orderId, data, sharedContext = {}) {
196
+ const order = await this.retrieve(orderId, { select: ["id"] }, sharedContext);
197
+ const methods = data.map((method) => {
198
+ return {
199
+ ...method,
200
+ order_id: order.id,
201
+ };
202
+ });
203
+ return await this.addShippingMethodsBulk_(methods, sharedContext);
204
+ }
205
+ async addShippingMethodsBulk_(data, sharedContext = {}) {
206
+ return await this.shippingMethodService_.create(data, sharedContext);
207
+ }
208
+ async removeShippingMethods(methodIdsOrSelector, sharedContext = {}) {
209
+ let toDelete;
210
+ if ((0, utils_1.isObject)(methodIdsOrSelector)) {
211
+ const methods = await this.listShippingMethods({
212
+ ...methodIdsOrSelector,
213
+ }, {}, sharedContext);
214
+ toDelete = methods.map((m) => m.id);
215
+ }
216
+ else {
217
+ toDelete = Array.isArray(methodIdsOrSelector)
218
+ ? methodIdsOrSelector
219
+ : [methodIdsOrSelector];
220
+ }
221
+ await this.shippingMethodService_.delete(toDelete, sharedContext);
222
+ }
223
+ async addLineItemAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
224
+ let addedAdjustments = [];
225
+ if ((0, utils_1.isString)(orderIdOrData)) {
226
+ const order = await this.retrieve(orderIdOrData, { select: ["id"], relations: ["items"] }, sharedContext);
227
+ const lineIds = order.items?.map((item) => item.id);
228
+ for (const adj of adjustments || []) {
229
+ if (!lineIds?.includes(adj.item_id)) {
230
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Line item with id ${adj.item_id} does not exist on order with id ${orderIdOrData}`);
231
+ }
232
+ }
233
+ addedAdjustments = await this.lineItemAdjustmentService_.create(adjustments, sharedContext);
234
+ }
235
+ else {
236
+ const data = Array.isArray(orderIdOrData)
237
+ ? orderIdOrData
238
+ : [orderIdOrData];
239
+ addedAdjustments = await this.lineItemAdjustmentService_.create(data, sharedContext);
240
+ }
241
+ return await this.baseRepository_.serialize(addedAdjustments, {
242
+ populate: true,
243
+ });
244
+ }
245
+ async setLineItemAdjustments(orderId, adjustments, sharedContext = {}) {
246
+ const order = await this.retrieve(orderId, { select: ["id"], relations: ["items.adjustments"] }, sharedContext);
247
+ const existingAdjustments = await this.listLineItemAdjustments({ item: { order_id: order.id } }, { select: ["id"] }, sharedContext);
248
+ const adjustmentsSet = new Set(adjustments
249
+ .map((a) => a.id)
250
+ .filter(Boolean));
251
+ const toDelete = [];
252
+ // From the existing adjustments, find the ones that are not passed in adjustments
253
+ existingAdjustments.forEach((adj) => {
254
+ if (!adjustmentsSet.has(adj.id)) {
255
+ toDelete.push(adj);
256
+ }
257
+ });
258
+ if (toDelete.length) {
259
+ await this.lineItemAdjustmentService_.delete(toDelete.map((adj) => adj.id), sharedContext);
260
+ }
261
+ let result = await this.lineItemAdjustmentService_.upsert(adjustments, sharedContext);
262
+ return await this.baseRepository_.serialize(result, {
263
+ populate: true,
264
+ });
265
+ }
266
+ async removeLineItemAdjustments(adjustmentIdsOrSelector, sharedContext = {}) {
267
+ let ids;
268
+ if ((0, utils_1.isObject)(adjustmentIdsOrSelector)) {
269
+ const adjustments = await this.listLineItemAdjustments({
270
+ ...adjustmentIdsOrSelector,
271
+ }, { select: ["id"] }, sharedContext);
272
+ ids = adjustments.map((adj) => adj.id);
273
+ }
274
+ else {
275
+ ids = Array.isArray(adjustmentIdsOrSelector)
276
+ ? adjustmentIdsOrSelector
277
+ : [adjustmentIdsOrSelector];
278
+ }
279
+ await this.lineItemAdjustmentService_.delete(ids, sharedContext);
280
+ }
281
+ async setShippingMethodAdjustments(orderId, adjustments, sharedContext = {}) {
282
+ const order = await this.retrieve(orderId, { select: ["id"], relations: ["shipping_methods.adjustments"] }, sharedContext);
283
+ const existingAdjustments = await this.listShippingMethodAdjustments({ shipping_method: { order_id: order.id } }, { select: ["id"] }, sharedContext);
284
+ const adjustmentsSet = new Set(adjustments
285
+ .map((a) => a?.id)
286
+ .filter(Boolean));
287
+ const toDelete = [];
288
+ // From the existing adjustments, find the ones that are not passed in adjustments
289
+ existingAdjustments.forEach((adj) => {
290
+ if (!adjustmentsSet.has(adj.id)) {
291
+ toDelete.push(adj);
292
+ }
293
+ });
294
+ if (toDelete.length) {
295
+ await this.shippingMethodAdjustmentService_.delete(toDelete.map((adj) => adj.id), sharedContext);
296
+ }
297
+ const result = await this.shippingMethodAdjustmentService_.upsert(adjustments, sharedContext);
298
+ return await this.baseRepository_.serialize(result, {
299
+ populate: true,
300
+ });
301
+ }
302
+ async addShippingMethodAdjustments(orderIdOrData, adjustments, sharedContext = {}) {
303
+ let addedAdjustments = [];
304
+ if ((0, utils_1.isString)(orderIdOrData)) {
305
+ const order = await this.retrieve(orderIdOrData, { select: ["id"], relations: ["shipping_methods"] }, sharedContext);
306
+ const methodIds = order.shipping_methods?.map((method) => method.id);
307
+ for (const adj of adjustments || []) {
308
+ if (!methodIds?.includes(adj.shipping_method_id)) {
309
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Shipping method with id ${adj.shipping_method_id} does not exist on order with id ${orderIdOrData}`);
310
+ }
311
+ }
312
+ addedAdjustments = await this.shippingMethodAdjustmentService_.create(adjustments, sharedContext);
313
+ }
314
+ else {
315
+ const data = Array.isArray(orderIdOrData)
316
+ ? orderIdOrData
317
+ : [orderIdOrData];
318
+ addedAdjustments = await this.shippingMethodAdjustmentService_.create(data, sharedContext);
319
+ }
320
+ if ((0, utils_1.isObject)(orderIdOrData)) {
321
+ return await this.baseRepository_.serialize(addedAdjustments[0], {
322
+ populate: true,
323
+ });
324
+ }
325
+ return await this.baseRepository_.serialize(addedAdjustments, {
326
+ populate: true,
327
+ });
328
+ }
329
+ async removeShippingMethodAdjustments(adjustmentIdsOrSelector, sharedContext = {}) {
330
+ let ids;
331
+ if ((0, utils_1.isObject)(adjustmentIdsOrSelector)) {
332
+ const adjustments = await this.listShippingMethodAdjustments({
333
+ ...adjustmentIdsOrSelector,
334
+ }, { select: ["id"] }, sharedContext);
335
+ ids = adjustments.map((adj) => adj.id);
336
+ }
337
+ else {
338
+ ids = Array.isArray(adjustmentIdsOrSelector)
339
+ ? adjustmentIdsOrSelector
340
+ : [adjustmentIdsOrSelector];
341
+ }
342
+ await this.shippingMethodAdjustmentService_.delete(ids, sharedContext);
343
+ }
344
+ async addLineItemTaxLines(orderIdOrData, taxLines, sharedContext = {}) {
345
+ let addedTaxLines;
346
+ if ((0, utils_1.isString)(orderIdOrData)) {
347
+ // existence check
348
+ await this.retrieve(orderIdOrData, { select: ["id"] }, sharedContext);
349
+ const lines = Array.isArray(taxLines) ? taxLines : [taxLines];
350
+ addedTaxLines = await this.lineItemTaxLineService_.create(lines, sharedContext);
351
+ }
352
+ else {
353
+ const data = Array.isArray(orderIdOrData)
354
+ ? orderIdOrData
355
+ : [orderIdOrData];
356
+ addedTaxLines = await this.lineItemTaxLineService_.create(data, sharedContext);
357
+ }
358
+ const serialized = await this.baseRepository_.serialize(addedTaxLines, {
359
+ populate: true,
360
+ });
361
+ if ((0, utils_1.isObject)(orderIdOrData)) {
362
+ return serialized[0];
363
+ }
364
+ return serialized;
365
+ }
366
+ async setLineItemTaxLines(orderId, taxLines, sharedContext = {}) {
367
+ const order = await this.retrieve(orderId, { select: ["id"], relations: ["items.tax_lines"] }, sharedContext);
368
+ const existingTaxLines = await this.listLineItemTaxLines({ item: { order_id: order.id } }, { select: ["id"] }, sharedContext);
369
+ const taxLinesSet = new Set(taxLines
370
+ .map((taxLine) => taxLine?.id)
371
+ .filter(Boolean));
372
+ const toDelete = [];
373
+ // From the existing tax lines, find the ones that are not passed in taxLines
374
+ existingTaxLines.forEach((taxLine) => {
375
+ if (!taxLinesSet.has(taxLine.id)) {
376
+ toDelete.push(taxLine);
377
+ }
378
+ });
379
+ if (toDelete.length) {
380
+ await this.lineItemTaxLineService_.delete(toDelete.map((taxLine) => taxLine.id), sharedContext);
381
+ }
382
+ const result = await this.lineItemTaxLineService_.upsert(taxLines, sharedContext);
383
+ return await this.baseRepository_.serialize(result, {
384
+ populate: true,
385
+ });
386
+ }
387
+ async removeLineItemTaxLines(taxLineIdsOrSelector, sharedContext = {}) {
388
+ let ids;
389
+ if ((0, utils_1.isObject)(taxLineIdsOrSelector)) {
390
+ const taxLines = await this.listLineItemTaxLines({
391
+ ...taxLineIdsOrSelector,
392
+ }, { select: ["id"] }, sharedContext);
393
+ ids = taxLines.map((taxLine) => taxLine.id);
394
+ }
395
+ else {
396
+ ids = Array.isArray(taxLineIdsOrSelector)
397
+ ? taxLineIdsOrSelector
398
+ : [taxLineIdsOrSelector];
399
+ }
400
+ await this.lineItemTaxLineService_.delete(ids, sharedContext);
401
+ }
402
+ async addShippingMethodTaxLines(orderIdOrData, taxLines, sharedContext = {}) {
403
+ let addedTaxLines;
404
+ if ((0, utils_1.isString)(orderIdOrData)) {
405
+ // existence check
406
+ await this.retrieve(orderIdOrData, { select: ["id"] }, sharedContext);
407
+ const lines = Array.isArray(taxLines) ? taxLines : [taxLines];
408
+ addedTaxLines = await this.shippingMethodTaxLineService_.create(lines, sharedContext);
409
+ }
410
+ else {
411
+ addedTaxLines = await this.shippingMethodTaxLineService_.create(taxLines, sharedContext);
412
+ }
413
+ const serialized = await this.baseRepository_.serialize(addedTaxLines[0], {
414
+ populate: true,
415
+ });
416
+ if ((0, utils_1.isObject)(orderIdOrData)) {
417
+ return serialized[0];
418
+ }
419
+ return serialized;
420
+ }
421
+ async setShippingMethodTaxLines(orderId, taxLines, sharedContext = {}) {
422
+ const order = await this.retrieve(orderId, { select: ["id"], relations: ["shipping_methods.tax_lines"] }, sharedContext);
423
+ const existingTaxLines = await this.listShippingMethodTaxLines({ shipping_method: { order_id: order.id } }, { select: ["id"] }, sharedContext);
424
+ const taxLinesSet = new Set(taxLines
425
+ .map((taxLine) => taxLine?.id)
426
+ .filter(Boolean));
427
+ const toDelete = [];
428
+ // From the existing tax lines, find the ones that are not passed in taxLines
429
+ existingTaxLines.forEach((taxLine) => {
430
+ if (!taxLinesSet.has(taxLine.id)) {
431
+ toDelete.push(taxLine);
432
+ }
433
+ });
434
+ if (toDelete.length) {
435
+ await this.shippingMethodTaxLineService_.delete(toDelete.map((taxLine) => taxLine.id), sharedContext);
436
+ }
437
+ const result = await this.shippingMethodTaxLineService_.upsert(taxLines, sharedContext);
438
+ return await this.baseRepository_.serialize(result, {
439
+ populate: true,
440
+ });
441
+ }
442
+ async removeShippingMethodTaxLines(taxLineIdsOrSelector, sharedContext = {}) {
443
+ let ids;
444
+ if ((0, utils_1.isObject)(taxLineIdsOrSelector)) {
445
+ const taxLines = await this.listShippingMethodTaxLines({
446
+ ...taxLineIdsOrSelector,
447
+ }, { select: ["id"] }, sharedContext);
448
+ ids = taxLines.map((taxLine) => taxLine.id);
449
+ }
450
+ else {
451
+ ids = Array.isArray(taxLineIdsOrSelector)
452
+ ? taxLineIdsOrSelector
453
+ : [taxLineIdsOrSelector];
454
+ }
455
+ await this.shippingMethodTaxLineService_.delete(ids, sharedContext);
456
+ }
457
+ }
458
+ exports.default = OrderModuleService;
459
+ __decorate([
460
+ (0, utils_1.InjectManager)("baseRepository_"),
461
+ __param(1, (0, utils_1.MedusaContext)()),
462
+ __metadata("design:type", Function),
463
+ __metadata("design:paramtypes", [Object, Object]),
464
+ __metadata("design:returntype", Promise)
465
+ ], OrderModuleService.prototype, "create", null);
466
+ __decorate([
467
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
468
+ __param(1, (0, utils_1.MedusaContext)()),
469
+ __metadata("design:type", Function),
470
+ __metadata("design:paramtypes", [Array, Object]),
471
+ __metadata("design:returntype", Promise)
472
+ ], OrderModuleService.prototype, "create_", null);
473
+ __decorate([
474
+ (0, utils_1.InjectManager)("baseRepository_"),
475
+ __param(1, (0, utils_1.MedusaContext)()),
476
+ __metadata("design:type", Function),
477
+ __metadata("design:paramtypes", [Object, Object]),
478
+ __metadata("design:returntype", Promise)
479
+ ], OrderModuleService.prototype, "update", null);
480
+ __decorate([
481
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
482
+ __param(1, (0, utils_1.MedusaContext)()),
483
+ __metadata("design:type", Function),
484
+ __metadata("design:paramtypes", [Array, Object]),
485
+ __metadata("design:returntype", Promise)
486
+ ], OrderModuleService.prototype, "update_", null);
487
+ __decorate([
488
+ (0, utils_1.InjectManager)("baseRepository_"),
489
+ __param(2, (0, utils_1.MedusaContext)()),
490
+ __metadata("design:type", Function),
491
+ __metadata("design:paramtypes", [Object, Object, Object]),
492
+ __metadata("design:returntype", Promise)
493
+ ], OrderModuleService.prototype, "addLineItems", null);
494
+ __decorate([
495
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
496
+ __param(2, (0, utils_1.MedusaContext)()),
497
+ __metadata("design:type", Function),
498
+ __metadata("design:paramtypes", [String, Array, Object]),
499
+ __metadata("design:returntype", Promise)
500
+ ], OrderModuleService.prototype, "addLineItems_", null);
501
+ __decorate([
502
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
503
+ __param(1, (0, utils_1.MedusaContext)()),
504
+ __metadata("design:type", Function),
505
+ __metadata("design:paramtypes", [Array, Object]),
506
+ __metadata("design:returntype", Promise)
507
+ ], OrderModuleService.prototype, "addLineItemsBulk_", null);
508
+ __decorate([
509
+ (0, utils_1.InjectManager)("baseRepository_"),
510
+ __param(2, (0, utils_1.MedusaContext)()),
511
+ __metadata("design:type", Function),
512
+ __metadata("design:paramtypes", [Object, Object, Object]),
513
+ __metadata("design:returntype", Promise)
514
+ ], OrderModuleService.prototype, "updateLineItems", null);
515
+ __decorate([
516
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
517
+ __param(2, (0, utils_1.MedusaContext)()),
518
+ __metadata("design:type", Function),
519
+ __metadata("design:paramtypes", [String, Object, Object]),
520
+ __metadata("design:returntype", Promise)
521
+ ], OrderModuleService.prototype, "updateLineItem_", null);
522
+ __decorate([
523
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
524
+ __param(1, (0, utils_1.MedusaContext)()),
525
+ __metadata("design:type", Function),
526
+ __metadata("design:paramtypes", [Array, Object]),
527
+ __metadata("design:returntype", Promise)
528
+ ], OrderModuleService.prototype, "updateLineItemsWithSelector_", null);
529
+ __decorate([
530
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
531
+ __param(1, (0, utils_1.MedusaContext)()),
532
+ __metadata("design:type", Function),
533
+ __metadata("design:paramtypes", [Object, Object]),
534
+ __metadata("design:returntype", Promise)
535
+ ], OrderModuleService.prototype, "removeLineItems", null);
536
+ __decorate([
537
+ (0, utils_1.InjectManager)("baseRepository_"),
538
+ __param(1, (0, utils_1.MedusaContext)()),
539
+ __metadata("design:type", Function),
540
+ __metadata("design:paramtypes", [Object, Object]),
541
+ __metadata("design:returntype", Promise)
542
+ ], OrderModuleService.prototype, "createAddresses", null);
543
+ __decorate([
544
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
545
+ __param(1, (0, utils_1.MedusaContext)()),
546
+ __metadata("design:type", Function),
547
+ __metadata("design:paramtypes", [Array, Object]),
548
+ __metadata("design:returntype", Promise)
549
+ ], OrderModuleService.prototype, "createAddresses_", null);
550
+ __decorate([
551
+ (0, utils_1.InjectManager)("baseRepository_"),
552
+ __param(1, (0, utils_1.MedusaContext)()),
553
+ __metadata("design:type", Function),
554
+ __metadata("design:paramtypes", [Object, Object]),
555
+ __metadata("design:returntype", Promise)
556
+ ], OrderModuleService.prototype, "updateAddresses", null);
557
+ __decorate([
558
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
559
+ __param(1, (0, utils_1.MedusaContext)()),
560
+ __metadata("design:type", Function),
561
+ __metadata("design:paramtypes", [Array, Object]),
562
+ __metadata("design:returntype", Promise)
563
+ ], OrderModuleService.prototype, "updateAddresses_", null);
564
+ __decorate([
565
+ (0, utils_1.InjectManager)("baseRepository_"),
566
+ __param(2, (0, utils_1.MedusaContext)()),
567
+ __metadata("design:type", Function),
568
+ __metadata("design:paramtypes", [Object, Array, Object]),
569
+ __metadata("design:returntype", Promise)
570
+ ], OrderModuleService.prototype, "addShippingMethods", null);
571
+ __decorate([
572
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
573
+ __param(2, (0, utils_1.MedusaContext)()),
574
+ __metadata("design:type", Function),
575
+ __metadata("design:paramtypes", [String, Array, Object]),
576
+ __metadata("design:returntype", Promise)
577
+ ], OrderModuleService.prototype, "addShippingMethods_", null);
578
+ __decorate([
579
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
580
+ __param(1, (0, utils_1.MedusaContext)()),
581
+ __metadata("design:type", Function),
582
+ __metadata("design:paramtypes", [Array, Object]),
583
+ __metadata("design:returntype", Promise)
584
+ ], OrderModuleService.prototype, "addShippingMethodsBulk_", null);
585
+ __decorate([
586
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
587
+ __param(1, (0, utils_1.MedusaContext)()),
588
+ __metadata("design:type", Function),
589
+ __metadata("design:paramtypes", [Object, Object]),
590
+ __metadata("design:returntype", Promise)
591
+ ], OrderModuleService.prototype, "removeShippingMethods", null);
592
+ __decorate([
593
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
594
+ __param(2, (0, utils_1.MedusaContext)()),
595
+ __metadata("design:type", Function),
596
+ __metadata("design:paramtypes", [Object, Array, Object]),
597
+ __metadata("design:returntype", Promise)
598
+ ], OrderModuleService.prototype, "addLineItemAdjustments", null);
599
+ __decorate([
600
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
601
+ __param(2, (0, utils_1.MedusaContext)()),
602
+ __metadata("design:type", Function),
603
+ __metadata("design:paramtypes", [String, Array, Object]),
604
+ __metadata("design:returntype", Promise)
605
+ ], OrderModuleService.prototype, "setLineItemAdjustments", null);
606
+ __decorate([
607
+ __param(1, (0, utils_1.MedusaContext)()),
608
+ __metadata("design:type", Function),
609
+ __metadata("design:paramtypes", [Object, Object]),
610
+ __metadata("design:returntype", Promise)
611
+ ], OrderModuleService.prototype, "removeLineItemAdjustments", null);
612
+ __decorate([
613
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
614
+ __param(2, (0, utils_1.MedusaContext)()),
615
+ __metadata("design:type", Function),
616
+ __metadata("design:paramtypes", [String, Array, Object]),
617
+ __metadata("design:returntype", Promise)
618
+ ], OrderModuleService.prototype, "setShippingMethodAdjustments", null);
619
+ __decorate([
620
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
621
+ __param(2, (0, utils_1.MedusaContext)()),
622
+ __metadata("design:type", Function),
623
+ __metadata("design:paramtypes", [Object, Array, Object]),
624
+ __metadata("design:returntype", Promise)
625
+ ], OrderModuleService.prototype, "addShippingMethodAdjustments", null);
626
+ __decorate([
627
+ __param(1, (0, utils_1.MedusaContext)()),
628
+ __metadata("design:type", Function),
629
+ __metadata("design:paramtypes", [Object, Object]),
630
+ __metadata("design:returntype", Promise)
631
+ ], OrderModuleService.prototype, "removeShippingMethodAdjustments", null);
632
+ __decorate([
633
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
634
+ __param(2, (0, utils_1.MedusaContext)()),
635
+ __metadata("design:type", Function),
636
+ __metadata("design:paramtypes", [Object, Object, Object]),
637
+ __metadata("design:returntype", Promise)
638
+ ], OrderModuleService.prototype, "addLineItemTaxLines", null);
639
+ __decorate([
640
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
641
+ __param(2, (0, utils_1.MedusaContext)()),
642
+ __metadata("design:type", Function),
643
+ __metadata("design:paramtypes", [String, Array, Object]),
644
+ __metadata("design:returntype", Promise)
645
+ ], OrderModuleService.prototype, "setLineItemTaxLines", null);
646
+ __decorate([
647
+ __param(1, (0, utils_1.MedusaContext)()),
648
+ __metadata("design:type", Function),
649
+ __metadata("design:paramtypes", [Object, Object]),
650
+ __metadata("design:returntype", Promise)
651
+ ], OrderModuleService.prototype, "removeLineItemTaxLines", null);
652
+ __decorate([
653
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
654
+ __param(2, (0, utils_1.MedusaContext)()),
655
+ __metadata("design:type", Function),
656
+ __metadata("design:paramtypes", [Object, Object, Object]),
657
+ __metadata("design:returntype", Promise)
658
+ ], OrderModuleService.prototype, "addShippingMethodTaxLines", null);
659
+ __decorate([
660
+ (0, utils_1.InjectTransactionManager)("baseRepository_"),
661
+ __param(2, (0, utils_1.MedusaContext)()),
662
+ __metadata("design:type", Function),
663
+ __metadata("design:paramtypes", [String, Array, Object]),
664
+ __metadata("design:returntype", Promise)
665
+ ], OrderModuleService.prototype, "setShippingMethodTaxLines", null);
666
+ __decorate([
667
+ __param(1, (0, utils_1.MedusaContext)()),
668
+ __metadata("design:type", Function),
669
+ __metadata("design:paramtypes", [Object, Object]),
670
+ __metadata("design:returntype", Promise)
671
+ ], OrderModuleService.prototype, "removeShippingMethodTaxLines", null);
@@ -0,0 +1,7 @@
1
+ import { BigNumberInput } from "@medusajs/types";
2
+ export interface UpdateOrderShippingMethodDTO {
3
+ id: string;
4
+ name?: string;
5
+ amount?: BigNumberInput;
6
+ data?: Record<string, unknown>;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });