Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Pool = require('pg').Pool
- const response = require('./response')
- const pool = new Pool({
- user: 'postgres',
- host: 'localhost',
- database: 'perijinan',
- password: 'postgres',
- port: 5433,
- })
- const getSMK = (req, res) => {
- let data = {
- id_bag : req.params.id_bag
- }
- pool.query('SELECT * FROM public.tb_profil WHERE id_bagian = 1', (error, results) => {
- if (error) {
- throw error
- }
- response.get("Success Get Data",results.rows,res)
- })
- }
- const getP2T = (req, res) => {
- let data = {
- id_bag : req.params.id_bag
- }
- pool.query('SELECT * FROM public.tb_profil WHERE id_bagian = 3', (error, results) => {
- if (error) {
- throw error
- }
- response.get("Success Get Data",results.rows,res)
- })
- }
- const postPerijinanSMK = (req, res) => {
- let data = {
- urlfile : req.body.urlfile,
- no_pengajuan : req.body.no_pengajuan
- }
- let date = new Date();
- let timenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
- let datenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
- 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) => {
- if(error){
- throw error
- }
- pool.query(`INSERT INTO "public"."tb_arsip" (arsip) VALUES ('${data.urlfile}')`, (error, results) => {
- if (error) {
- throw error
- }else{
- console.log("Success")
- }
- })
- response.post("Success Get Data",res)
- })
- }
- const postSekolahYayasan = (req, res) => {
- let data = {
- urlfile : req.body.urlfile,
- no_pengajuan : req.body.no_pengajuan
- }
- let date = new Date();
- let timenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
- let datenow = date.getDate()+"-"+date.getMonth()+1+"-"+date.getFullYear();
- 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) => {
- if(error){
- throw error
- }
- pool.query(`INSERT INTO "public"."tb_arsip" (arsip) VALUES ('${data.urlfile}')`, (error, results) => {
- if (error) {
- throw error
- }else{
- console.log("Success")
- }
- })
- response.post("Success Get Data",res)
- })
- }
- const getDataDisdik = (req, res) => {
- pool.query(`SELECT * FROM tb_pengajuan WHERE id_profil = 1`, (error, results) => {
- if (error) {
- throw error
- }
- response.post("Success Get Data",res)
- })
- }
- module.exports = {
- getSMK,
- getP2T,
- getDataDisdik,
- postPerijinanSMK,
- postSekolahYayasan
- }
- //API
- app.get('/getusersmk', db.getSMK)
- app.get('/getuserp2t', db.getP2T)
- app.get('/getdatadisdik', db.getDataDisdik)
- app.post('/postperijinan', db.postPerijinanSMK)
- app.post('/postsekolah', db.postSekolahYayasan)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement