mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
* add-generics-to-query-type: adding generics for query type in express core * add-generics-to-query-type: fixing test case + lint * add-generics-to-query-type: updating the default query type for express * add-generics-to-query-type: fixing failed test cases * add-generics-to-query-type: fixing express-paginate-tests Co-authored-by: Puneet Arora <parora@atlassian.com>
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import express from 'express';
|
|
import * as paginate from 'express-paginate';
|
|
|
|
declare function findAndCountAll(params: object): Promise<{count: number, rows: object[]}>;
|
|
|
|
const app = express();
|
|
|
|
app.use(paginate.middleware(10, 50));
|
|
|
|
app.get('/users', async (req, res, next) => {
|
|
// req.skip should be available
|
|
return findAndCountAll({limit: req.query.limit, offset: req.skip})
|
|
.then(results => {
|
|
const itemCount = results.count;
|
|
const pageCount = Math.ceil(results.count / parseInt(req.query.limit as string, 10));
|
|
res.render('users/all_users', {
|
|
users: results.rows,
|
|
pageCount,
|
|
itemCount,
|
|
currentPageHref: paginate.href(req)(false, req.params),
|
|
// Instead of exposing this to the html template, we'll test this here and pass a static number
|
|
hasNextPages: paginate.hasNextPages(req)(pageCount),
|
|
pages: paginate.getArrayPages(req)(3, pageCount, parseInt(req.query.page as string, 10))
|
|
});
|
|
}).catch(next);
|
|
});
|