@opra/common
Version:
Opra common package
86 lines (85 loc) • 3.64 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 index_js_3 = require("../data-type/primitive-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.FindMany
*/
http_operation_js_1.HttpOperation.Entity.FindMany = 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: 'GET',
...args,
composition: 'Entity.FindMany',
});
decorator
.Response(index_js_1.HttpStatusCode.OK, {
description: 'Operation is successful. Returns OperationResult with "payload" field that contains list of resources.',
contentType: index_js_1.MimeTypes.opra_response_json,
type: args.type,
partial: 'deep',
isArray: true,
})
.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,
})
.QueryParam('limit', {
description: 'Determines number of returning instances',
type: new index_js_3.IntegerType({ minValue: 1, maxValue: args.maxLimit }),
})
.QueryParam('skip', {
description: 'Determines number of returning instances',
type: new index_js_3.IntegerType({ minValue: 1 }),
})
.QueryParam('count', {
description: 'Counts all matching instances if enabled',
type: Boolean,
})
.QueryParam('projection', {
description: 'Determines fields projection',
type: new index_js_2.FieldPathType({
dataType: args.type,
allowSigns: 'each',
}),
isArray: true,
arraySeparator: ',',
});
decoratorChain.push((operationMeta) => {
const compositionOptions = (operationMeta.compositionOptions =
operationMeta.compositionOptions || {});
compositionOptions.type = (0, http_operation_entity_decorator_js_1.getDataTypeName)(args.type);
if (args.defaultLimit)
compositionOptions.defaultLimit = args.defaultLimit;
if (args.defaultProjection)
compositionOptions.defaultProjection = args.defaultProjection;
if (args.maxLimit)
compositionOptions.maxLimit = args.maxLimit;
});
decorator.Filter = (0, http_operation_entity_decorator_js_1.createFilterDecorator)(decorator, decoratorChain, args.type);
/**
*
*/
decorator.DefaultSort = (...fields) => {
decoratorChain.push((operationMeta) => {
const compositionOptions = (operationMeta.compositionOptions =
operationMeta.compositionOptions || {});
compositionOptions.defaultSort = fields;
});
return decorator;
};
decorator.SortFields = (0, http_operation_entity_decorator_js_1.createSortFieldsDecorator)(decorator, decoratorChain);
return decorator;
};