Skip to content

Commit

Permalink
Borrando código duplicado
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 2, 2024
1 parent acb5c9d commit cd30dee
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ app.get("/health", (req, res) => {
res.json({ status: "OK" });
});

returnError = (res, error) => {
res.status(error.response.status).json({ error: error.response.data.error });
}

app.post("/login", async (req, res) => {
try {
// Forward the login request to the authentication service
const authResponse = await axios.post(authServiceUrl + "/login", req.body);
res.json(authResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -49,9 +51,7 @@ app.post("/adduser", async (req, res) => {
);
res.json(userResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -64,9 +64,7 @@ app.get("/userInfo", async (req, res) => {
);
res.json(userResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -79,9 +77,7 @@ app.post("/saveGameList", async (req, res) => {
);
res.json(gameResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -94,9 +90,7 @@ app.get("/questions", async (req, res) => {
);
res.json(questionResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -109,9 +103,7 @@ app.post("/questions", async (req, res) => {
);
res.json(questionResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -123,9 +115,7 @@ app.get("/stats", async (req, res) => {
});
res.json(statsResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -138,9 +128,7 @@ app.post("/saveGame", async (req, res) => {
);
res.json(gameResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand All @@ -151,9 +139,7 @@ app.get("/ranking", async (req, res) => {
});
res.json(statsResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
returnError(res, error);
}
});

Expand Down

0 comments on commit cd30dee

Please sign in to comment.