channelape-sdk
Version:
A client for interacting with ChannelApe's API
42 lines • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateDeduplicationKey = exports.BatchesService = void 0;
const channelape_logger_1 = require("channelape-logger");
const Version_1 = require("../../model/Version");
const Resource_1 = require("../../model/Resource");
const RestService_1 = require("../../service/RestService");
class BatchesService extends RestService_1.default {
constructor(client) {
super();
this.client = client;
this.logger = new channelape_logger_1.Logger('BatchService', channelape_logger_1.LogLevel.VERBOSE);
this.EXPECTED_POST_STATUS = 202;
this.EXPECTED_GET_STATUS = 200;
}
createInventoryAdjustmentBatch(batchCreationRequest) {
const requestUrl = `/${Version_1.default.V1}${Resource_1.default.BATCHES}`;
this.logger.info(`Attempting to create a batch with ${batchCreationRequest.adjustments.length} adjustments`);
const options = {
data: batchCreationRequest,
};
return new Promise((resolve, reject) => {
this.client.post(requestUrl, options, (error, response, body) => {
this.mapResponsePromise(resolve, reject, error, response, body, requestUrl, this.EXPECTED_POST_STATUS);
});
});
}
get(batchId) {
const requestUrl = `/${Version_1.default.V1}${Resource_1.default.BATCHES}/${batchId}`;
return new Promise((resolve, reject) => {
this.client.get(requestUrl, {}, (error, response, body) => {
this.mapResponsePromise(resolve, reject, error, response, body, requestUrl, this.EXPECTED_GET_STATUS);
});
});
}
}
exports.BatchesService = BatchesService;
function generateDeduplicationKey(status, locationId, deduplicationKey, sku, inventoryItemId) {
return inventoryItemId ? `${deduplicationKey}_${locationId}_${inventoryItemId}_${status}` : `${deduplicationKey}_${locationId}_${sku}_${status}`;
}
exports.generateDeduplicationKey = generateDeduplicationKey;
//# sourceMappingURL=BatchesService.js.map