yazid138 3 vuotta sitten
vanhempi
commit
a541b137d6

+ 20 - 0
controller/laporan.controller.js

@@ -63,6 +63,26 @@ exports.create = handleError(async (req, res) => {
   }
 
   data = await laporanModel.create(data)
+
+  const notif = await notifWA(TEMPLATE_LAPORAN, [
+    {
+      key: '1',
+      value: 'nama',
+      value_text: user.nama,
+    },
+    { key: '2', value: 'pt', value_text: pt[0].nama },
+    { key: '3', value: 'keterangan', value_text: keterangan },
+    { key: '4', value: 'no_laporan', value_text: no_laporan },
+  ])
+
+  let contacts = await kontakModel.find()
+  contacts = contacts.map((e) => e.nama).join(', ')
+  if (notif[0].status == 'success') {
+    await logModel.create({
+      aktivitas: `Server berhasil mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan`,
+    })
+  }
+
   await pemantauanModel.create({
     laporan: data._id,
     action: 'CREATE LAPORAN',

+ 9 - 2
controller/sanksi.controller.js

@@ -88,8 +88,12 @@ exports.create = handleError(async (req, res) => {
 
 exports.getAll = handleError(async (req, res) => {
   const user = req.user
-  const { keberatan, jawaban, banding, cabutSanksi, perbaikan } = req.query
+  const { keberatan, jawaban, banding, cabutSanksi, perbaikan, aktif } =
+    req.query
   const where = {}
+  if (aktif && aktif === 'false') {
+    where.aktif = false
+  }
   if (keberatan === 'true') {
     where['pengajuan.keberatan'] = { $exists: true, $ne: null }
     if (jawaban === 'true') {
@@ -124,13 +128,16 @@ exports.getOne = handleError(async (req, res) => {
   const { sanksi_id } = req.params
 
   const w = {}
-  const { banding } = req.query
+  const { banding, aktif } = req.query
   if (banding === 'true') {
     w.banding = true
     w['pengajuan.keberatan'] = { $exists: true, $ne: null }
     w['jawaban.keberatan'] = { $exists: true, $ne: null }
     w['pengajuan.banding'] = { $exists: true, $ne: null }
   }
+  if (aktif && aktif === 'false') {
+    w.aktif = false
+  }
 
   const sanksi = await cekSatuDataSanksi(res, user, sanksi_id, w)
   if (!sanksi) return

+ 1 - 0
controller/sanksi/cabutSanksi.controller.js

@@ -84,6 +84,7 @@ exports.createJawaban = handleError(async (req, res) => {
       ['pengajuan.cabut_sanksi']: { $exists: true, $ne: null },
     },
     {
+      aktif: false,
       ['jawaban.cabut_sanksi']: {
         status,
         keterangan,

+ 7 - 9
utils/cekData.js

@@ -7,10 +7,9 @@ exports.cekSatuDataLaporan = async (
   res,
   user,
   laporan_id,
-  where = { delegasi: false }
+  where = { delegasi: false, aktif: true }
 ) => {
-  const w = { _id: laporan_id, aktif: true, ...where }
-  if (where.aktif === false) w.aktif = false
+  const w = { _id: laporan_id, aktif: where.aktif || true, ...where }
   switch (user.role.id) {
     case 2020:
       if (!where.delegasi) w.role_data = 'dikti'
@@ -50,8 +49,7 @@ exports.cekSatuDataLaporan = async (
 }
 
 exports.cekBanyakDataLaporan = async (user, where = { delegasi: false }) => {
-  const w = { aktif: true, ...where }
-  if (where.aktif === false) w.aktif = false
+  const w = { aktif: where.aktif || true, ...where }
   switch (user.role.id) {
     case 2020:
       if (!where.delegasi) w.role_data = 'dikti'
@@ -91,7 +89,7 @@ exports.cekSatuDataSanksi = async (
   sanksi_id,
   where = { banding: false }
 ) => {
-  const w = { aktif: true }
+  const w = { aktif: where.aktif || true }
   switch (user.role.id) {
     case 2020:
       if (!where.banding) w.role_data = 'dikti'
@@ -133,7 +131,7 @@ exports.cekSatuDataSanksi = async (
 }
 
 exports.cekBanyakDataSanksi = async (user, where = { banding: false }) => {
-  const w = { aktif: true }
+  const w = {}
   switch (user.role.id) {
     case 2020:
       if (!where.banding) {
@@ -149,14 +147,14 @@ exports.cekBanyakDataSanksi = async (user, where = { banding: false }) => {
       break
   }
   let data = await sanksiModel
-    .find({ aktif: true, ...where })
+    .find({ aktif: where.aktif || true, ...where })
     .populate({
       path: 'laporan',
       select: 'pt',
       match: w,
     })
     .populate('user')
-    .select('-batas_waktu -aktif -dokumen -pelanggaran')
+    .select('-batas_waktu -dokumen -pelanggaran')
     .sort({
       createdAt: -1,
     })