Browse Source

pemantauan dari dikti tampil semua laporan

yazid138 3 years ago
parent
commit
e379ac2735

+ 8 - 4
controller/laporan.controller.js

@@ -297,11 +297,14 @@ exports.public = handleError(async (req, res) => {
 exports.getAll = handleError(async (req, res) => {
   const user = req.user
   const where = {}
-  const { no_laporan, pt_id, jadwal, evaluasi, aktif, delegasi } = req.query
+  const { no_laporan, pt_id, jadwal, evaluasi, aktif, delegasi, all } =
+    req.query
   if (no_laporan) where.no_laporan = no_laporan
   if (pt_id) where['pt.id'] = pt_id
   if (aktif) where.aktif = aktif === 'true'
-  if (delegasi) where.delegasi = delegasi === 'true'
+  if (all) where.all = true
+  else if (delegasi) where.delegasi = delegasi === 'true'
+
   if (jadwal === 'true') {
     where.jadwal = {
       $exists: true,
@@ -326,10 +329,11 @@ exports.getAll = handleError(async (req, res) => {
 exports.getOne = handleError(async (req, res) => {
   const { id } = req.params
   const user = req.user
-  const { aktif, delegasi } = req.query
+  const { aktif, delegasi, all } = req.query
   const where = {}
   if (aktif) where.aktif = aktif === 'true'
-  if (delegasi) where.delegasi = delegasi === 'true'
+  if (all) where.all = true
+  else if (delegasi) where.delegasi = delegasi === 'true'
   const data = await cekSatuDataLaporan(res, user, id, where)
   if (!data) return
   return response.success(res, {

+ 2 - 1
controller/pemantauan.controller.js

@@ -9,7 +9,7 @@ const userModel = require('../model/user.model')
 exports.get = handleError(async (req, res) => {
   const user = req.user
   const { laporan_id } = req.params
-  const { delegasi, asc } = req.query
+  const { delegasi, asc, all } = req.query
   // const pt = await axios.get(
   //   `https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${pt_id}`
   // )
@@ -25,6 +25,7 @@ exports.get = handleError(async (req, res) => {
   // }
   const where = {}
   if (delegasi) where.delegasi = true
+  if (all) where.all = true
   const laporan = await cekSatuDataLaporan(res, user, laporan_id, where)
   if (!laporan) return
 

+ 11 - 7
controller/sanksi/cabutSanksi.controller.js

@@ -68,14 +68,18 @@ exports.createJawaban = handleError(async (req, res) => {
   })
   if (!isValid) return
 
-  const files = req.files
-  if (!files?.length) {
-    return response.error(res, {
-      message: 'dokumen harus ada',
-    })
+  let dokumen_id = null
+  if (req.body.status === 'Diterima') {
+    const files = req.files
+    if (!files?.length) {
+      return response.error(res, {
+        message: 'dokumen harus ada',
+      })
+    }
+    const dokumen = await addManyDokumen(files)
+    dokumen_id = dokumen.map((e) => e._id)
   }
-  const dokumen = await addManyDokumen(files)
-  const dokumen_id = dokumen.map((e) => e._id)
+
   const { status, keterangan } = req.body
   const data = await sanksiModel.findOneAndUpdate(
     {

+ 6 - 4
utils/cekData.js

@@ -12,7 +12,8 @@ exports.cekSatuDataLaporan = async (
   const w = { _id: laporan_id, aktif: where.aktif || true, ...where }
   switch (user.role.id) {
     case 2020:
-      if (!where.delegasi) w.role_data = 'dikti'
+      if (where.all) break
+      else if (!where.delegasi) w.role_data = 'dikti'
       else {
         w.role_data = 'lldikti'
         w.role_asal = 'dikti'
@@ -37,8 +38,8 @@ exports.cekSatuDataLaporan = async (
     .populate({ path: 'user', populate: 'foto' })
     .populate({ path: 'pelanggaran', select: 'pelanggaran' })
     .populate('dokumen')
-    .populate({path: 'evaluasi', populate: ['user', 'dokumen']})
-    // .populate('evaluasi.user')
+    .populate({ path: 'evaluasi', populate: ['user', 'dokumen'] })
+  // .populate('evaluasi.user')
   if (!laporan) {
     response.error(res, {
       message: 'laporan_id tidak ada',
@@ -53,7 +54,8 @@ exports.cekBanyakDataLaporan = async (user, where = { delegasi: false }) => {
   const w = { aktif: where.aktif || true, ...where }
   switch (user.role.id) {
     case 2020:
-      if (!where.delegasi) w.role_data = 'dikti'
+      if (where.all) break
+      else if (!where.delegasi) w.role_data = 'dikti'
       else {
         w.role_data = 'lldikti'
         w.role_asal = 'dikti'