UNPKG

@opra/common

Version:
59 lines (58 loc) 2.35 kB
"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"); /** * */ http_operation_js_1.HttpOperation.Entity.Create = 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: 'POST', ...args, composition: 'Entity.Create', requestBody: { immediateFetch: 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.CREATED, { description: 'Operation is successful. Returns OperationResult with "payload" field that contains the created resource.', contentType: index_js_1.MimeTypes.opra_response_json, type: args.type, partial: 'deep', }) .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); }); return decorator; };