Skip to content

Commit

Permalink
wah
Browse files Browse the repository at this point in the history
  • Loading branch information
andifahruddinakas committed Oct 24, 2024
1 parent f0133ab commit 53cfd0c
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,51 @@ app.get(["/api", "/api/desa"], (req, res) => {
});

app.get("/api/desa/:kodedesa", (req, res) => {
const { kodedesa } = req.params;
const folderPath = path.join(__dirname, "public", "desa", kodedesa);
const folderPath = path.join(
__dirname,
"public",
"desa",
req.params.kodedesa
);

if (!fs.existsSync(folderPath)) {
return res.status(400).json({
status: 400,
error: true,
message: `ID Desa tidak ditemukan`,
message: "ID Desa tidak ditemukan",
});
}

res.status(400).json({
status: 400,
error: true,
message: "Tahun tidak ditemukan dalam permintaan",
});
});

app.get("/api/desa/:kodedesa/:tahun", (req, res) => {
const { kodedesa, tahun } = req.params;
const folderPath = path.join(__dirname, "public", "desa", kodedesa);
const filePath = path.join(folderPath, tahun + ".json");
const filePath = path.join(
__dirname,
"public",
"desa",
kodedesa,
tahun + ".json"
);

if (!fs.existsSync(folderPath)) {
if (!fs.existsSync(path.join(__dirname, "public", "desa", kodedesa))) {
return res.status(400).json({
status: 400,
error: true,
message: "ID Desa tidak ditemukan",
});
}

if (!fs.existsSync(filePath)) {
return res.status(400).json({
status: 400,
error: true,
message: `ID Desa tidak ditemukan`,
message: "Tahun tidak ditemukan",
});
}

Expand All @@ -50,7 +73,7 @@ app.get("/api/desa/:kodedesa/:tahun", (req, res) => {
return res.status(500).json({
status: 500,
error: true,
message: "ID Desa tidak ditemukan",
message: "Error reading the file",
});
}
res.json(JSON.parse(data));
Expand Down

0 comments on commit 53cfd0c

Please sign in to comment.