UNPKG

@sap-cloud-sdk/odata-v4

Version:

SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.

48 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdateRequestBuilder = void 0; const util_1 = require("@sap-cloud-sdk/util"); const internal_1 = require("@sap-cloud-sdk/odata-common/internal"); const extract_odata_etag_1 = require("../extract-odata-etag"); const uri_conversion_1 = require("../uri-conversion"); /** * Create OData query to update an entity. * @typeParam EntityT - Type of the entity to be updated. */ class UpdateRequestBuilder extends internal_1.UpdateRequestBuilderBase { /** * Creates an instance of UpdateRequestBuilder. * @param entityApi - Entity API for building and executing the request. * @param _entity - Entity to be updated. */ constructor(entityApi, _entity) { super(entityApi, _entity, (0, uri_conversion_1.createODataUri)(entityApi.deSerializers), (0, internal_1.entitySerializer)(entityApi.deSerializers), extract_odata_etag_1.extractODataEtag, util_1.identity); this._entity = _entity; } /** * Executes the query. * @param destination - Destination or DestinationFetchOptions to execute the request against. * @returns A promise resolving to the entity once it was updated. */ async execute(destination) { if (this.isEmptyObject(this.requestConfig.payload)) { return this._entity; } const request = await this.build(destination); return super.executeRequest(request); } /** * Execute request and return an {@link @sap-cloud-sdk/http-client!HttpResponse}. * @param destination - Destination or DestinationFetchOptions to execute the request against. * @returns A promise resolving to an {@link @sap-cloud-sdk/http-client!HttpResponse}. */ async executeRaw(destination) { if (this.isEmptyObject(this.requestConfig.payload)) { throw new Error('Cannot execute an update request with empty payload.'); } const request = await this.build(destination); return super.executeRequestRaw(request); } } exports.UpdateRequestBuilder = UpdateRequestBuilder; //# sourceMappingURL=update-request-builder.js.map