fsm-sdk
Version:
Node.JS sdk to interface with SAP Field Service Management APIs.
36 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const request_options_facory_1 = require("./request-options.facory");
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_facory_1.RequestOptionsFacory.getDataApiUriFor(this._token, action.dtoName, (action.method !== 'POST' ? action.dtoData.id : undefined)),
'?',
request_options_facory_1.RequestOptionsFacory.stringify(Object.assign({ clientIdentifier: this._config.clientIdentifier }, request_options_facory_1.RequestOptionsFacory.getRequestAccountQueryParams(this._token, this._config), (action.method !== 'DELETE' && { dtos: request_options_facory_1.RequestOptionsFacory.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