andi 3 роки тому
батько
коміт
f637ba8a10
2 змінених файлів з 107 додано та 0 видалено
  1. 106 0
      controller/graph.controller.js
  2. 1 0
      routes/v1/graph.routes.js

+ 106 - 0
controller/graph.controller.js

@@ -7,6 +7,7 @@ const {
   cekBanyakDataSanksi,
 } = require('../utils/cekData')
 const laporanModel = require('../model/laporan.model')
+const sanksiModel = require('../model/sanksi.model')
 const moment = require('moment')
 
 exports.laporan = handleError(async (req, res) => {
@@ -392,3 +393,108 @@ exports.laporanSelesai = handleError(async (req, res) => {
     data,
   })
 })
+
+exports.jumlahStatusLaporan = handleError(async (req, res) => {
+  const pembina = await laporanModel.distinct('pt.pembina.nama')
+
+  let data = await Promise.all(
+    pembina.map(async (e) => {
+      return {
+        [e]: {
+          jumlah_jadwal_evaluasi: await laporanModel
+            .find({
+              jadwal: {
+                $ne: null,
+                $exists: true,
+              },
+              'pt.pembina.nama': e,
+            })
+            .count(),
+          jumlah_pemeriksaan: await laporanModel
+            .find({
+              evaluasi: {
+                $ne: [],
+                $exists: true,
+              },
+              'pt.pembina.nama': e,
+            })
+            .count(),
+          jumlah_sanksi: await laporanModel
+            .find({
+              sanksi: {
+                $ne: null,
+                $exists: true,
+              },
+              'pt.pembina.nama': e,
+            })
+            .count(),
+          jumlah_keberatan: (
+            await sanksiModel
+              .find({
+                'pengajuan.keberatan': {
+                  $ne: null,
+                  $exists: true,
+                },
+              })
+              .populate({
+                path: 'laporan',
+                match: {
+                  'pt.pembina.nama': e,
+                },
+              })
+          ).filter((e) => e.laporan != null).length,
+          jumlah_banding: (
+            await sanksiModel
+              .find({
+                'pengajuan.banding': {
+                  $ne: null,
+                  $exists: true,
+                },
+              })
+              .populate({
+                path: 'laporan',
+                match: {
+                  'pt.pembina.nama': e,
+                },
+              })
+          ).filter((e) => e.laporan != null).length,
+          jumlah_pemantauan_perbaikan: (
+            await sanksiModel
+              .find({
+                perbaikan: {
+                  $ne: [],
+                  $exists: true,
+                },
+              })
+              .populate({
+                path: 'laporan',
+                match: {
+                  'pt.pembina.nama': e,
+                },
+              })
+          ).filter((e) => e.laporan != null).length,
+          jumlah_pencabutan_sanksi: (
+            await sanksiModel
+              .find({
+                'pengajuan.cabut_sanksi': {
+                  $ne: null,
+                  $exists: true,
+                },
+              })
+              .populate({
+                path: 'laporan',
+                match: {
+                  'pt.pembina.nama': e,
+                },
+              })
+          ).filter((e) => e.laporan != null).length,
+        },
+      }
+    })
+  )
+
+  return response.success(res, {
+    message: 'Berhasil menganalisis data',
+    data,
+  })
+})

+ 1 - 0
routes/v1/graph.routes.js

@@ -10,6 +10,7 @@ router.get(
   roleId([2020, 2021, 2023]),
   graph.laporanSelesai
 )
+router.get('/jumlahStatusLaporan', graph.jumlahStatusLaporan)
 router.get('/:token/:nama_file', auth, roleId([2020, 2021, 2023]), graph.excel)
 
 module.exports = router