Browse Source

fixing sanksi and graph

yazid138 3 năm trước cách đây
mục cha
commit
769b1c6ae0
3 tập tin đã thay đổi với 27 bổ sung26 xóa
  1. 20 21
      controller/graph.controller.js
  2. 4 3
      controller/sanksi.controller.js
  3. 3 2
      utils/cekData.js

+ 20 - 21
controller/graph.controller.js

@@ -258,7 +258,8 @@ exports.excel = handleError(async (req, res) => {
       break
   }
 
-  const { tahun } = req.query
+  const { tahun, penjadwalan, pelaporan, pemeriksaan, delegasi, sanksi } =
+    req.query
 
   berdasarkan_tahun = {
     $and: [
@@ -346,28 +347,26 @@ exports.excel = handleError(async (req, res) => {
       Status: value.sanksi ? 'Sudah ditetapkan' : 'Belum ditetapkan',
     }))
 
-  const buffer = excel.to_excel([
-    {
-      SheetNames: 'Delegasi',
-      data: dataDelegasi,
-    },
-    {
-      SheetNames: 'Pelaporan',
-      data: dataLaporan,
-    },
-    {
+  const data = []
+  if (delegasi === 'true') {
+    data.push({ SheetNames: 'Delegasi', data: dataDelegasi })
+  }
+  if (pelaporan === 'true') {
+    data.push({ SheetNames: 'Pelaporan', data: dataLaporan })
+  }
+  if (penjadwalan === 'true') {
+    data.push({
       SheetNames: 'Penjadwalan',
       data: dataJadwal,
-    },
-    {
-      SheetNames: 'Pemeriksaan',
-      data: dataPemeriksaan,
-    },
-    {
-      SheetNames: 'Sanksi',
-      data: dataSanksi,
-    },
-  ])
+    })
+  }
+  if (pemeriksaan === 'true') {
+    data.push({ SheetNames: 'Pemeriksaan', data: dataPemeriksaan })
+  }
+  if (sanksi === 'true') {
+    data.push({ SheetNames: 'Sanksi', data: dataSanksi })
+  }
+  const buffer = excel.to_excel(data)
 
   res.header(
     'Content-Type',

+ 4 - 3
controller/sanksi.controller.js

@@ -12,8 +12,6 @@ const {
   cekBanyakDataSanksi,
 } = require('../utils/cekData')
 const laporanModel = require('../model/laporan.model')
-const ip = require('ip')
-const osValue = require('../utils/osValue')
 
 exports.create = handleError(async (req, res) => {
   const { no_sanksi, keterangan, from_date, to_date } = req.body
@@ -69,7 +67,10 @@ exports.create = handleError(async (req, res) => {
       keberatan: hariKerja(10),
     },
   })
-  await laporanModel.findByIdAndUpdate(laporan._id, { sanksi: data._id })
+  await laporanModel.findByIdAndUpdate(laporan._id, {
+    sanksi: data._id,
+    aktif: false,
+  })
   await pemantauanModel.create({
     laporan: laporan._id,
     sanksi: data._id,

+ 3 - 2
utils/cekData.js

@@ -136,7 +136,7 @@ exports.cekSatuDataSanksi = async (
     .findOne({ _id: sanksi_id, aktif: true, ...where })
     .populate({
       path: 'laporan',
-      select: 'pt role_data aktif keterangan',
+      select: w.select,
       match: w,
     })
     .populate('dokumen')
@@ -184,8 +184,9 @@ exports.cekBanyakDataSanksi = async (user, where = {}, q = {}) => {
     .find({ aktif: where.aktif || true, ...where })
     .populate({
       path: 'laporan',
-      select: 'pt no_laporan',
+      select: w.select || '-sanksi',
       match: w,
+      populate: ['pelanggaran'],
     })
     .populate('user')
     .populate('pelanggaran')