Skip to content

Commit

Permalink
Total count for users
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsm412 committed Nov 15, 2024
1 parent af8a158 commit b65f945
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
22 changes: 18 additions & 4 deletions rair-node/bin/api/users/users.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,26 @@ exports.listUsers = async (req, res, next) => {
}
queriedFields[field] = 1;
});
const list = await User.find({}, queriedFields)
.skip(pageNum * itemsPerPage)
.limit(itemsPerPage);
const [result] = await User.aggregate([
{
$project: queriedFields,
},
{
$facet: {
list: [
{ $skip: pageNum * itemsPerPage },
{ $limit: itemsPerPage },
],
count: [
{ $count: 'total' },
],
},
},
]);
return res.json({
success: true,
data: list,
data: result.list,
totalCount: result?.count?.[0]?.total || 0,
});
} catch (err) {
return next(err);
Expand Down
1 change: 0 additions & 1 deletion rair-node/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async function main() {
},
});


const hls = await StartHLS();

const limiter = rateLimit({
Expand Down

0 comments on commit b65f945

Please sign in to comment.