contensis-core-api
Version:
A dependency library used by contensis-delivery-api and contensis-management-api
37 lines (36 loc) • 1.2 kB
JavaScript
import { WhereExpression } from './Operators';
import { serializeOrder } from './QueryTypes';
export class Query {
where = new WhereExpression();
orderBy = [];
pageIndex = 0;
pageSize = 20;
fieldLinkDepths = {};
fields = [];
aggregations = {};
constructor(...whereExpressions) {
if (whereExpressions) {
this.where.addRange(whereExpressions);
}
}
toJSON() {
const result = {};
result.pageIndex = this.pageIndex;
result.pageSize = this.pageSize;
const orderByDtos = serializeOrder(this.orderBy);
if (orderByDtos && orderByDtos.length > 0) {
result.orderBy = orderByDtos;
}
result.where = this.where;
if (this.fields && this.fields.length > 0) {
result.fields = this.fields;
}
if (this.fieldLinkDepths && Object.keys(this.fieldLinkDepths).length > 0) {
result.fieldLinkDepths = this.fieldLinkDepths;
}
if (this.aggregations && Object.keys(this.aggregations).length > 0) {
result.aggregations = this.aggregations;
}
return result;
}
}