|
@@ -301,7 +301,8 @@ router.get('/', async (req, res, next) => {
|
|
|
postCount: 'postCount'
|
|
|
};
|
|
|
let offset = Number.isInteger(+req.query.offset) ? +req.query.offset : 0;
|
|
|
- let havingClause;
|
|
|
+ let havingClause = '';
|
|
|
+
|
|
|
if(req.query.role === 'admin') {
|
|
|
havingClause = 'HAVING Users.admin = true';
|
|
|
} else if(req.query.role === 'user') {
|
|
@@ -310,6 +311,18 @@ router.get('/', async (req, res, next) => {
|
|
|
havingClause = '';
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ if(req.query.search) {
|
|
|
+ //I.e. if there is not already a HAVING clause
|
|
|
+ if(!havingClause.length) {
|
|
|
+ havingClause = 'HAVING ';
|
|
|
+ } else {
|
|
|
+ havingClause += ' AND ';
|
|
|
+ }
|
|
|
+
|
|
|
+ havingClause += 'Users.username LIKE $search';
|
|
|
+ }
|
|
|
+
|
|
|
let sql = `
|
|
|
SELECT X.username, X.admin, X.createdAt, X.postCount, COUNT(Threads.id) as threadCount
|
|
|
FROM (
|
|
@@ -329,7 +342,8 @@ router.get('/', async (req, res, next) => {
|
|
|
`;
|
|
|
|
|
|
let users = await sequelize.query(sql, {
|
|
|
- model: User
|
|
|
+ model: User,
|
|
|
+ bind: { search: req.query.search + '%' }
|
|
|
});
|
|
|
|
|
|
res.json(users)
|