yazid138 3 سال پیش
والد
کامیت
b5683d8700
1فایلهای تغییر یافته به همراه85 افزوده شده و 76 حذف شده
  1. 85 76
      controller/graph.controller.js

+ 85 - 76
controller/graph.controller.js

@@ -395,100 +395,109 @@ exports.laporanSelesai = handleError(async (req, res) => {
 })
 
 exports.jumlahStatusLaporan = handleError(async (req, res) => {
-  const pembina = await laporanModel.distinct('pt.pembina.nama')
+  let dataPembina = await laporanModel.find()
+
+  dataPembina = [
+    ...new Set(
+      dataPembina.map((e) => `${e.pt.pembina.id};${e.pt.pembina.nama}`)
+    ),
+  ]
+  dataPembina = dataPembina.map((e) => ({
+    id: e.split(';')[0],
+    name: e.split(';')[1],
+  }))
 
   let data = await Promise.all(
-    pembina.map(async (e) => {
+    dataPembina.map(async (e) => {
       return {
-        [e]: {
-          jumlah_jadwal_evaluasi: await laporanModel
+        pembina: e,
+        jumlah_jadwal_evaluasi: await laporanModel
+          .find({
+            jadwal: {
+              $ne: null,
+              $exists: true,
+            },
+            'pt.pembina.id': e.id,
+          })
+          .count(),
+        jumlah_pemeriksaan: await laporanModel
+          .find({
+            evaluasi: {
+              $ne: [],
+              $exists: true,
+            },
+            'pt.pembina.id': e.id,
+          })
+          .count(),
+        jumlah_sanksi: await laporanModel
+          .find({
+            sanksi: {
+              $ne: null,
+              $exists: true,
+            },
+            'pt.pembina.id': e.id,
+          })
+          .count(),
+        jumlah_keberatan: (
+          await sanksiModel
+            .find({
+              'pengajuan.keberatan': {
+                $ne: null,
+                $exists: true,
+              },
+            })
+            .populate({
+              path: 'laporan',
+              match: {
+                'pt.pembina.id': e.id,
+              },
+            })
+        ).filter((e) => e.laporan != null).length,
+        jumlah_banding: (
+          await sanksiModel
             .find({
-              jadwal: {
+              'pengajuan.banding': {
                 $ne: null,
                 $exists: true,
               },
-              'pt.pembina.nama': e,
             })
-            .count(),
-          jumlah_pemeriksaan: await laporanModel
+            .populate({
+              path: 'laporan',
+              match: {
+                'pt.pembina.id': e.id,
+              },
+            })
+        ).filter((e) => e.laporan != null).length,
+        jumlah_pemantauan_perbaikan: (
+          await sanksiModel
             .find({
-              evaluasi: {
+              perbaikan: {
                 $ne: [],
                 $exists: true,
               },
-              'pt.pembina.nama': e,
             })
-            .count(),
-          jumlah_sanksi: await laporanModel
+            .populate({
+              path: 'laporan',
+              match: {
+                'pt.pembina.id': e.id,
+              },
+            })
+        ).filter((e) => e.laporan != null).length,
+        jumlah_pencabutan_sanksi: (
+          await sanksiModel
             .find({
-              sanksi: {
+              'pengajuan.cabut_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,
-        },
+            .populate({
+              path: 'laporan',
+              match: {
+                'pt.pembina.id': e.id,
+              },
+            })
+        ).filter((e) => e.laporan != null).length,
       }
     })
   )