Advertisement
Guest User

DEV4

a guest
Sep 16th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. const connection = require('../config/database')
  2. const bodyParser = require('body-parser')
  3.  
  4. exports.ShowPengeluaran = (req, res) => {
  5. const sql = 'SELECT * FROM pengeluaran'
  6. connection.query(sql, (error, results) => {
  7. if(error) throw error
  8. res.json(results)
  9. })
  10. }
  11.  
  12. exports.PengeluaranID = (req, res) => {
  13. const id = req.params.id
  14. const sql = 'SELECT * FROM pengeluaran WHERE id=?'
  15. connection.query(sql, [id], (error, results) => {
  16. if(error) throw error
  17. res.json(results)
  18. })
  19. }
  20.  
  21. exports.AddPengeluaran = (req, res) => {
  22. const id_nik = req.body.id_nik
  23. const pengeluaran = req.body.pengeluaran
  24. const tanggal_pengeluaran = req.body.tanggal_pengeluaran
  25. const sql = 'INSERT INTO pengeluaran(id_nik,pengeluaran,tanggal_pengeluaran) VALUES(?,?,?)'
  26. connection.query(sql, [id_nik, pengeluaran, tanggal_pengeluaran], (error, results) => {
  27. if(error) throw error
  28. res.json(results)
  29. })
  30. }
  31.  
  32. exports.EditPengeluaran = (req, res) => {
  33. const id = req.params.id
  34. const id_nik = req.params.id_nik
  35. const pengeluaran = req.body.pengeluaran
  36. const tanggal_pengeluaran = req.body.tanggal_pengeluaran
  37. const sql = 'UPDATE pengeluaran SET id_nik=?, pengeluaran=?, tanggal_pengeluaran=? WHERE id=?'
  38. connection.query(sql, [id_nik,pengeluaran,tanggal_pengeluaran,id], (error, results) => {
  39. if(error) throw error
  40. res.json(results)
  41. })
  42. }
  43.  
  44. exports.DeletePengeluaran = (req, res) => {
  45. const id = req.params.id
  46. const id_nik = req.body.id_nik
  47. const pengeluaran = req.body.pengeluaran
  48. const tanggal_pengeluaran = req.body.tanggal_pengeluaran
  49. const sql = 'DELETE FROM pengeluaran WHERE id=?'
  50. connection.query(sql, [id], (error, results) => {
  51. if(error) throw error
  52. res.json(results)
  53. })
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement