Skip to content

Commit

Permalink
Merge pull request #459 from sparcs-kaist/#441-rooms-create-time-vali…
Browse files Browse the repository at this point in the history
…dation

#441 방 생성 시각의 유효성을 검사하지 않는 버그
  • Loading branch information
chlehdwon authored Feb 13, 2024
2 parents 78d1f04 + c1fa0f4 commit 2e6af9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
17 changes: 11 additions & 6 deletions src/routes/docs/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@ roomsDocs[`${apiPrefix}/create`] = {
examples: {
"출발지와 도착지가 같음": {
value: {
error: "Room/create : locations are same",
error: "Rooms/create : locations are same",
},
},
"현재로부터 2주일보다 이후의 방을 생성": {
value: {
error:
"Room/create : cannot over 2 weeks on the basis of current Date",
"Rooms/create : cannot over 2 weeks on the basis of current Date",
},
},
"설정된 출발 시각 이후에 방을 생성": {
value: {
error: "Rooms/create : invalid timestamp",
},
},
"존재하지 않는 location Document를 입력": {
Expand Down Expand Up @@ -306,12 +311,12 @@ roomsDocs[`${apiPrefix}/join`] = {
},
"입력한 시간의 방이 이미 출발함": {
value: {
error: "Room/join : The room has already departed",
error: "Rooms/join : The room has already departed",
},
},
"방의 인원이 모두 찼음": {
value: {
error: "Room/join : The room is already full",
error: "Rooms/join : The room is already full",
},
},
},
Expand Down Expand Up @@ -590,12 +595,12 @@ roomsDocs[`${apiPrefix}/search`] = {
examples: {
"출발지와 도착지가 같음": {
value: {
error: "Room/search : Bad request",
error: "Rooms/search : Bad request",
},
},
"출발/도착지가 존재하지 않는 장소": {
value: {
error: "Room/search : no corresponding locations",
error: "Rooms/search : no corresponding locations",
},
},
},
Expand Down
23 changes: 15 additions & 8 deletions src/services/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const createHandler = async (req, res) => {
try {
if (from === to) {
return res.status(400).json({
error: "Room/create : locations are same",
error: "Rooms/create : locations are same",
});
}

if (req.timestamp > Date.parse(req.body.time)) {
return res.status(400).json({
error: "Rooms/create : invalid timestamp",
});
}

Expand All @@ -33,7 +39,8 @@ const createHandler = async (req, res) => {

if (createTime.getTime() > maxTime.getTime()) {
return res.status(400).json({
error: "Room/create : cannot over 2 weeks on the basis of current Date",
error:
"Rooms/create : cannot over 2 weeks on the basis of current Date",
});
}

Expand Down Expand Up @@ -179,15 +186,15 @@ const joinHandler = async (req, res) => {
// 방이 이미 출발한 경우, 400 오류를 반환합니다.
if (req.timestamp >= room.time) {
res.status(400).json({
error: "Room/join : The room has already departed",
error: "Rooms/join : The room has already departed",
});
return;
}

// 방의 인원이 모두 찬 경우, 400 오류를 반환합니다.
if (room.part.length + 1 > room.maxPartLength) {
res.status(400).json({
error: "Room/join : The room is already full",
error: "Rooms/join : The room is already full",
});
return;
}
Expand Down Expand Up @@ -267,7 +274,7 @@ const abortHandler = async (req, res) => {
} else {
// room.part에는 user가 있지만 user.ongoingRoom이나 user.doneRoom에는 room이 없는 상황.
logger.error(
`Room/abort: referential integrity error (user: ${user._id}, room: ${room._id})`
`Rooms/abort: referential integrity error (user: ${user._id}, room: ${room._id})`
);
return res.status(500).json({
error: "Rooms/abort : internal server error",
Expand Down Expand Up @@ -311,7 +318,7 @@ const searchHandler = async (req, res) => {
// 출발지와 도착지가 같은 경우
if (from && to && from === to) {
return res.status(400).json({
error: "Room/search : Bad request",
error: "Rooms/search : Bad request",
});
}

Expand All @@ -320,15 +327,15 @@ const searchHandler = async (req, res) => {
const fromLocation = await locationModel.findById(from);
if (!fromLocation || fromLocation?.isValid === false) {
return res.status(400).json({
error: "Room/search : no corresponding locations",
error: "Rooms/search : no corresponding locations",
});
}
}
if (to) {
const toLocation = await locationModel.findById(to);
if (!toLocation || toLocation?.isValid === false) {
return res.status(400).json({
error: "Room/search : no corresponding locations",
error: "Rooms/search : no corresponding locations",
});
}
}
Expand Down

0 comments on commit 2e6af9d

Please sign in to comment.