diff --git a/api/server.js b/api/server.js index 71fc119..12143df 100644 --- a/api/server.js +++ b/api/server.js @@ -124,23 +124,10 @@ app.get("/sensordata/:id", (req, res) => { air_data.bz, air_data.aq, air_data.updated_at, - - sensor_data.alamat, - - kelurahan.nama AS kelurahan, - kecamatan.nama AS kecamatan - + alamat_data.alamat AS alamat FROM air_data - - JOIN sensor_data - ON air_data.id = sensor_data.id - - JOIN kelurahan - ON sensor_data.kelurahan = kelurahan.id - - JOIN kecamatan - ON kelurahan.kecamatan_id = kecamatan.id - + JOIN alamat_data + ON alamat_data.id = air_data.id WHERE air_data.id = ? ORDER BY air_data.updated_at DESC LIMIT 1 @@ -163,7 +150,7 @@ app.get("/sensordata/:id", (req, res) => { }); app.get("/sensors", (req, res) => { - const sql = `SELECT id FROM sensor_data ORDER BY id ASC`; + const sql = `SELECT * FROM alamat_data where status = 1 ORDER BY id ASC`; db.query(sql, (err, results) => { if (err) { @@ -178,56 +165,52 @@ app.get("/sensors", (req, res) => { // ADD SENSOR // ============================ app.post("/addSensor", (req, res) => { - const { kelurahan, alamat } = req.body; + const { id } = req.body; - // ============================ - // VALIDATION - // ============================ - if (!kelurahan || !alamat) { + // check if id is provided + if (!id) { return res.status(400).json({ - error: "kelurahan dan alamat wajib diisi" + error: "Sensor ID is required" }); } - // ============================ - // VALIDATE KELURAHAN EXISTS - // ============================ - const checkSql = `SELECT id FROM kelurahan WHERE id = ?`; + // check if id is numeric + if (isNaN(id)) { + return res.status(400).json({ + error: "Sensor ID must be numeric" + }); + } - db.query(checkSql, [kelurahan], (err, rows) => { + // check if id exists in alamat_data table, if available then continue + const checkSql = `SELECT id FROM alamat_data WHERE id = ?`; + + db.query(checkSql, [id], (err, results) => { if (err) { console.error(err); return res.status(500).json({ error: "DB error" }); } - if (rows.length === 0) { + if (results.length === 0) { return res.status(400).json({ - error: "Kelurahan tidak valid" + error: "Sensor ID not found in alamat_data table" }); } + }); + + // update the status field to 1 to the id in alamat_data table + const updateSql = `UPDATE alamat_data SET status = 1 WHERE id = ?`; - // ============================ - // INSERT SENSOR - // ============================ - const insertSql = ` - INSERT INTO sensor_data (kelurahan, alamat) - VALUES (?, ?) - `; - - db.query(insertSql, [kelurahan, alamat], (err, result) => { - if (err) { - console.error(err); - return res.status(500).json({ - error: "DB error saat insert" - }); - } - - res.json({ - message: "Sensor berhasil ditambahkan", - sensor_id: result.insertId - }); + db.query(updateSql, [id], (err, result) => { + if (err) { + console.error(err); + return res.status(500).json({ error: "DB error" }); + } + res.json({ + message: "Sensor added successfully", + id: id }); }); + }); // ============================ @@ -252,8 +235,8 @@ app.get("/history", (req, res) => { // get kecamatan -app.get("/kecamatan", (req, res) => { - const sql = `SELECT id, nama FROM kecamatan ORDER BY nama ASC`; +app.get("/alamat", (req, res) => { + const sql = `SELECT * from alamat_data where status = 0 ORDER BY id ASC`; db.query(sql, (err, results) => { if (err) { @@ -266,38 +249,6 @@ app.get("/kecamatan", (req, res) => { }); -// get kelurahan by kecamatan_id -app.get("/kelurahan", (req, res) => { - const { kecamatan_id } = req.query; - - let sql = ` - SELECT - kelurahan.id, - kelurahan.nama, - kecamatan.nama AS kecamatan - FROM kelurahan - JOIN kecamatan ON kelurahan.kecamatan_id = kecamatan.id - `; - - let params = []; - - if (kecamatan_id) { - sql += ` WHERE kelurahan.kecamatan_id = ?`; - params.push(kecamatan_id); - } - - sql += ` ORDER BY kelurahan.nama ASC`; - - db.query(sql, params, (err, results) => { - if (err) { - console.error(err); - return res.status(500).json({ error: "DB error" }); - } - - res.json(results); - }); -}); - // ============================ // START SERVER // ============================ diff --git a/site/assets/images/1/1.png b/site/assets/images/1/1.png new file mode 100644 index 0000000..7212415 Binary files /dev/null and b/site/assets/images/1/1.png differ diff --git a/site/assets/images/1/2.png b/site/assets/images/1/2.png new file mode 100644 index 0000000..24e32e7 Binary files /dev/null and b/site/assets/images/1/2.png differ diff --git a/site/assets/images/10/1.png b/site/assets/images/10/1.png new file mode 100644 index 0000000..6abb9c6 Binary files /dev/null and b/site/assets/images/10/1.png differ diff --git a/site/assets/images/10/2.png b/site/assets/images/10/2.png new file mode 100644 index 0000000..b37e157 Binary files /dev/null and b/site/assets/images/10/2.png differ diff --git a/site/assets/images/2/1.png b/site/assets/images/2/1.png new file mode 100644 index 0000000..60f1fbe Binary files /dev/null and b/site/assets/images/2/1.png differ diff --git a/site/assets/images/2/2.png b/site/assets/images/2/2.png new file mode 100644 index 0000000..f287e3f Binary files /dev/null and b/site/assets/images/2/2.png differ diff --git a/site/assets/images/3/1.png b/site/assets/images/3/1.png new file mode 100644 index 0000000..69c5f31 Binary files /dev/null and b/site/assets/images/3/1.png differ diff --git a/site/assets/images/4/1.png b/site/assets/images/4/1.png new file mode 100644 index 0000000..daa3d97 Binary files /dev/null and b/site/assets/images/4/1.png differ diff --git a/site/assets/images/4/2.png b/site/assets/images/4/2.png new file mode 100644 index 0000000..0a8edcd Binary files /dev/null and b/site/assets/images/4/2.png differ diff --git a/site/assets/images/5/1.png b/site/assets/images/5/1.png new file mode 100644 index 0000000..0b67489 Binary files /dev/null and b/site/assets/images/5/1.png differ diff --git a/site/assets/images/6/1.png b/site/assets/images/6/1.png new file mode 100644 index 0000000..e9236eb Binary files /dev/null and b/site/assets/images/6/1.png differ diff --git a/site/assets/images/6/2.png b/site/assets/images/6/2.png new file mode 100644 index 0000000..bfc35d6 Binary files /dev/null and b/site/assets/images/6/2.png differ diff --git a/site/assets/images/7/1.png b/site/assets/images/7/1.png new file mode 100644 index 0000000..bcf5f90 Binary files /dev/null and b/site/assets/images/7/1.png differ diff --git a/site/assets/images/7/2.png b/site/assets/images/7/2.png new file mode 100644 index 0000000..b430930 Binary files /dev/null and b/site/assets/images/7/2.png differ diff --git a/site/assets/images/8/1.png b/site/assets/images/8/1.png new file mode 100644 index 0000000..7f954e1 Binary files /dev/null and b/site/assets/images/8/1.png differ diff --git a/site/assets/images/9/1.png b/site/assets/images/9/1.png new file mode 100644 index 0000000..7c15d84 Binary files /dev/null and b/site/assets/images/9/1.png differ diff --git a/site/index.html b/site/index.html index 4199e24..7ce7d52 100644 --- a/site/index.html +++ b/site/index.html @@ -32,6 +32,12 @@ Halaman Utama +
diff --git a/site/list.html b/site/list.html new file mode 100644 index 0000000..80d3b57 --- /dev/null +++ b/site/list.html @@ -0,0 +1,128 @@ + + + +
+ + + +
+ + + + + + + +
+ +