Skip to content

Commit

Permalink
๐Ÿ› catch๋ฌธ์—์„œ error๋ฅผ ๋ช…์‹œํ•˜์ง€ ์•Š์•„ ๋ฐœ์ƒํ•˜๋Š” ๋ฒ„๊ทธ ์ˆ˜์ •, response๋กœ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฐ์ฒด๊ฐ€ ํฌํ•จํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€ โ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆ๋ฐ ์ˆ˜์ •
  • Loading branch information
ChanHoLee275 committed Sep 23, 2021
1 parent 6c2f441 commit 5b9a50e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions backend/src/services/team/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ const Team = require("../../models/team");

const createTeam = async (req, res, next) => {
try{
await Team.create({...req.body});
const result = await Team.create({...req.body});
await res.status(201).json({
code: '2001',
status: '์„ฑ๊ณต : Team ์ƒ์„ฑ',
message: 'Team์ด ์ •์ƒ์ ์œผ๋กœ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'
message: 'Team์ด ์ •์ƒ์ ์œผ๋กœ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
id: result["_id"]
});
}
catch(err){
Expand All @@ -30,7 +31,7 @@ const deleteTeam = async (req, res, next) => {
message: 'Team์ด ์ •์ƒ์ ์œผ๋กœ ์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'
});
}
catch{
catch(err){
console.error(err);
await res.status(500).json({
code: '5000',
Expand All @@ -43,27 +44,28 @@ const deleteTeam = async (req, res, next) => {
const updateTeam = async (req, res, next) => {
try{
const teamId = req.params['teamId'];
if(req.body['userIds'] !== undefined) throw new Error("userIds๋Š” ์ ‘๊ทผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
await Team.findByIdAndUpdate(teamId,{...req.body});
await res.status(200).json({
code: '2000',
status: '์„ฑ๊ณต : Team ์ˆ˜์ •',
message: 'Team์ด ์ •์ƒ์ ์œผ๋กœ ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'
});
}
catch{
catch(err){
console.error(err);
await res.status(500).json({
code: '5000',
status: '์—๋Ÿฌ : ์„œ๋ฒ„ ์—๋Ÿฌ',
message : '์ˆ˜์ • ์š”์ฒญ ์ฒ˜๋ฆฌ ์ค‘ ์„œ๋ฒ„์—์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.'
message : `${err}`
});
}
};

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

await res.status(200).json({
Expand All @@ -73,7 +75,7 @@ const searchTeams = async (req, res, next) => {
study: teams
});
}
catch{
catch(err){
console.error(err);
await res.status(500).json({
code: '5000',
Expand Down

0 comments on commit 5b9a50e

Please sign in to comment.