Skip to content

Commit

Permalink
Refactor: return 0 when locations are same in getTaxiFareHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
kmc7468 committed Aug 20, 2024
1 parent 9e6af15 commit d5c8346
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/services/fare.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ const getTaxiFareHandler = async (req, res) => {
naverMapApi["X-NCP-APIGW-API-KEY"] === false ||
naverMapApi["X-NCP-APIGW-API-KEY-ID"] === false
) {
res.status(503).json({
return res.status(503).json({
error: "fare/getTaxiFareHandler: Naver Map API credential not found",
});
return;
}

if (req.query.from === req.query.to) {
return res.status(200).json({ fare: 0 });
}

const from = await locationModel
.findOne({
_id: { $eq: req.query.from },
Expand All @@ -40,10 +44,9 @@ const getTaxiFareHandler = async (req, res) => {
const sTime = scaledTime(new Date(req.query.time));

if (!from || !to) {
res
return res
.status(400)
.json({ error: "fare/getTaxiFareHandler: Wrong location" });
return;
}

const fare = await taxiFareModel
Expand Down

0 comments on commit d5c8346

Please sign in to comment.