Skip to content

Commit d6f26da

Browse files
committed
fix bugs
1 parent 7fbf2b6 commit d6f26da

File tree

8 files changed

+35
-10
lines changed

8 files changed

+35
-10
lines changed

controller/hasilpanen.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const updateHasilPanen = async (req, res) => {
8383
id_hasil: req.params.id_hasil
8484
}
8585
});
86+
if (updateHasilPanen == 0) return error
8687
res.status(200).json({
8788
status: res.statusCode,
8889
message: 'Berhasil memperbarui hasil panen',

controller/inventaris.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const postInventaris = async (req, res) => {
1616
const fileSize = file.data.length
1717
const ext = path.extname(file.name)
1818
const fileName = file.md5 + ext
19-
const url = `${req.protocol}://${req.get("host")}/images/${fileName}`
19+
const url = `${req.protocol}://${req.get("host")}/public/images/${fileName}`
2020
const allowedType = ['.png', '.jpg', '.jpeg']
2121

2222
if (!allowedType.includes(ext.toLowerCase())) return res.status(422).json({

controller/keuangan.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,24 @@ export const getKeuanganById = async (req, res) => {
7171
}
7272

7373
export const updateKeuangan = async (req, res) => {
74-
const dataKeuangan = req.body
7574
try {
7675
const updateKeuangan = await Keuangan.update({
7776
tanggal: req.body.tanggal,
7877
kegiatan: req.body.kegiatan,
7978
jenis: req.body.jenis,
8079
catatan: req.body.catatan,
81-
jumlah: req.body.catatan,
80+
jumlah: req.body.jumlah,
8281
},{
8382
where:{
8483
id_keuangan: req.params.id_keuangan
8584
}
8685
});
86+
if (updateKeuangan == 0) return error
87+
const dataKeuangan = await Keuangan.findOne({
88+
where: {
89+
id_keuangan: req.params.id_keuangan,
90+
}
91+
})
8792
res.status(200).json({
8893
status: res.statusCode,
8994
message: 'Berhasil memperbarui Keuangan',

controller/penyakit.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//POG
22
import Penyakit from "../models/penyakit.js";
3+
import path from "path"
4+
import fs from "fs"
35

46
export const postPenyakit = async (req, res) => {
57
const {
@@ -18,7 +20,7 @@ export const postPenyakit = async (req, res) => {
1820
const fileSize = file.data.length
1921
const ext = path.extname(file.name)
2022
const fileName = file.md5 + ext
21-
const url = `${req.protocol}://${req.get("host")}/images/${fileName}`
23+
const url = `${req.protocol}://${req.get("host")}/public/images/${fileName}`
2224
const allowedType = ['.png', '.jpg', '.jpeg']
2325

2426
if (!allowedType.includes(ext.toLowerCase())) return res.status(422).json({
@@ -110,7 +112,7 @@ export const updatePenyakit = async (req, res) => {
110112

111113
let fileName = "";
112114
if (req.files === null) {
113-
fileName = penyakit.image
115+
fileName = searchpenyakit.image
114116
} else {
115117
const file = req.files.file
116118
const fileSize = file.data.length
@@ -127,7 +129,7 @@ export const updatePenyakit = async (req, res) => {
127129
message: 'Image must be less than 5 MB',
128130
})
129131

130-
const filePath = `./public/images/${searchinventaris.image}`
132+
const filePath = `./public/images/${searchpenyakit.image}`
131133
fs.unlinkSync(filePath)
132134

133135
file.mv(`./public/images/${fileName}`, (err) => {
@@ -192,7 +194,7 @@ export const deletePenyakit = async (req, res) => {
192194
})
193195

194196
try {
195-
const filePath = `./public/images/${Penyakit.image}`
197+
const filePath = `./public/images/${penyakit.image}`
196198
fs.unlinkSync(filePath)
197199
await Penyakit.destroy({
198200
where: {

models/keuangan.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const Keuangan = db.define('keuangan',{
77
},
88
tanggal: {
99
type: Date,
10-
default: Date.now(),
1110
},
1211
kegiatan: {
1312
type: String,
@@ -19,7 +18,7 @@ const Keuangan = db.define('keuangan',{
1918
type: String,
2019
},
2120
jumlah: {
22-
type: String,
21+
type: Int16Array,
2322
},
2423
createdAt: {
2524
type: String,

models/penyakit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const Penyakit = db.define('penyakit',{
1212
indikasi: {
1313
type: String,
1414
},
15-
link_foto: {
15+
image: {
16+
type: String,
17+
},
18+
url: {
1619
type: String,
1720
},
1821
tanggal: {

public/images/bercak.png

257 KB
Loading

routes/routes.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { getToken, getUsers, Register, Login, Logout, Delete } from "../controll
33
import { verifyToken } from "../middleware/verifyToken.js";
44
import { postHasilPanen, getHasilPanen, getHasilPanenById, updateHasilPanen, deleteHasilPanen } from "../controller/hasilpanen.js";
55
import { postInventaris, getInventaris, getInventarisById, updateInventaris, deleteInventaris } from "../controller/inventaris.js";
6+
import { postKeuangan, getKeuangan, getKeuanganById, updateKeuangan, deleteKeuangan } from "../controller/keuangan.js";
7+
import { postPenyakit, getPenyakit, getPenyakitById, updatePenyakit, deletePenyakit } from "../controller/penyakit.js";
68
import { refreshToken } from "../controller/refreshToken.js";
79

810

@@ -33,5 +35,18 @@ router.get("/inventaris/:id_inventaris", getInventarisById);
3335
router.put("/inventaris/:id_inventaris", updateInventaris);
3436
router.delete("/inventaris/:id_inventaris", deleteInventaris);
3537

38+
// KEUANGAN
39+
router.post("/keuangan", postKeuangan);
40+
router.get("/keuangan", getKeuangan);
41+
router.get("/keuangan/:id_keuangan", getKeuanganById);
42+
router.put("/keuangan/:id_keuangan", updateKeuangan);
43+
router.delete("/keuangan/:id_keuangan", deleteKeuangan);
44+
45+
// INVENTARIS
46+
router.post("/penyakit", postPenyakit);
47+
router.get("/penyakit", getPenyakit);
48+
router.get("/penyakit/:id_penyakit", getPenyakitById);
49+
router.put("/penyakit/:id_penyakit", updatePenyakit);
50+
router.delete("/penyakit/:id_penyakit", deletePenyakit);
3651

3752
export default router;

0 commit comments

Comments
 (0)