Skip to content

Commit

Permalink
๐Ÿ› GET /study?userId=${userId}๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฒ„๊ทธ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
query์— ์ œ์•ฝ์„ ๋‘์–ด, userId๋„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ˆ˜์ •
  • Loading branch information
ChanHoLee275 committed Sep 23, 2021
1 parent b583c4a commit 1d71d59
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions backend/src/services/team/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ const updateTeam = async (req, res, next) => {

const searchTeams = async (req, res, next) => {
try{

let title = req.query["title"];
if(title === undefined) title = '';
const teams = await Team.find({title: new RegExp(`${title}`,'i')}).exec();
let userId = req.query["userId"];
let teams;

if(title !== undefined && userId === undefined) teams = await Team.find({title: new RegExp(`${title}`,'i')}).exec();
else if(title === undefined && userId !== undefined) teams = await Team.find({userIds : [`${userId}`]}).exec();
else if(title === undefined && userId === undefined) teams = await Team.find({});
else{
throw new Error("query๋กœ ๋ณด๋‚ด๋Š” ๋ณ€์ˆ˜๊ฐ€ ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
}

await res.status(200).json({
code: '2000',
Expand All @@ -80,7 +88,7 @@ const searchTeams = async (req, res, next) => {
await res.status(500).json({
code: '5000',
status: '์—๋Ÿฌ : ์„œ๋ฒ„ ์—๋Ÿฌ',
message : '๊ฒ€์ƒ‰ ์š”์ฒญ ์ฒ˜๋ฆฌ ์ค‘ ์„œ๋ฒ„์—์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
message : `${err}`
});
}
};
Expand Down

0 comments on commit 1d71d59

Please sign in to comment.