fix: pagination error in roles collections resourcer

This commit is contained in:
Chareice 2024-03-12 15:14:59 +08:00
parent de6e8469d3
commit 023096b1a9
No known key found for this signature in database

View File

@ -22,7 +22,7 @@ const rolesRemoteCollectionsResourcer = {
const collectionRepository = new FullDataRepository<any>(dataSource.collectionManager.getCollections()); const collectionRepository = new FullDataRepository<any>(dataSource.collectionManager.getCollections());
// all collections // all collections
const [collections, count] = await collectionRepository.findAndCount(); const [collections] = await collectionRepository.findAndCount();
const filterItem = lodash.get(filter, '$and'); const filterItem = lodash.get(filter, '$and');
const filterByTitle = filterItem?.find((item) => item.title); const filterByTitle = filterItem?.find((item) => item.title);
@ -45,15 +45,15 @@ const rolesRemoteCollectionsResourcer = {
.filter((roleResources) => roleResources.get('usingActionsConfig')) .filter((roleResources) => roleResources.get('usingActionsConfig'))
.map((roleResources) => roleResources.get('name')); .map((roleResources) => roleResources.get('name'));
const items = lodash.sortBy( const filtedCollections = collections.filter((collection) => {
collections
.filter((collection) => {
return ( return (
(!filterTitle || lodash.get(collection, 'options.title')?.toLowerCase().includes(filterTitle)) && (!filterTitle || lodash.get(collection, 'options.title')?.toLowerCase().includes(filterTitle)) &&
(!filterName || collection.options.name.toLowerCase().includes(filterName)) (!filterName || collection.options.name.toLowerCase().includes(filterName))
); );
}) });
.map((collection, i) => {
const items = lodash.sortBy(
filtedCollections.map((collection, i) => {
const collectionName = collection.options.name; const collectionName = collection.options.name;
const exists = roleResourcesNames.includes(collectionName); const exists = roleResourcesNames.includes(collectionName);
@ -78,11 +78,11 @@ const rolesRemoteCollectionsResourcer = {
); );
ctx.body = { ctx.body = {
count, count: filtedCollections.length,
rows: items, rows: items,
page: Number(page), page: Number(page),
pageSize: Number(pageSize), pageSize: Number(pageSize),
totalPage: totalPage(count, pageSize), totalPage: totalPage(filtedCollections.length, pageSize),
}; };
await next(); await next();