From f51a5fb1e1e19f70268138a177ccc2cb748a03e4 Mon Sep 17 00:00:00 2001 From: kage1414 Date: Sat, 17 Aug 2024 14:38:14 -0400 Subject: [PATCH] feat: search from db (#3771) --- server/routes/user/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/routes/user/index.ts b/server/routes/user/index.ts index 94784df5..c58d0f1c 100644 --- a/server/routes/user/index.ts +++ b/server/routes/user/index.ts @@ -30,8 +30,18 @@ router.get('/', async (req, res, next) => { try { const pageSize = req.query.take ? Number(req.query.take) : 10; const skip = req.query.skip ? Number(req.query.skip) : 0; + const searchQuery = + req.query.searchQuery === 'null' || req.query.searchQuery === null + ? null + : req.query.searchQuery; let query = getRepository(User).createQueryBuilder('user'); + if (searchQuery) { + await query.where('user.email like :query OR user.username like :query', { + query: `%${searchQuery}%`, + }); + } + switch (req.query.sort) { case 'updated': query = query.orderBy('user.updatedAt', 'DESC');