yazid138 %!s(int64=3) %!d(string=hai) anos
pai
achega
a27bf68813

+ 6 - 2
controller/laporan.controller.js

@@ -166,9 +166,10 @@ 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 } = req.query
+  const { no_laporan, pt_id, jadwal, evaluasi, aktif } = 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 (jadwal === 'true') {
     where.jadwal = {
       $exists: true,
@@ -193,7 +194,10 @@ exports.getAll = handleError(async (req, res) => {
 exports.getOne = handleError(async (req, res) => {
   const { id } = req.params
   const user = req.user
-  const data = await cekSatuDataLaporan(res, user, id)
+  const { aktif } = req.query
+  const where = { }
+  if (aktif) where.aktif = aktif === 'true'
+  const data = await cekSatuDataLaporan(res, user, id, where)
   if (!data) return
   return response.success(res, {
     message: 'Berhasil ambil data Laporan',

+ 1 - 1
controller/pemantauan.controller.js

@@ -42,7 +42,7 @@ exports.get = handleError(async (req, res) => {
 exports.getPT = handleError(async (req, res) => {
   const user = req.user
   const data = await pemantauanModel
-    .find({ pt: user.lembaga.id, for_pt: true })
+    .find({ pt_id: user.lembaga.id, for_pt: true })
     .populate({ path: 'user', select: 'nama role isPublic isPrivate' })
     .populate({ path: 'laporan', select: 'no_laporan' })
     .populate({ path: 'sanksi', select: 'no_sanksi' })

+ 2 - 0
utils/cekData.js

@@ -5,6 +5,7 @@ const response = require('../utils/responseHandler')
 
 exports.cekSatuDataLaporan = async (res, user, laporan_id, where = {}) => {
   const w = { _id: laporan_id, aktif: true, ...where }
+  if (where.aktif === false) w.aktif = false
   switch (user.role.id) {
     case 2020:
       w.role_data = 'dikti'
@@ -35,6 +36,7 @@ exports.cekSatuDataLaporan = async (res, user, laporan_id, where = {}) => {
 
 exports.cekBanyakDataLaporan = async (user, where = {}) => {
   const w = { aktif: true, ...where }
+  if (where.aktif === false) w.aktif = false
   switch (user.role.id) {
     case 2020:
       w.role_data = 'dikti'