@flexfactory/query
v3.1.0
Published
A query helper library for use within Hotelflex services
Downloads
29
Readme
query
Install
npm i --save @flexfactory/query
Usage
Applying a query filter
const { applyQueryFilters } = require('@flexfactory/query');
const query = ctx.request.query;
const builder = Store.Account.query();
/*
* Will apply known query filters along with any others in query
* -- (use ignoreQueryFields if you need to)
*/
applyQueryFilters(builder, query, ignoreQueryFields);
const rows = await builder;
Getting the validation schema for a query filter
const { getFilterSchema } = require('@flexfactory/query');
const schema = Joi.object().keys({
query: Joi.object().keys({
type: Joi.string(),
name: getFilterSchema(Joi), //defaults to type="string"
age: getFilterSchema(Joi, 'number'),
createdAt: getFilterSchema(Joi, 'date'),
select: getFilterSchema(Joi, 'select'),
orderBy: getFilterSchema(Joi, 'orderBy'),
}),
});