mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 16:52:18 +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 _ = require('lodash');
|
||||||
|
const parseType = require('./parse-type');
|
||||||
|
|
||||||
const QUERY_OPERATORS = ['_where', '_or', '_and'];
|
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
|
* Sort query parser
|
||||||
* @param {string} sortQuery - ex: id:asc,price:desc
|
* @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
|
// 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 = {};
|
const query = {};
|
||||||
|
|
||||||
@ -181,6 +186,10 @@ const convertNestedPopulate = subPopulate => {
|
|||||||
query.populate = convertPopulateQueryParams(populate);
|
query.populate = convertPopulateQueryParams(populate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count) {
|
||||||
|
query.count = convertCountQueryParams(count);
|
||||||
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user