@medusajs/inventory 1.0.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 (41) hide show
  1. package/dist/config.d.ts +1 -0
  2. package/dist/config.js +5 -0
  3. package/dist/config.js.map +1 -0
  4. package/dist/index.d.ts +7 -0
  5. package/dist/index.js +36 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/loaders/connection.d.ts +5 -0
  8. package/dist/loaders/connection.js +64 -0
  9. package/dist/loaders/connection.js.map +1 -0
  10. package/dist/migrations/schema-migrations/1665748086258-inventory_setup.d.ts +13 -0
  11. package/dist/migrations/schema-migrations/1665748086258-inventory_setup.js +131 -0
  12. package/dist/migrations/schema-migrations/1665748086258-inventory_setup.js.map +1 -0
  13. package/dist/models/index.d.ts +3 -0
  14. package/dist/models/index.js +20 -0
  15. package/dist/models/index.js.map +1 -0
  16. package/dist/models/inventory-item.d.ts +15 -0
  17. package/dist/models/inventory-item.js +95 -0
  18. package/dist/models/inventory-item.js.map +1 -0
  19. package/dist/models/inventory-level.d.ts +10 -0
  20. package/dist/models/inventory-level.js +77 -0
  21. package/dist/models/inventory-level.js.map +1 -0
  22. package/dist/models/reservation-item.d.ts +9 -0
  23. package/dist/models/reservation-item.js +73 -0
  24. package/dist/models/reservation-item.js.map +1 -0
  25. package/dist/services/index.d.ts +4 -0
  26. package/dist/services/index.js +15 -0
  27. package/dist/services/index.js.map +1 -0
  28. package/dist/services/inventory-item.d.ts +53 -0
  29. package/dist/services/inventory-item.js +289 -0
  30. package/dist/services/inventory-item.js.map +1 -0
  31. package/dist/services/inventory-level.d.ts +89 -0
  32. package/dist/services/inventory-level.js +411 -0
  33. package/dist/services/inventory-level.js.map +1 -0
  34. package/dist/services/inventory.d.ts +150 -0
  35. package/dist/services/inventory.js +496 -0
  36. package/dist/services/inventory.js.map +1 -0
  37. package/dist/services/reservation-item.d.ts +68 -0
  38. package/dist/services/reservation-item.js +385 -0
  39. package/dist/services/reservation-item.js.map +1 -0
  40. package/jest.config.js +13 -0
  41. package/package.json +37 -0
