andi 3 years ago
parent
commit
383612d11e

+ 34 - 23
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',
@@ -395,7 +394,9 @@ exports.laporanSelesai = handleError(async (req, res) => {
 })
 
 exports.jumlahStatusLaporan = handleError(async (req, res) => {
-  let dataPembina = await laporanModel.find()
+  let dataPembina = await laporanModel.find({
+    aktif: true,
+  })
   const user = req.user
 
   dataPembina = [
@@ -425,6 +426,7 @@ exports.jumlahStatusLaporan = handleError(async (req, res) => {
         ).filter((e) => e.laporan != null),
         jumlah_jadwal_evaluasi: await laporanModel
           .find({
+            aktif: true,
             jadwal: {
               $ne: null,
               $exists: true,
@@ -434,8 +436,12 @@ exports.jumlahStatusLaporan = handleError(async (req, res) => {
           .count(),
         jumlah_pemeriksaan: await laporanModel
           .find({
+            aktif: true,
             evaluasi: {
-              $ne: [],
+              $ne: null,
+              $not: {
+                $size: 0,
+              },
               $exists: true,
             },
             'pt.pembina.id': e.id,
@@ -443,6 +449,7 @@ exports.jumlahStatusLaporan = handleError(async (req, res) => {
           .count(),
         jumlah_sanksi: await laporanModel
           .find({
+            aktif: true,
             sanksi: {
               $ne: null,
               $exists: true,
@@ -453,6 +460,7 @@ exports.jumlahStatusLaporan = handleError(async (req, res) => {
         jumlah_keberatan: (
           await sanksiModel
             .find({
+              aktif: true,
               'pengajuan.keberatan': {
                 $ne: null,
                 $exists: true,
@@ -468,6 +476,7 @@ exports.jumlahStatusLaporan = handleError(async (req, res) => {
         jumlah_banding: (
           await sanksiModel
             .find({
+              aktif: true,
               'pengajuan.banding': {
                 $ne: null,
                 $exists: true,
@@ -483,6 +492,7 @@ exports.jumlahStatusLaporan = handleError(async (req, res) => {
         jumlah_pemantauan_perbaikan: (
           await sanksiModel
             .find({
+              aktif: true,
               perbaikan: {
                 $ne: [],
                 $exists: true,
@@ -498,6 +508,7 @@ exports.jumlahStatusLaporan = handleError(async (req, res) => {
         jumlah_pencabutan_sanksi: (
           await sanksiModel
             .find({
+              aktif: true,
               'pengajuan.cabut_sanksi': {
                 $ne: null,
                 $exists: true,

+ 89 - 15
controller/laporan.controller.js

@@ -444,28 +444,102 @@ exports.jumlahLaporan = handleError(async (req, res) => {
 
 exports.laporanByPembina = handleError(async (req, res) => {
   const { idPembina } = req.params
+  const {
+    penjadwalan,
+    pemeriksaan,
+    sanksi,
+    keberatan,
+    banding,
+    perbaikan,
+    cabutSanksi,
+  } = req.query
   const user = req.user
+  const where = {}
+  let isLaporan = true
+  let isSanksi = true
+
+  if (penjadwalan === 'true') {
+    where.jadwal = {
+      $exists: true,
+      $ne: null,
+    }
+    isLaporan = true
+    isSanksi = false
+  }
+  if (pemeriksaan === 'true') {
+    where.evaluasi = {
+      $exists: true,
+      $ne: null,
+      $not: {
+        $size: 0,
+      },
+    }
+    isLaporan = true
+    isSanksi = false
+  }
+  if (sanksi === 'true') {
+    where.sanksi = {
+      $exists: true,
+      $ne: null,
+    }
+    isLaporan = false
+    isSanksi = true
+  }
+  if (keberatan === 'true') {
+    where['pengajuan.keberatan'] = { $exists: true, $ne: null }
+    isLaporan = false
+    isSanksi = true
+  }
+  if (banding === 'true') {
+    where.banding = true
+    where['pengajuan.keberatan'] = { $exists: true, $ne: null }
+    where['jawaban.keberatan'] = { $exists: true, $ne: null }
+    where['pengajuan.banding'] = { $exists: true, $ne: null }
+    isLaporan = false
+    isSanksi = true
+  }
+  if (cabutSanksi === 'true') {
+    where.perbaikan = {
+      $exists: true,
+      $ne: null,
+      $not: {
+        $size: 0,
+      },
+    }
+    isLaporan = false
+    isSanksi = true
+  }
+  if (perbaikan === 'true') {
+    where['jawaban.banding'] = { $exists: true, $ne: null }
+    isLaporan = false
+    isSanksi = true
+  }
 
-  const [laporan, sanksi] = await Promise.all([
+  const [laporan, dataSanksi] = await Promise.all([
     (async () =>
-      await cekBanyakDataLaporan(user, {
-        'pt.pembina.id': idPembina,
-        all: true,
-      }))(),
+      isLaporan
+        ? await cekBanyakDataLaporan(user, {
+            'pt.pembina.id': idPembina,
+            all: true,
+            ...where,
+          })
+        : [])(),
     (async () =>
-      (
-        await cekBanyakDataSanksi(
-          user,
-          { all: true },
-          {
-            ['pt.pembina.id']: idPembina,
-          }
-        )
-      ).filter((e) => e.laporan != null))(),
+      isSanksi
+        ? (
+            await cekBanyakDataSanksi(
+              user,
+              { all: true, ...where },
+              {
+                ['pt.pembina.id']: idPembina,
+              }
+            )
+          ).filter((e) => e.laporan != null)
+        : [])(),
   ])
 
   return response.success(res, {
     message: 'berhasil get laporan by pembina',
-    data: { laporan, sanksi },
+    data: { laporan, sanksi: dataSanksi },
   })
 })

+ 23 - 7
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,
@@ -106,7 +107,8 @@ exports.getAll = handleError(async (req, res) => {
     if (jawaban === 'true') {
       where['jawaban.keberatan'] = { $exists: true, $ne: null }
     }
-  } else if (banding === 'true') {
+  }
+  if (banding === 'true') {
     where.banding = true
     where['pengajuan.keberatan'] = { $exists: true, $ne: null }
     where['jawaban.keberatan'] = { $exists: true, $ne: null }
@@ -114,15 +116,18 @@ exports.getAll = handleError(async (req, res) => {
     if (jawaban === 'true') {
       where['jawaban.banding'] = { $exists: true, $ne: null }
     }
-  } else if (cabutSanksi === 'true') {
+  }
+  if (cabutSanksi === 'true') {
     where.perbaikan = { $exists: true, $ne: [] }
     if (jawaban === 'true') {
       where['pengajuan.cabut_sanksi'] = { $exists: true, $ne: null }
       // where['jawaban.cabut_sanksi'] = { $exists: true, $ne: null }
     }
-  } else if (perbaikan === 'true') {
+  }
+  if (perbaikan === 'true') {
     where['jawaban.banding'] = { $exists: true, $ne: null }
-  } else if (delegasi === 'true') {
+  }
+  if (delegasi === 'true') {
     where.delegasi = true
   }
   const data = await cekBanyakDataSanksi(user, where)
@@ -167,6 +172,7 @@ exports.editTmt = handleError(async (req, res) => {
   const user = req.user
   const { id } = req.params
   const { from_date, to_date } = req.body
+  const files = req.files
 
   const sanksi = await cekSatuDataSanksi(res, user, id)
   if (!sanksi) return
@@ -177,11 +183,21 @@ exports.editTmt = handleError(async (req, res) => {
   })
   if (!isValid) return
 
+  if (!files.length) {
+    return response.error(res, {
+      message: 'dokumen harus ada',
+    })
+  }
+
+  const dokumen = await addManyDokumen(files)
+  const dokumen_id = dokumen.map((e) => e._id)
+
   const data = await sanksiModel.findByIdAndUpdate(sanksi._id, {
     masa_berlaku: {
       from_date,
       to_date,
     },
+    'pengajuan.update_tmt': { dokumen: dokumen_id },
   })
 
   await pemantauanModel.create({

+ 1 - 1
middleware/role.js

@@ -7,7 +7,7 @@ module.exports = (role) => async (req, res, next) => {
     (typeof role == 'number' && user.role.id !== role) ||
     (typeof role == 'object' && !role.includes(user.role.id))
   ) {
-    response.error(res, {
+    return response.error(res, {
       message: 'Forbidden',
       code: 403,
     })

+ 11 - 0
model/sanksi.model.js

@@ -105,6 +105,17 @@ module.exports = mongoose.model(
           },
           { timestamps: true }
         ),
+        update_tmt: new Schema(
+          {
+            dokumen: [
+              {
+                type: Types.ObjectId,
+                ref: dokumen,
+              },
+            ],
+          },
+          { timestamps: true }
+        ),
       },
       perbaikan: [
         new Schema(

+ 11 - 0
model/sanksi2.model.js

@@ -103,6 +103,17 @@ module.exports = mongoose.model(
           },
           { timestamps: true }
         ),
+        update_tmt: new Schema(
+          {
+            dokumen: [
+              {
+                type: Types.ObjectId,
+                ref: dokumen,
+              },
+            ],
+          },
+          { timestamps: true }
+        ),
       },
       perbaikan: [
         new Schema(

+ 6 - 1
routes/v1/sanksi/index.js

@@ -9,7 +9,12 @@ router.post(
   handleDokumen.array('dokumen'),
   sanksi.create
 )
-router.put('/tmt/update/:id', roleId([2020, 2021, 2023]), sanksi.editTmt)
+router.put(
+  '/tmt/update/:id',
+  roleId([2020, 2021, 2023]),
+  handleDokumen.array('dokumen'),
+  sanksi.editTmt
+)
 router.get('/', sanksi.getAll)
 router.get('/:sanksi_id', sanksi.getOne)
 

+ 4 - 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')
@@ -145,6 +145,7 @@ exports.cekSatuDataSanksi = async (
     .populate('pengajuan.keberatan.dokumen')
     .populate('jawaban.keberatan.dokumen')
     .populate('pengajuan.banding.dokumen')
+    .populate('pengajuan.update_tmt.dokumen')
     .populate('jawaban.banding.dokumen')
     .populate('pengajuan.cabut_sanksi.dokumen')
     .populate('jawaban.cabut_sanksi.dokumen')
@@ -183,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')