MCPcopy Create free account
hub / github.com/Muhammadsiddiq-code/backend-group-lessons / searchUser

Function searchUser

controller/userController.js:373–394  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

371
372// Search user
373const searchUser = async (req, res) => {
374 try {
375 const { query } = req.query;
376
377 if (!query || typeof query !== "string") {
378 return res.status(400).json({ message: "Invalid search query" });
379 }
380
381 const result = await User.find({
382 $or: [
383 { firstname: { $regex: query, $options: "i" } },
384 { lastname: { $regex: query, $options: "i" } },
385 { username: { $regex: query, $options: "i" } },
386 ],
387 });
388
389 res.status(200).json({ success: true, users: result });
390 } catch (error) {
391 console.error(error);
392 return res.status(500).json({ success: false, message: "Server Error" });
393 }
394};
395
396module.exports = {
397 CreateUser,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected