题解功能

This commit is contained in:
masnn committed 2020-04-10 19:40:08 +08:00
1 parent ec727d58aa
commit 41261f8c4b
20 files changed
+825 -1277

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
const { ValidationError } = require('../error');
module.exports = async function paginate(cursor, page, page_size) {
if (page <= 0) throw new ValidationError('page');
let [count, page_docs] = await Promise.all([
cursor.count(),
cursor.skip((page - 1) * page_size).limit(page_size).toArray()
]);
let num_pages = Math.floor((count + page_size - 1) / page_size);
return [page_docs, num_pages, count];
};