diff --git a/controller/hasilpanen.js b/controller/hasilpanen.js index d30e7ca35..303b98bc8 100644 --- a/controller/hasilpanen.js +++ b/controller/hasilpanen.js @@ -83,6 +83,7 @@ export const updateHasilPanen = async (req, res) => { id_hasil: req.params.id_hasil } }); + if (updateHasilPanen == 0) return error res.status(200).json({ status: res.statusCode, message: 'Berhasil memperbarui hasil panen', diff --git a/controller/inventaris.js b/controller/inventaris.js index 6e6c893e5..780ef5a97 100644 --- a/controller/inventaris.js +++ b/controller/inventaris.js @@ -16,7 +16,7 @@ export const postInventaris = async (req, res) => { const fileSize = file.data.length const ext = path.extname(file.name) const fileName = file.md5 + ext - const url = `${req.protocol}://${req.get("host")}/images/${fileName}` + const url = `${req.protocol}://${req.get("host")}/public/images/${fileName}` const allowedType = ['.png', '.jpg', '.jpeg'] if (!allowedType.includes(ext.toLowerCase())) return res.status(422).json({ diff --git a/controller/keuangan.js b/controller/keuangan.js index 069e5b6f2..c0660887d 100644 --- a/controller/keuangan.js +++ b/controller/keuangan.js @@ -71,19 +71,24 @@ export const getKeuanganById = async (req, res) => { } export const updateKeuangan = async (req, res) => { - const dataKeuangan = req.body try { const updateKeuangan = await Keuangan.update({ tanggal: req.body.tanggal, kegiatan: req.body.kegiatan, jenis: req.body.jenis, catatan: req.body.catatan, - jumlah: req.body.catatan, + jumlah: req.body.jumlah, },{ where:{ id_keuangan: req.params.id_keuangan } }); + if (updateKeuangan == 0) return error + const dataKeuangan = await Keuangan.findOne({ + where: { + id_keuangan: req.params.id_keuangan, + } + }) res.status(200).json({ status: res.statusCode, message: 'Berhasil memperbarui Keuangan', diff --git a/controller/penyakit.js b/controller/penyakit.js index 00ee1663e..fce191128 100644 --- a/controller/penyakit.js +++ b/controller/penyakit.js @@ -1,5 +1,7 @@ //POG import Penyakit from "../models/penyakit.js"; +import path from "path" +import fs from "fs" export const postPenyakit = async (req, res) => { const { @@ -18,7 +20,7 @@ export const postPenyakit = async (req, res) => { const fileSize = file.data.length const ext = path.extname(file.name) const fileName = file.md5 + ext - const url = `${req.protocol}://${req.get("host")}/images/${fileName}` + const url = `${req.protocol}://${req.get("host")}/public/images/${fileName}` const allowedType = ['.png', '.jpg', '.jpeg'] if (!allowedType.includes(ext.toLowerCase())) return res.status(422).json({ @@ -110,7 +112,7 @@ export const updatePenyakit = async (req, res) => { let fileName = ""; if (req.files === null) { - fileName = penyakit.image + fileName = searchpenyakit.image } else { const file = req.files.file const fileSize = file.data.length @@ -127,7 +129,7 @@ export const updatePenyakit = async (req, res) => { message: 'Image must be less than 5 MB', }) - const filePath = `./public/images/${searchinventaris.image}` + const filePath = `./public/images/${searchpenyakit.image}` fs.unlinkSync(filePath) file.mv(`./public/images/${fileName}`, (err) => { @@ -192,7 +194,7 @@ export const deletePenyakit = async (req, res) => { }) try { - const filePath = `./public/images/${Penyakit.image}` + const filePath = `./public/images/${penyakit.image}` fs.unlinkSync(filePath) await Penyakit.destroy({ where: { diff --git a/models/keuangan.js b/models/keuangan.js index 8f839b883..38b2e2938 100644 --- a/models/keuangan.js +++ b/models/keuangan.js @@ -7,7 +7,6 @@ const Keuangan = db.define('keuangan',{ }, tanggal: { type: Date, - default: Date.now(), }, kegiatan: { type: String, @@ -19,7 +18,7 @@ const Keuangan = db.define('keuangan',{ type: String, }, jumlah: { - type: String, + type: Int16Array, }, createdAt: { type: String, diff --git a/models/penyakit.js b/models/penyakit.js index 260db2ab9..f3f621ea4 100644 --- a/models/penyakit.js +++ b/models/penyakit.js @@ -12,7 +12,10 @@ const Penyakit = db.define('penyakit',{ indikasi: { type: String, }, - link_foto: { + image: { + type: String, + }, + url: { type: String, }, tanggal: { diff --git a/public/images/bercak.png b/public/images/bercak.png new file mode 100644 index 000000000..93c571e8b Binary files /dev/null and b/public/images/bercak.png differ diff --git a/routes/routes.js b/routes/routes.js index 85a64fa55..f6c732350 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -3,6 +3,8 @@ import { getToken, getUsers, Register, Login, Logout, Delete } from "../controll import { verifyToken } from "../middleware/verifyToken.js"; import { postHasilPanen, getHasilPanen, getHasilPanenById, updateHasilPanen, deleteHasilPanen } from "../controller/hasilpanen.js"; import { postInventaris, getInventaris, getInventarisById, updateInventaris, deleteInventaris } from "../controller/inventaris.js"; +import { postKeuangan, getKeuangan, getKeuanganById, updateKeuangan, deleteKeuangan } from "../controller/keuangan.js"; +import { postPenyakit, getPenyakit, getPenyakitById, updatePenyakit, deletePenyakit } from "../controller/penyakit.js"; import { refreshToken } from "../controller/refreshToken.js"; @@ -33,5 +35,18 @@ router.get("/inventaris/:id_inventaris", getInventarisById); router.put("/inventaris/:id_inventaris", updateInventaris); router.delete("/inventaris/:id_inventaris", deleteInventaris); +// KEUANGAN +router.post("/keuangan", postKeuangan); +router.get("/keuangan", getKeuangan); +router.get("/keuangan/:id_keuangan", getKeuanganById); +router.put("/keuangan/:id_keuangan", updateKeuangan); +router.delete("/keuangan/:id_keuangan", deleteKeuangan); + +// INVENTARIS +router.post("/penyakit", postPenyakit); +router.get("/penyakit", getPenyakit); +router.get("/penyakit/:id_penyakit", getPenyakitById); +router.put("/penyakit/:id_penyakit", updatePenyakit); +router.delete("/penyakit/:id_penyakit", deletePenyakit); export default router; \ No newline at end of file