@@ -0,0 +1,496 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __read = (this && this.__read) || function (o, n) {
50
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
51
+ if (!m) return o;
52
+ var i = m.call(o), r, ar = [], e;
53
+ try {
54
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
+ }
56
+ catch (error) { e = { error: error }; }
57
+ finally {
58
+ try {
59
+ if (r && !r.done && (m = i["return"])) m.call(i);
60
+ }
61
+ finally { if (e) throw e.error; }
62
+ }
63
+ return ar;
64
+ };
65
+ Object.defineProperty(exports, "__esModule", { value: true });
66
+ var medusa_core_utils_1 = require("medusa-core-utils");
67
+ var _1 = require("./");
68
+ var InventoryService = /** @class */ (function () {
69
+ function InventoryService(_a) {
70
+ var eventBusService = _a.eventBusService;
71
+ this.eventBusService_ = eventBusService;
72
+ this.inventoryItemService_ = new _1.InventoryItemService({ eventBusService: eventBusService });
73
+ this.inventoryLevelService_ = new _1.InventoryLevelService({
74
+ eventBusService: eventBusService,
75
+ });
76
+ this.reservationItemService_ = new _1.ReservationItemService({
77
+ eventBusService: eventBusService,
78
+ inventoryLevelService: this.inventoryLevelService_,
79
+ });
80
+ }
81
+ /**
82
+ * Lists inventory items that match the given selector
83
+ * @param selector - the selector to filter inventory items by
84
+ * @param config - the find configuration to use
85
+ * @return A tuple of inventory items and their total count
86
+ */
87
+ InventoryService.prototype.listInventoryItems = function (selector, config) {
88
+ if (config === void 0) { config = { relations: [], skip: 0, take: 10 }; }
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ return __generator(this, function (_a) {
91
+ switch (_a.label) {
92
+ case 0: return [4 /*yield*/, this.inventoryItemService_.listAndCount(selector, config)];
93
+ case 1: return [2 /*return*/, _a.sent()];
94
+ }
95
+ });
96
+ });
97
+ };
98
+ /**
99
+ * Lists inventory levels that match the given selector
100
+ * @param selector - the selector to filter inventory levels by
101
+ * @param config - the find configuration to use
102
+ * @return A tuple of inventory levels and their total count
103
+ */
104
+ InventoryService.prototype.listInventoryLevels = function (selector, config) {
105
+ if (config === void 0) { config = { relations: [], skip: 0, take: 10 }; }
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0: return [4 /*yield*/, this.inventoryLevelService_.listAndCount(selector, config)];
110
+ case 1: return [2 /*return*/, _a.sent()];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ /**
116
+ * Lists reservation items that match the given selector
117
+ * @param selector - the selector to filter reservation items by
118
+ * @param config - the find configuration to use
119
+ * @return A tuple of reservation items and their total count
120
+ */
121
+ InventoryService.prototype.listReservationItems = function (selector, config) {
122
+ if (config === void 0) { config = {
123
+ relations: [],
124
+ skip: 0,
125
+ take: 10,
126
+ }; }
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ return __generator(this, function (_a) {
129
+ switch (_a.label) {
130
+ case 0: return [4 /*yield*/, this.reservationItemService_.listAndCount(selector, config)];
131
+ case 1: return [2 /*return*/, _a.sent()];
132
+ }
133
+ });
134
+ });
135
+ };
136
+ /**
137
+ * Retrieves an inventory item with the given id
138
+ * @param inventoryItemId - the id of the inventory item to retrieve
139
+ * @param config - the find configuration to use
140
+ * @return The retrieved inventory item
141
+ */
142
+ InventoryService.prototype.retrieveInventoryItem = function (inventoryItemId, config) {
143
+ return __awaiter(this, void 0, void 0, function () {
144
+ var inventoryItem;
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0: return [4 /*yield*/, this.inventoryItemService_.retrieve(inventoryItemId, config)];
148
+ case 1:
149
+ inventoryItem = _a.sent();
150
+ return [2 /*return*/, __assign({}, inventoryItem)];
151
+ }
152
+ });
153
+ });
154
+ };
155
+ /**
156
+ * Retrieves an inventory level for a given inventory item and location
157
+ * @param inventoryItemId - the id of the inventory item
158
+ * @param locationId - the id of the location
159
+ * @return the retrieved inventory level
160
+ */
161
+ InventoryService.prototype.retrieveInventoryLevel = function (inventoryItemId, locationId) {
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ var _a, inventoryLevel;
164
+ return __generator(this, function (_b) {
165
+ switch (_b.label) {
166
+ case 0: return [4 /*yield*/, this.inventoryLevelService_.list({ inventory_item_id: inventoryItemId, location_id: locationId }, { take: 1 })];
167
+ case 1:
168
+ _a = __read.apply(void 0, [_b.sent(), 1]), inventoryLevel = _a[0];
169
+ if (!inventoryLevel) {
170
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Inventory level for item ".concat(inventoryItemId, " and location ").concat(locationId, " not found"));
171
+ }
172
+ return [2 /*return*/, inventoryLevel];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ /**
178
+ * Creates a reservation item
179
+ * @param input - the input object
180
+ * @return The created reservation item
181
+ */
182
+ InventoryService.prototype.createReservationItem = function (input) {
183
+ return __awaiter(this, void 0, void 0, function () {
184
+ var _a, inventoryLevel, reservationItem;
185
+ return __generator(this, function (_b) {
186
+ switch (_b.label) {
187
+ case 0: return [4 /*yield*/, this.inventoryLevelService_.list({
188
+ inventory_item_id: input.inventory_item_id,
189
+ location_id: input.location_id,
190
+ }, { take: 1 })];
191
+ case 1:
192
+ _a = __read.apply(void 0, [_b.sent(), 1]), inventoryLevel = _a[0];
193
+ if (!inventoryLevel) {
194
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Item ".concat(input.inventory_item_id, " is not stocked at location ").concat(input.location_id));
195
+ }
196
+ return [4 /*yield*/, this.reservationItemService_.create(input)];
197
+ case 2:
198
+ reservationItem = _b.sent();
199
+ return [2 /*return*/, __assign({}, reservationItem)];
200
+ }
201
+ });
202
+ });
203
+ };
204
+ /**
205
+ * Creates an inventory item
206
+ * @param input - the input object
207
+ * @return The created inventory item
208
+ */
209
+ InventoryService.prototype.createInventoryItem = function (input) {
210
+ return __awaiter(this, void 0, void 0, function () {
211
+ var inventoryItem;
212
+ return __generator(this, function (_a) {
213
+ switch (_a.label) {
214
+ case 0: return [4 /*yield*/, this.inventoryItemService_.create(input)];
215
+ case 1:
216
+ inventoryItem = _a.sent();
217
+ return [2 /*return*/, __assign({}, inventoryItem)];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ /**
223
+ * Creates an inventory item
224
+ * @param input - the input object
225
+ * @return The created inventory level
226
+ */
227
+ InventoryService.prototype.createInventoryLevel = function (input) {
228
+ return __awaiter(this, void 0, void 0, function () {
229
+ return __generator(this, function (_a) {
230
+ switch (_a.label) {
231
+ case 0: return [4 /*yield*/, this.inventoryLevelService_.create(input)];
232
+ case 1: return [2 /*return*/, _a.sent()];
233
+ }
234
+ });
235
+ });
236
+ };
237
+ /**
238
+ * Updates an inventory item
239
+ * @param inventoryItemId - the id of the inventory item to update
240
+ * @param input - the input object
241
+ * @return The updated inventory item
242
+ */
243
+ InventoryService.prototype.updateInventoryItem = function (inventoryItemId, input) {
244
+ return __awaiter(this, void 0, void 0, function () {
245
+ var inventoryItem;
246
+ return __generator(this, function (_a) {
247
+ switch (_a.label) {
248
+ case 0: return [4 /*yield*/, this.inventoryItemService_.update(inventoryItemId, input)];
249
+ case 1:
250
+ inventoryItem = _a.sent();
251
+ return [2 /*return*/, __assign({}, inventoryItem)];
252
+ }
253
+ });
254
+ });
255
+ };
256
+ /**
257
+ * Deletes an inventory item
258
+ * @param inventoryItemId - the id of the inventory item to delete
259
+ */
260
+ InventoryService.prototype.deleteInventoryItem = function (inventoryItemId) {
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ return __generator(this, function (_a) {
263
+ switch (_a.label) {
264
+ case 0: return [4 /*yield*/, this.inventoryItemService_.delete(inventoryItemId)];
265
+ case 1: return [2 /*return*/, _a.sent()];
266
+ }
267
+ });
268
+ });
269
+ };
270
+ /**
271
+ * Deletes an inventory level
272
+ * @param inventoryItemId - the id of the inventory item associated with the level
273
+ * @param locationId - the id of the location associated with the level
274
+ */
275
+ InventoryService.prototype.deleteInventoryLevel = function (inventoryItemId, locationId) {
276
+ return __awaiter(this, void 0, void 0, function () {
277
+ var _a, inventoryLevel;
278
+ return __generator(this, function (_b) {
279
+ switch (_b.label) {
280
+ case 0: return [4 /*yield*/, this.inventoryLevelService_.list({ inventory_item_id: inventoryItemId, location_id: locationId }, { take: 1 })];
281
+ case 1:
282
+ _a = __read.apply(void 0, [_b.sent(), 1]), inventoryLevel = _a[0];
283
+ if (!inventoryLevel) {
284
+ return [2 /*return*/];
285
+ }
286
+ return [4 /*yield*/, this.inventoryLevelService_.delete(inventoryLevel.id)];
287
+ case 2: return [2 /*return*/, _b.sent()];
288
+ }
289
+ });
290
+ });
291
+ };
292
+ /**
293
+ * Updates an inventory level
294
+ * @param inventoryItemId - the id of the inventory item associated with the level
295
+ * @param locationId - the id of the location associated with the level
296
+ * @param input - the input object
297
+ * @return The updated inventory level
298
+ */
299
+ InventoryService.prototype.updateInventoryLevel = function (inventoryItemId, locationId, input) {
300
+ return __awaiter(this, void 0, void 0, function () {
301
+ var _a, inventoryLevel;
302
+ return __generator(this, function (_b) {
303
+ switch (_b.label) {
304
+ case 0: return [4 /*yield*/, this.inventoryLevelService_.list({ inventory_item_id: inventoryItemId, location_id: locationId }, { take: 1 })];
305
+ case 1:
306
+ _a = __read.apply(void 0, [_b.sent(), 1]), inventoryLevel = _a[0];
307
+ if (!inventoryLevel) {
308
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Inventory level for item ".concat(inventoryItemId, " and location ").concat(locationId, " not found"));
309
+ }
310
+ return [4 /*yield*/, this.inventoryLevelService_.update(inventoryLevel.id, input)];
311
+ case 2: return [2 /*return*/, _b.sent()];
312
+ }
313
+ });
314
+ });
315
+ };
316
+ /**
317
+ * Updates a reservation item
318
+ * @param inventoryItemId - the id of the inventory item associated with the level
319
+ * @param input - the input object
320
+ * @return The updated inventory level
321
+ */
322
+ InventoryService.prototype.updateReservationItem = function (reservationItemId, input) {
323
+ return __awaiter(this, void 0, void 0, function () {
324
+ return __generator(this, function (_a) {
325
+ switch (_a.label) {
326
+ case 0: return [4 /*yield*/, this.reservationItemService_.update(reservationItemId, input)];
327
+ case 1: return [2 /*return*/, _a.sent()];
328
+ }
329
+ });
330
+ });
331
+ };
332
+ /**
333
+ * Deletes reservation items by line item
334
+ * @param lineItemId - the id of the line item associated with the reservation item
335
+ */
336
+ InventoryService.prototype.deleteReservationItemsByLineItem = function (lineItemId) {
337
+ return __awaiter(this, void 0, void 0, function () {
338
+ return __generator(this, function (_a) {
339
+ switch (_a.label) {
340
+ case 0: return [4 /*yield*/, this.reservationItemService_.deleteByLineItem(lineItemId)];
341
+ case 1: return [2 /*return*/, _a.sent()];
342
+ }
343
+ });
344
+ });
345
+ };
346
+ /**
347
+ * Deletes a reservation item
348
+ * @param reservationItemId - the id of the reservation item to delete
349
+ */
350
+ InventoryService.prototype.deleteReservationItem = function (reservationItemId) {
351
+ return __awaiter(this, void 0, void 0, function () {
352
+ return __generator(this, function (_a) {
353
+ switch (_a.label) {
354
+ case 0: return [4 /*yield*/, this.reservationItemService_.delete(reservationItemId)];
355
+ case 1: return [2 /*return*/, _a.sent()];
356
+ }
357
+ });
358
+ });
359
+ };
360
+ /**
361
+ * Adjusts the inventory level for a given inventory item and location.
362
+ * @param inventoryItemId - the id of the inventory item
363
+ * @param locationId - the id of the location
364
+ * @param adjustment - the number to adjust the inventory by (can be positive or negative)
365
+ * @return The updated inventory level
366
+ * @throws when the inventory level is not found
367
+ */
368
+ InventoryService.prototype.adjustInventory = function (inventoryItemId, locationId, adjustment) {
369
+ return __awaiter(this, void 0, void 0, function () {
370
+ var _a, inventoryLevel, updatedInventoryLevel;
371
+ return __generator(this, function (_b) {
372
+ switch (_b.label) {
373
+ case 0: return [4 /*yield*/, this.inventoryLevelService_.list({ inventory_item_id: inventoryItemId, location_id: locationId }, { take: 1 })];
374
+ case 1:
375
+ _a = __read.apply(void 0, [_b.sent(), 1]), inventoryLevel = _a[0];
376
+ if (!inventoryLevel) {
377
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Inventory level for inventory item ".concat(inventoryItemId, " and location ").concat(locationId, " not found"));
378
+ }
379
+ return [4 /*yield*/, this.inventoryLevelService_.update(inventoryLevel.id, {
380
+ stocked_quantity: inventoryLevel.stocked_quantity + adjustment,
381
+ })];
382
+ case 2:
383
+ updatedInventoryLevel = _b.sent();
384
+ return [2 /*return*/, __assign({}, updatedInventoryLevel)];
385
+ }
386
+ });
387
+ });
388
+ };
389
+ /**
390
+ * Retrieves the available quantity of a given inventory item in a given location.
391
+ * @param inventoryItemId - the id of the inventory item
392
+ * @param locationIds - the ids of the locations to check
393
+ * @return The available quantity
394
+ * @throws when the inventory item is not found
395
+ */
396
+ InventoryService.prototype.retrieveAvailableQuantity = function (inventoryItemId, locationIds) {
397
+ return __awaiter(this, void 0, void 0, function () {
398
+ var availableQuantity;
399
+ return __generator(this, function (_a) {
400
+ switch (_a.label) {
401
+ case 0:
402
+ // Throws if item does not exist
403
+ return [4 /*yield*/, this.inventoryItemService_.retrieve(inventoryItemId, {
404
+ select: ["id"],
405
+ })];
406
+ case 1:
407
+ // Throws if item does not exist
408
+ _a.sent();
409
+ return [4 /*yield*/, this.inventoryLevelService_.getAvailableQuantity(inventoryItemId, locationIds)];
410
+ case 2:
411
+ availableQuantity = _a.sent();
412
+ return [2 /*return*/, availableQuantity];
413
+ }
414
+ });
415
+ });
416
+ };
417
+ /**
418
+ * Retrieves the stocked quantity of a given inventory item in a given location.
419
+ * @param inventoryItemId - the id of the inventory item
420
+ * @param locationIds - the ids of the locations to check
421
+ * @return The stocked quantity
422
+ * @throws when the inventory item is not found
423
+ */
424
+ InventoryService.prototype.retrieveStockedQuantity = function (inventoryItemId, locationIds) {
425
+ return __awaiter(this, void 0, void 0, function () {
426
+ var stockedQuantity;
427
+ return __generator(this, function (_a) {
428
+ switch (_a.label) {
429
+ case 0:
430
+ // Throws if item does not exist
431
+ return [4 /*yield*/, this.inventoryItemService_.retrieve(inventoryItemId, {
432
+ select: ["id"],
433
+ })];
434
+ case 1:
435
+ // Throws if item does not exist
436
+ _a.sent();
437
+ return [4 /*yield*/, this.inventoryLevelService_.getStockedQuantity(inventoryItemId, locationIds)];
438
+ case 2:
439
+ stockedQuantity = _a.sent();
440
+ return [2 /*return*/, stockedQuantity];
441
+ }
442
+ });
443
+ });
444
+ };
445
+ /**
446
+ * Retrieves the reserved quantity of a given inventory item in a given location.
447
+ * @param inventoryItemId - the id of the inventory item
448
+ * @param locationIds - the ids of the locations to check
449
+ * @return The reserved quantity
450
+ * @throws when the inventory item is not found
451
+ */
452
+ InventoryService.prototype.retrieveReservedQuantity = function (inventoryItemId, locationIds) {
453
+ return __awaiter(this, void 0, void 0, function () {
454
+ var reservedQuantity;
455
+ return __generator(this, function (_a) {
456
+ switch (_a.label) {
457
+ case 0:
458
+ // Throws if item does not exist
459
+ return [4 /*yield*/, this.inventoryItemService_.retrieve(inventoryItemId, {
460
+ select: ["id"],
461
+ })];
462
+ case 1:
463
+ // Throws if item does not exist
464
+ _a.sent();
465
+ return [4 /*yield*/, this.inventoryLevelService_.getReservedQuantity(inventoryItemId, locationIds)];
466
+ case 2:
467
+ reservedQuantity = _a.sent();
468
+ return [2 /*return*/, reservedQuantity];
469
+ }
470
+ });
471
+ });
472
+ };
473
+ /**
474
+ * Confirms whether there is sufficient inventory for a given quantity of a given inventory item in a given location.
475
+ * @param inventoryItemId - the id of the inventory item
476
+ * @param locationIds - the ids of the locations to check
477
+ * @param quantity - the quantity to check
478
+ * @return Whether there is sufficient inventory
479
+ */
480
+ InventoryService.prototype.confirmInventory = function (inventoryItemId, locationIds, quantity) {
481
+ return __awaiter(this, void 0, void 0, function () {
482
+ var availableQuantity;
483
+ return __generator(this, function (_a) {
484
+ switch (_a.label) {
485
+ case 0: return [4 /*yield*/, this.retrieveAvailableQuantity(inventoryItemId, locationIds)];
486
+ case 1:
487
+ availableQuantity = _a.sent();
488
+ return [2 /*return*/, availableQuantity >= quantity];
489
+ }
490
+ });
491
+ });
492
+ };
493
+ return InventoryService;
494
+ }());
495
+ exports.default = InventoryService;
496
+ //# sourceMappingURL=inventory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inventory.js","sourceRoot":"","sources":["../../src/services/inventory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAkB/C,uBAIW;AAMX;IAME,0BAAY,EAAyC;YAAvC,eAAe,qBAAA;QAC3B,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAA;QAEvC,IAAI,CAAC,qBAAqB,GAAG,IAAI,uBAAoB,CAAC,EAAE,eAAe,iBAAA,EAAE,CAAC,CAAA;QAC1E,IAAI,CAAC,sBAAsB,GAAG,IAAI,wBAAqB,CAAC;YACtD,eAAe,iBAAA;SAChB,CAAC,CAAA;QACF,IAAI,CAAC,uBAAuB,GAAG,IAAI,yBAAsB,CAAC;YACxD,eAAe,iBAAA;YACf,qBAAqB,EAAE,IAAI,CAAC,sBAAsB;SACnD,CAAC,CAAA;IACJ,CAAC;IAED;;;;;OAKG;IACG,6CAAkB,GAAxB,UACE,QAAsC,EACtC,MAA2E;QAA3E,uBAAA,EAAA,WAAyC,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAA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;IACG,2CAAgB,GAAtB,UACE,eAAuB,EACvB,WAAqB,EACrB,QAAgB;;;;;4BAEU,qBAAM,IAAI,CAAC,yBAAyB,CAC5D,eAAe,EACf,WAAW,CACZ,EAAA;;wBAHK,iBAAiB,GAAG,SAGzB;wBACD,sBAAO,iBAAiB,IAAI,QAAQ,EAAA;;;;KACrC;IACH,uBAAC;AAAD,CAAC,AA/XD,IA+XC"}
@@ -0,0 +1,68 @@
1
+ import { EntityManager } from "typeorm";
2
+ import { FindConfig, IEventBusService, FilterableReservationItemProps, CreateReservationItemInput, TransactionBaseService, UpdateReservationItemInput } from "@medusajs/medusa";
3
+ import { ReservationItem } from "../models";
4
+ import { InventoryLevelService } from ".";
5
+ declare type InjectedDependencies = {
6
+ eventBusService: IEventBusService;
7
+ inventoryLevelService: InventoryLevelService;
8
+ };
9
+ export default class ReservationItemService extends TransactionBaseService {
10
+ static Events: {
11
+ CREATED: string;
12
+ UPDATED: string;
13
+ DELETED: string;
14
+ DELETED_BY_LINE_ITEM: string;
15
+ };
16
+ protected manager_: EntityManager;
17
+ protected transactionManager_: EntityManager | undefined;
18
+ protected readonly eventBusService_: IEventBusService;
19
+ protected readonly inventoryLevelService_: InventoryLevelService;
20
+ constructor({ eventBusService, inventoryLevelService, }: InjectedDependencies);
21
+ private getManager;
22
+ /**
23
+ * Lists reservation items that match the provided filter.
24
+ * @param selector - Filters to apply to the reservation items.
25
+ * @param config - Configuration for the query.
26
+ * @return Array of reservation items that match the selector.
27
+ */
28
+ list(selector?: FilterableReservationItemProps, config?: FindConfig<ReservationItem>): Promise<ReservationItem[]>;
29
+ /**
30
+ * Lists reservation items that match the provided filter and returns the total count.
31
+ * @param selector - Filters to apply to the reservation items.
32
+ * @param config - Configuration for the query.
33
+ * @return Array of reservation items that match the selector and the total count.
34
+ */
35
+ listAndCount(selector?: FilterableReservationItemProps, config?: FindConfig<ReservationItem>): Promise<[ReservationItem[], number]>;
36
+ /**
37
+ * Retrieves a reservation item by its id.
38
+ * @param reservationItemId - The id of the reservation item to retrieve.
39
+ * @param config - Configuration for the query.
40
+ * @return The reservation item with the provided id.
41
+ * @throws If reservationItemId is not defined or if the reservation item was not found.
42
+ */
43
+ retrieve(reservationItemId: string, config?: FindConfig<ReservationItem>): Promise<ReservationItem>;
44
+ /**
45
+ * Create a new reservation item.
46
+ * @param data - The reservation item data.
47
+ * @return The created reservation item.
48
+ */
49
+ create(data: CreateReservationItemInput): Promise<ReservationItem>;
50
+ /**
51
+ * Update a reservation item.
52
+ * @param reservationItemId - The reservation item's id.
53
+ * @param data - The reservation item data to update.
54
+ * @return The updated reservation item.
55
+ */
56
+ update(reservationItemId: string, data: UpdateReservationItemInput): Promise<ReservationItem>;
57
+ /**
58
+ * Deletes a reservation item by line item id.
59
+ * @param lineItemId - the id of the line item to delete.
60
+ */
61
+ deleteByLineItem(lineItemId: string): Promise<void>;
62
+ /**
63
+ * Deletes a reservation item by id.
64
+ * @param reservationItemId - the id of the reservation item to delete.
65
+ */
66
+ delete(reservationItemId: string): Promise<void>;
67
+ }
68
+ export {};