UNPKG

fsm-sdk

Version:

Node.JS sdk to interface with SAP Field Service Management APIs.

37 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BatchRequest = void 0; const request_options_factory_1 = require("../../request-options.factory"); class BatchRequest { constructor(_token, _config, _actions) { this._token = _token; this._config = _config; this._actions = _actions; } toString() { const body = this._actions.map((action, idx) => { let bodyPart = ''; bodyPart += '--======boundary======\n'; bodyPart += 'Content-Type: application/http\n'; bodyPart += 'Content-ID: req' + idx + '\n'; bodyPart += '\n'; bodyPart += [ action.method.toUpperCase(), ' ', request_options_factory_1.RequestOptionsFactory.getDataApiUriFor(this._config, action.dtoName, (action.method !== 'POST' ? action.dtoData.id : undefined)), '?', request_options_factory_1.RequestOptionsFactory.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ clientIdentifier: this._config.clientIdentifier }, request_options_factory_1.RequestOptionsFactory.getRequestAccountQueryParams(this._token, this._config)), (action.method !== 'DELETE' && { dtos: request_options_factory_1.RequestOptionsFactory.getDTOVersionsString([action.dtoName]) })), (action.force && action.method !== 'DELETE' && { forceUpdate: 'true' })), (action.force && action.method === 'DELETE' && { forceDelete: 'true' })), (action.method === 'DELETE' && !!action.dtoData && !!action.dtoData.lastChanged && { lastChanged: action.dtoData.lastChanged }))), ' ', 'HTTP/1.1\n' ].join(''); bodyPart += 'Content-Type: application/json\n'; bodyPart += '\n'; bodyPart += JSON.stringify(action.dtoData); bodyPart += '\n\n'; return bodyPart; }).join('\n'); return body; } } exports.BatchRequest = BatchRequest; //# sourceMappingURL=batch-request.model.js.map