add count feature inside populate field of content-api

This commit is contained in:
Pierre Noël 2021-09-24 17:39:09 +02:00
parent 6fe8c51df2
commit b5e2ddfc3b

View File

@ -6,6 +6,7 @@
*/
const _ = require('lodash');
const parseType = require('./parse-type');
const QUERY_OPERATORS = ['_where', '_or', '_and'];
@ -29,6 +30,10 @@ const validateOrder = order => {
}
};
const convertCountQueryParams = countQuery => {
return parseType({ type: 'boolean', value: countQuery });
};
/**
* Sort query parser
* @param {string} sortQuery - ex: id:asc,price:desc
@ -161,7 +166,7 @@ const convertNestedPopulate = subPopulate => {
}
// TODO: We will need to consider a way to add limitation / pagination
const { sort, filters, fields, populate } = subPopulate;
const { sort, filters, fields, populate, count } = subPopulate;
const query = {};
@ -181,6 +186,10 @@ const convertNestedPopulate = subPopulate => {
query.populate = convertPopulateQueryParams(populate);
}
if (count) {
query.count = convertCountQueryParams(count);
}
return query;
};