Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
royyan005 committed Jun 2, 2022
1 parent 7fbf2b6 commit d6f26da
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions controller/hasilpanen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion controller/inventaris.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
9 changes: 7 additions & 2 deletions controller/keuangan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 6 additions & 4 deletions controller/penyakit.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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({
Expand Down Expand Up @@ -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
Expand All @@ -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) => {
Expand Down Expand Up @@ -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: {
Expand Down
3 changes: 1 addition & 2 deletions models/keuangan.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Keuangan = db.define('keuangan',{
},
tanggal: {
type: Date,
default: Date.now(),
},
kegiatan: {
type: String,
Expand All @@ -19,7 +18,7 @@ const Keuangan = db.define('keuangan',{
type: String,
},
jumlah: {
type: String,
type: Int16Array,
},
createdAt: {
type: String,
Expand Down
5 changes: 4 additions & 1 deletion models/penyakit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const Penyakit = db.define('penyakit',{
indikasi: {
type: String,
},
link_foto: {
image: {
type: String,
},
url: {
type: String,
},
tanggal: {
Expand Down
Binary file added public/images/bercak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand Down Expand Up @@ -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;

0 comments on commit d6f26da

Please sign in to comment.