Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.48 KB | None | 0 0
  1. const Pool = require('pg').Pool
  2. const response = require('./response')
  3. const pool = new Pool({
  4.   user: 'postgres',
  5.   host: 'localhost',
  6.   database: 'perijinan',
  7.   password: 'postgres',
  8.   port: 5433,
  9. })
  10.  
  11. const getSMK = (req, res) => {
  12.   let data = {
  13.     id_bag : req.params.id_bag
  14.   }
  15.     pool.query('SELECT * FROM public.tb_profil WHERE id_bagian = 1', (error, results) => {
  16.       if (error) {
  17.         throw error
  18.       }
  19.       response.get("Success Get Data",results.rows,res)
  20.     })
  21.   }
  22.   const getP2T = (req, res) => {
  23.     let data = {
  24.       id_bag : req.params.id_bag
  25.     }
  26.       pool.query('SELECT * FROM public.tb_profil WHERE id_bagian = 3', (error, results) => {
  27.         if (error) {
  28.           throw error
  29.         }
  30.         response.get("Success Get Data",results.rows,res)
  31.       })
  32.     }
  33.     const postPerijinanSMK = (req, res) => {
  34.       let data = {
  35.         urlfile : req.body.urlfile,
  36.         no_pengajuan : req.body.no_pengajuan
  37.       }
  38.       let date = new Date();
  39.       let timenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
  40.       let datenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
  41.  
  42.           pool.query(`INSERT INTO "public"."tb_pengajuan"(id_profil, no_pengajuan, waktu_pengajuan, id_status, tanggal_update, "id_jenispengajuan ") VALUES (1,`+data.no_pengajuan+`,`+timenow+`, 1,`+datenow+`, 2)`,(error, result) => {
  43.  
  44.             if(error){
  45.               throw error
  46.             }
  47.  
  48.             pool.query(`INSERT INTO "public"."tb_arsip" (arsip) VALUES ('${data.urlfile}')`, (error, results) => {
  49.               if (error) {
  50.                 throw error
  51.               }else{
  52.                 console.log("Success")
  53.               }
  54.            
  55.             })
  56.  
  57.             response.post("Success Get Data",res)
  58.  
  59.           })
  60.       }
  61.       const postSekolahYayasan = (req, res) => {
  62.         let data = {
  63.           urlfile : req.body.urlfile,
  64.           no_pengajuan : req.body.no_pengajuan
  65.         }
  66.         let date = new Date();
  67.         let timenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
  68.         let datenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
  69.    
  70.             pool.query(`INSERT INTO "public"."tb_pengajuan"(id_profil, no_pengajuan, waktu_pengajuan, id_status, tanggal_update, "id_jenispengajuan ") VALUES (1,`+data.no_pengajuan+`,`+timenow+`, 1,`+datenow+`, 2)`,(error, result) => {
  71.    
  72.               if(error){
  73.                 throw error
  74.               }
  75.    
  76.               pool.query(`INSERT INTO "public"."tb_arsip" (arsip) VALUES ('${data.urlfile}')`, (error, results) => {
  77.                 if (error) {
  78.                   throw error
  79.                 }else{
  80.                   console.log("Success")
  81.                 }
  82.              
  83.               })
  84.    
  85.               response.post("Success Get Data",res)
  86.    
  87.             })
  88.         }
  89.         const getDataDisdik = (req, res) => {
  90.           pool.query(`SELECT * FROM tb_pengajuan WHERE id_profil = 1`, (error, results) => {
  91.             if (error) {
  92.               throw error
  93.             }
  94.             response.post("Success Get Data",res)
  95.           })
  96.         }
  97. module.exports = {
  98.     getSMK,
  99.     getP2T,
  100.     getDataDisdik,
  101.     postPerijinanSMK,
  102.     postSekolahYayasan
  103. }
  104. //API
  105. app.get('/getusersmk', db.getSMK)
  106. app.get('/getuserp2t', db.getP2T)
  107. app.get('/getdatadisdik', db.getDataDisdik)
  108. app.post('/postperijinan', db.postPerijinanSMK)
  109. app.post('/postsekolah', db.postSekolahYayasan)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement