Skip to content

Commit

Permalink
fixed user
Browse files Browse the repository at this point in the history
  • Loading branch information
phucd5 committed Oct 28, 2023
1 parent c16c40e commit 56b747b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions server/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ export const getUserById = async (req, res) => {

export const getUserByEmailOrUsername = async (req, res) => {
try {
const { emailOrUsername } = req.params;
const { email, username } = req.body;

const conditions = [];
if (email) conditions.push({ email });
if (username) conditions.push({ userName: username });

const user = await UserModel.findOne({
$or: [{ email: emailOrUsername }, { userName: emailOrUsername }],
$or: conditions,
});

if (!user) {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

const router = express.Router();

router.get("/search/:emailOrUsername", getUserByEmailOrUsername);
router.post("/search", getUserByEmailOrUsername);
router.get("/:userId", getUserById);

router.get("/:userId/friends", getUserFriends);
Expand Down

0 comments on commit 56b747b

Please sign in to comment.