@opra/common
Version:
Opra common package
67 lines (66 loc) • 2.85 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_js_1 = require("../../enums/index.js");
const constants_js_1 = require("../constants.js");
const index_js_2 = require("../data-type/extended-types/index.js");
const http_operation_js_1 = require("../http/http-operation.js");
const http_operation_decorator_js_1 = require("./http-operation.decorator.js");
const http_operation_entity_decorator_js_1 = require("./http-operation-entity.decorator.js");
/**
* HttpOperation.Entity.Update
*/
http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
let args;
if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
args = arg0;
}
else
args = { ...arg1, type: arg0 };
/** Initialize the decorator and the chain */
const decoratorChain = [];
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
method: 'PATCH',
...args,
composition: 'Entity.Update',
requestBody: {
partial: 'deep',
immediateFetch: true,
allowPatchOperators: true,
keepKeyFields: true,
...args.requestBody,
required: true,
},
});
decorator
.QueryParam('projection', {
description: 'Determines fields projection',
type: new index_js_2.FieldPathType({
dataType: args.type,
allowSigns: 'each',
}),
isArray: true,
arraySeparator: ',',
})
.RequestContent(args.requestBody?.type || args.type)
.Response(index_js_1.HttpStatusCode.OK, {
description: 'Operation is successful. Returns OperationResult with "payload" field that contains updated resource.',
contentType: index_js_1.MimeTypes.opra_response_json,
type: args.type,
partial: 'deep',
})
.Response(index_js_1.HttpStatusCode.NO_CONTENT, {
description: 'Operation is successful but no resource found',
})
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
contentType: index_js_1.MimeTypes.opra_response_json,
});
decoratorChain.push((operationMeta) => {
const compositionOptions = (operationMeta.compositionOptions =
operationMeta.compositionOptions || {});
compositionOptions.type = (0, http_operation_entity_decorator_js_1.getDataTypeName)(args.type);
});
decorator.KeyParam = (0, http_operation_entity_decorator_js_1.createKeyParamDecorator)(decorator, decoratorChain);
decorator.Filter = (0, http_operation_entity_decorator_js_1.createFilterDecorator)(decorator, decoratorChain, args.type);
return decorator;
};