UNPKG

fsm-sdk

Version:

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

88 lines 4.38 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CompositeBulkAPI = void 0; const polyfills_1 = require("../../polyfills"); const request_options_factory_1 = require("../request-options.factory"); /** * Service for performing composite bulk operations on service calls. * Allows creating, updating, and managing multiple service calls in a single request. */ class CompositeBulkAPI { constructor(_config, _http, _auth) { this._config = _config; this._http = _http; this._auth = _auth; } /** * Constructs the API URL for composite bulk service call operations. * * @param {string} path - Optional path to append to the base URL. * @returns {string} The complete API URL. * @see https://api.sap.com/api/service_management_ext/resource/Service_API_V2 */ getApiUrl(path = '') { return `${this._config.baseUrl}/service-management/api/v2/composite-bulk/service-calls${path}`; } /** * Creates multiple service calls in a single bulk operation. * * @param {Partial<ServiceCall>[]} data - Array of service call objects to create. * @param {object} params - Optional query parameters. * @param {boolean} params.autoCreateActivity - Whether to automatically create activities for the service calls. * @returns {Promise<BulkResponse<ServiceCall>>} A promise resolving to the bulk operation results. */ postServiceCalls(data, params = {}) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`${(params ? `?${new polyfills_1.URLSearchParams(params)}` : '')}`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } /** * Updates multiple service calls in a single bulk operation. * * @param {Partial<ServiceCall>[]} data - Array of service call objects with updates. Each must include an id. * @returns {Promise<BulkResponse<ServiceCall>>} A promise resolving to the bulk operation results. */ patchServiceCalls(data) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(), { method: 'PATCH', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } /** * Marks multiple service calls as technically complete in a single bulk operation. * * @param {object} data - Request data. * @param {Partial<UnifiedIdentifier>[]} data.serviceCallIds - Array of service call identifiers to mark as technically complete. * @returns {Promise<BulkResponse<ServiceCall>>} A promise resolving to the bulk operation results. */ postServiceCallsTechnicallyComplete(data) { return __awaiter(this, void 0, void 0, function* () { const token = yield this._auth.ensureToken(this._config); return this._http.request(this.getApiUrl(`/technically-complete`), { method: 'POST', headers: request_options_factory_1.RequestOptionsFactory.getRequestHeaders(token, this._config), body: JSON.stringify(data) }); }); } } exports.CompositeBulkAPI = CompositeBulkAPI; //# sourceMappingURL=composite-bulk-api.service.js.map