mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 02:16:03 +00:00
add count feature inside populate field of content-api
This commit is contained in:
parent
6fe8c51df2
commit
b5e2ddfc3b
@ -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;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user