@unito/integration-sdk
Version:
Integration SDK
32 lines (26 loc) • 758 B
text/typescript
import { Request, Response, NextFunction } from 'express';
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Express {
interface Locals {
// When the query params contains...
//
// select=name,department.name
//
// ... it becomes available as follow in handlers:
//
// ['name', 'department.name']
selects: string[];
}
}
}
function extractSelects(req: Request, res: Response, next: NextFunction) {
const rawSelect = req.query.select;
if (typeof rawSelect === 'string') {
res.locals.selects = rawSelect.split(',').map(select => decodeURIComponent(select));
} else {
res.locals.selects = [];
}
next();
}
export default extractSelects;