mirror of
https://github.com/psforever/PSFPortal.git
synced 2026-01-19 18:14:45 +00:00
33 lines
608 B
JavaScript
33 lines
608 B
JavaScript
import * as db from './db.js'
|
|
|
|
export function get_pagination(req) {
|
|
let page = parseInt(req.query.page);
|
|
let order = req.query.order; // TODO
|
|
|
|
if (!page || page < 1) {
|
|
page = 1;
|
|
}
|
|
|
|
return {
|
|
page: page,
|
|
items_per_page: 40,
|
|
//order: order, // TODO
|
|
};
|
|
}
|
|
|
|
export async function fetch_user_middleware(req, res, next, id) {
|
|
try {
|
|
const account = await db.get_account_by_id(id);
|
|
|
|
if (!account) {
|
|
res.status(404).json({message: `account ${id} does not exist`});
|
|
} else {
|
|
req.user = account;
|
|
next();
|
|
}
|
|
} catch (e) {
|
|
console.log(e);
|
|
res.status(500).json({message: 'error'});
|
|
}
|
|
}
|