Skip to content

Commit

Permalink
feat: search from db (sct#3771)
Browse files Browse the repository at this point in the history
  • Loading branch information
kage1414 committed Aug 17, 2024
1 parent 52e8a2c commit f51a5fb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/routes/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit f51a5fb

Please sign in to comment.