|
|
@@ -1,21 +1,22 @@
|
|
|
-const axios = require('../utils/axios')
|
|
|
-const handleError = require('../utils/handleError')
|
|
|
-const response = require('../utils/responseHandler')
|
|
|
-const laporanModel = require('../model/laporan.model')
|
|
|
-const pelanggaranModel = require('../model/pelanggaran.model')
|
|
|
-const pemantauanModel = require('../model/pemantauan.model')
|
|
|
-const { validate } = require('../utils/validation')
|
|
|
-const { notifWA } = require('../utils/notifFunction')
|
|
|
-const { addManyDokumen } = require('../utils/dokumenFunction')
|
|
|
-const userModel = require('../model/user.model')
|
|
|
+const axios = require('../../utils/axios')
|
|
|
+const handleError = require('../../utils/v1/handleError')
|
|
|
+const response = require('../../utils/responseHandler')
|
|
|
+const laporanModel = require('../../model/laporan.model')
|
|
|
+const pelanggaranModel = require('../../model/pelanggaran.model')
|
|
|
+const pemantauanModel = require('../../model/pemantauan.model')
|
|
|
+const { validate } = require('../../utils/v1/validation')
|
|
|
+const { notifWA } = require('../../utils/v1/notifFunction')
|
|
|
+const { addManyDokumen } = require('../../utils/dokumenFunction')
|
|
|
+const userModel = require('../../model/user.model')
|
|
|
const {
|
|
|
cekSatuDataLaporan,
|
|
|
cekBanyakDataLaporan,
|
|
|
cekBanyakDataSanksi,
|
|
|
-} = require('../utils/cekData')
|
|
|
-const { TEMPLATE_LAPORAN } = require('../utils/constanta')
|
|
|
-const logModel = require('../model/log.model')
|
|
|
-const kontakModel = require('../model/kontak.model')
|
|
|
+} = require('../../utils/v1/cekData')
|
|
|
+const { TEMPLATE_LAPORAN, PELAPORAN, CREATE_LAPORAN, DIKTI, LLDIKTI, DITUTUP, DELEGASI, TRUE, FALSE } = require('../../utils/constanta')
|
|
|
+const logModel = require('../../model/log.model')
|
|
|
+const kontakModel = require('../../model/kontak.model')
|
|
|
+const sanksiModel = require('../../model/sanksi.model')
|
|
|
const { isValidObjectId } = require('mongoose')
|
|
|
|
|
|
exports.create = handleError(async (req, res) => {
|
|
|
@@ -62,9 +63,11 @@ exports.create = handleError(async (req, res) => {
|
|
|
pt: pt[0],
|
|
|
pelanggaran: pelanggaran_id,
|
|
|
keterangan,
|
|
|
- role_data: user.role.id === 2020 ? 'dikti' : 'lldikti',
|
|
|
- role_asal: user.role.id === 2020 ? 'dikti' : 'lldikti',
|
|
|
+ role_data: user.role.id === 2021 ? LLDIKTI : DIKTI,
|
|
|
+ role_asal: user.role.id === 2021 ? LLDIKTI : DIKTI,
|
|
|
level: 2,
|
|
|
+ step: [PELAPORAN],
|
|
|
+ flag: PELAPORAN,
|
|
|
}
|
|
|
|
|
|
data = await laporanModel.create(data)
|
|
|
@@ -100,7 +103,7 @@ exports.create = handleError(async (req, res) => {
|
|
|
|
|
|
await pemantauanModel.create({
|
|
|
laporan: data._id,
|
|
|
- action: 'CREATE LAPORAN',
|
|
|
+ action: CREATE_LAPORAN,
|
|
|
pt_id: pt[0].id,
|
|
|
user: user._id,
|
|
|
keterangan: 'Membuat Laporan',
|
|
|
@@ -346,7 +349,7 @@ exports.getLaporanByNoLaporanAndId = 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, all, sanksi } =
|
|
|
+ const { no_laporan, pt_id, jadwal, evaluasi, aktif, delegasi, all, sanksi, tuntas } =
|
|
|
req.query
|
|
|
if (no_laporan) where.no_laporan = no_laporan
|
|
|
if (pt_id) where['pt.id'] = pt_id
|
|
|
@@ -372,8 +375,41 @@ exports.getAll = handleError(async (req, res) => {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
}
|
|
|
+ } else if (tuntas === 'true') {
|
|
|
+ let dataLaporan = (await cekBanyakDataLaporan(user, { aktif: 'empty', all: true, }, {lean: true}))
|
|
|
+ .filter(e => e.tuntas?.keterangan || e.aktif === false || e.aktif === true && e.sanksi?.jawaban?.cabut_sanksi?.status === 'Diterima' || e.sanksi?.aktif === false && !e.sanksi?.masa_berlaku?.from_date)
|
|
|
+ .map(e => ({ ...e, status: e.aktif === false || e.tuntas?.keterangan ? 'Ditutup' : e.sanksi?.jawaban?.cabut_sanksi?.status === 'Diterima' ? 'Diterima' : !e.sanksi?.masa_berlaku ? 'Selesai' : 'Ditutup' }))
|
|
|
+ // let dataSanksi = await cekBanyakDataSanksi(user, {
|
|
|
+ // aktif: false, 'jawaban.cabut_sanksi.status': 'Diterima'
|
|
|
+ // })
|
|
|
+ // const w = {}
|
|
|
+ // switch (user.role.id) {
|
|
|
+ // case 2020:
|
|
|
+ // w.$or = [{
|
|
|
+ // role_asal: DIKTI
|
|
|
+ // }, {
|
|
|
+ // role_data: DIKTI
|
|
|
+ // }]
|
|
|
+ // break
|
|
|
+ // case 2021:
|
|
|
+ // w.$or = [{
|
|
|
+ // role_asal: LLDIKTI
|
|
|
+ // }, {
|
|
|
+ // role_data: LLDIKTI
|
|
|
+ // }]
|
|
|
+ // w['pt.pembina.id'] = user.lembaga.id
|
|
|
+ // break
|
|
|
+ // }
|
|
|
+ // const dataLaporan = (await laporanModel.find(w).populate('sanksi').lean())
|
|
|
+ // .filter(e => e.aktif === false || e.tuntas?.keterangan || e.sanksi?.jawaban?.cabut_sanksi === 'Diterima' && e.sanksi?.aktif === false || !e.sanksi?.masa_berlaku)
|
|
|
+ // .map(e => ({...e, status: e.aktif === false || e.tuntas?.keterangan ? 'Ditutup' : e.sanksi?.jawaban?.cabut_sanksi === 'Diterima'? 'Diterima' : !e.sanksi?.masa_berlaku ? 'Selesai' : 'Ditutup'}))
|
|
|
+ return response.success(res, {
|
|
|
+ message: 'Berhasil ambil data laporan dan sanksi tuntas dan ditutup',
|
|
|
+ data: dataLaporan
|
|
|
+ })
|
|
|
}
|
|
|
- let data = await cekBanyakDataLaporan(user, where)
|
|
|
+
|
|
|
+ let data = (await cekBanyakDataLaporan(user, where)).filter(e => !e.sanksi || e.sanksi.aktif === true)
|
|
|
return response.success(res, {
|
|
|
message: 'Berhasil ambil data laporan',
|
|
|
data,
|
|
|
@@ -385,10 +421,10 @@ exports.getOne = handleError(async (req, res) => {
|
|
|
const user = req.user
|
|
|
const { aktif, delegasi, all } = req.query
|
|
|
const where = {}
|
|
|
- if (aktif) where.aktif = aktif === 'true'
|
|
|
+ if (aktif) where.aktif = aktif === TRUE
|
|
|
if (all) where.all = true
|
|
|
- else if (delegasi) where.delegasi = delegasi === 'true'
|
|
|
- const data = await cekSatuDataLaporan(res, user, id, where)
|
|
|
+ else if (delegasi) where.delegasi = delegasi === TRUE
|
|
|
+ const data = await cekSatuDataLaporan(res, user, id, { normal: true })
|
|
|
if (!data) return
|
|
|
return response.success(res, {
|
|
|
message: 'Berhasil ambil data Laporan',
|
|
|
@@ -404,8 +440,8 @@ exports.update = handleError(async (req, res) => {
|
|
|
if (!laporan) return
|
|
|
|
|
|
const isValid = validate(res, req.body, {
|
|
|
- change_role: { type: 'string', optional: true, enum: ['true', 'false'] },
|
|
|
- aktif: { type: 'string', optional: true, enum: ['true', 'false'] },
|
|
|
+ change_role: { type: 'string', optional: true, enum: [TRUE, FALSE] },
|
|
|
+ aktif: { type: 'string', optional: true, enum: [TRUE, FALSE] },
|
|
|
keterangan: 'string',
|
|
|
})
|
|
|
if (!isValid) return
|
|
|
@@ -415,10 +451,10 @@ exports.update = handleError(async (req, res) => {
|
|
|
let alasan = ''
|
|
|
const { change_role, aktif } = req.body
|
|
|
const keterangan2 = req.body.keterangan
|
|
|
- if (change_role === 'true') {
|
|
|
+ if (change_role === TRUE) {
|
|
|
+ data.flag = DELEGASI
|
|
|
data.role_data = user.role.id === 2020 ? 'lldikti' : 'dikti'
|
|
|
- keterangan = `Laporan didelegasi ke ${user.role.id === 2020 ? 'LLDIKTI' : 'DIKTI'
|
|
|
- }`
|
|
|
+ keterangan = `Laporan didelegasi ke ${user.role.id === 2020 ? 'LLDIKTI' : 'DIKTI'}`
|
|
|
alasan = keterangan2
|
|
|
data.alasan_delegasi = keterangan2
|
|
|
// if (laporan.jadwal) {
|
|
|
@@ -439,6 +475,7 @@ exports.update = handleError(async (req, res) => {
|
|
|
} else {
|
|
|
keterangan = `Laporan ditutup`
|
|
|
alasan = keterangan2
|
|
|
+ data.flag = DITUTUP
|
|
|
data.tuntas = {
|
|
|
keterangan: keterangan2,
|
|
|
dokumen: dokumen_id,
|
|
|
@@ -506,9 +543,12 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
banding,
|
|
|
perbaikan,
|
|
|
cabutSanksi,
|
|
|
+ delegasi,
|
|
|
+ ditutup,
|
|
|
+ diterima
|
|
|
} = req.query
|
|
|
- const user = req.user
|
|
|
- const where = {}
|
|
|
+ let where = {}
|
|
|
+ let where2 = {}
|
|
|
let isLaporan = true
|
|
|
let isSanksi = false
|
|
|
|
|
|
@@ -540,20 +580,25 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
isSanksi = true
|
|
|
}
|
|
|
if (keberatan === 'true') {
|
|
|
- where['pengajuan.keberatan'] = { $exists: true, $ne: null }
|
|
|
+ where2['pengajuan.keberatan'] = { $exists: true, $ne: null }
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
if (banding === 'true') {
|
|
|
- where.banding = true
|
|
|
- where['pengajuan.keberatan'] = { $exists: true, $ne: null }
|
|
|
- where['jawaban.keberatan'] = { $exists: true, $ne: null }
|
|
|
- where['pengajuan.banding'] = { $exists: true, $ne: null }
|
|
|
+ where2['pengajuan.banding'] = { $exists: true, $ne: null }
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
if (cabutSanksi === 'true') {
|
|
|
- where.perbaikan = {
|
|
|
+ where2['pengajuan.cabut_sanksi'] = {
|
|
|
+ $exists: true,
|
|
|
+ $ne: null,
|
|
|
+ }
|
|
|
+ isLaporan = false
|
|
|
+ isSanksi = true
|
|
|
+ }
|
|
|
+ if (perbaikan === 'true') {
|
|
|
+ where2.perbaikan = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
$not: {
|
|
|
@@ -563,51 +608,119 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
- if (perbaikan === 'true') {
|
|
|
- where['jawaban.banding'] = { $exists: true, $ne: null }
|
|
|
+ if(delegasi === 'true') {
|
|
|
+ where = {
|
|
|
+ role_asal: 'dikti',
|
|
|
+ role_data: 'lldikti'
|
|
|
+ }
|
|
|
+ isLaporan = true
|
|
|
+ isSanksi = false
|
|
|
+ }
|
|
|
+ if(ditutup === 'true') {
|
|
|
+ where.aktif = false
|
|
|
+ isLaporan = true
|
|
|
+ isSanksi = false
|
|
|
+ }
|
|
|
+ if(diterima === 'true') {
|
|
|
+ where2 = {
|
|
|
+ 'jawaban.cabut_sanksi.status': 'Diterima',
|
|
|
+ aktif: false
|
|
|
+ }
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
|
|
|
- const [laporan, dataSanksi] = await Promise.all([
|
|
|
- (async () => {
|
|
|
- let laporan = isLaporan
|
|
|
- ? await cekBanyakDataLaporan(user, {
|
|
|
- 'pt.pembina.id': idPembina,
|
|
|
- all: true,
|
|
|
- ...where,
|
|
|
- }, {lean: true})
|
|
|
- : []
|
|
|
- if (!laporan.length) return []
|
|
|
- laporan = laporan.map(e => {
|
|
|
+ let laporan = []
|
|
|
+ if (isSanksi) {
|
|
|
+ laporan = (await laporanModel.find({ ...where, 'pt.pembina.id': idPembina }).lean().populate({ path: 'sanksi', match: where2 }).lean())
|
|
|
+ .filter(e => e.sanksi)
|
|
|
+ .map(e => {
|
|
|
let step = 'Pelaporan'
|
|
|
if (e.jadwal && !e.evaluasi.length) step = 'Penjadwalan'
|
|
|
else if (e.evaluasi.length && !e.sanksi) step = 'Pemeriksaan'
|
|
|
else if (e.sanksi?.pengajuan?.cabut_sanksi) step = 'Cabut Sanksi'
|
|
|
else if (e.sanksi?.pengajuan?.keberatan && !e.sanksi?.pengajuan?.banding) step = 'Keberatan'
|
|
|
+ else if (e.sanksi?.aktif === false && !e.sanksi?.masa_berlaku?.from_date) step = 'Selesai'
|
|
|
+ else if (e.sanksi?.aktif === false && e.jawaban?.cabut_sanksi?.status === 'Diterima') step = 'Diterima'
|
|
|
else if (e.sanksi?.pengajuan?.banding) step = 'Banding'
|
|
|
else if (e.sanksi) step = 'Sanksi'
|
|
|
return { ...e, step }
|
|
|
})
|
|
|
- return laporan
|
|
|
- })(),
|
|
|
- (async () =>
|
|
|
- isSanksi
|
|
|
- ? (
|
|
|
- await cekBanyakDataSanksi(
|
|
|
- user,
|
|
|
- { all: true, ...where },
|
|
|
- {
|
|
|
- ['pt.pembina.id']: idPembina,
|
|
|
- }
|
|
|
- )
|
|
|
- ).filter((e) => e.laporan != null)
|
|
|
- : [])(),
|
|
|
- ])
|
|
|
+ } else if (isLaporan) {
|
|
|
+ laporan = (await laporanModel.find({ ...where, 'pt.pembina.id': idPembina }).lean().populate({ path: 'sanksi', match: where2 }).lean())
|
|
|
+ .map(e => {
|
|
|
+ let step = 'Pelaporan'
|
|
|
+ if (e.jadwal && !e.evaluasi.length) step = 'Penjadwalan'
|
|
|
+ else if (e.evaluasi.length && !e.sanksi) step = 'Pemeriksaan'
|
|
|
+ else if (e.sanksi?.pengajuan?.cabut_sanksi) step = 'Cabut Sanksi'
|
|
|
+ else if (e.sanksi?.pengajuan?.keberatan && !e.sanksi?.pengajuan?.banding) step = 'Keberatan'
|
|
|
+ else if (e.sanksi?.aktif === false && !e.sanksi?.masa_berlaku?.from_date) step = 'Selesai'
|
|
|
+ else if (e.sanksi?.aktif === false && e.jawaban?.cabut_sanksi?.status === 'Diterima') step = 'Diterima'
|
|
|
+ else if (e.sanksi?.pengajuan?.banding) step = 'Banding'
|
|
|
+ else if (e.sanksi) step = 'Sanksi'
|
|
|
+ return { ...e, step }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (isSanksi === true) {
|
|
|
+ // laporan = (await sanksiModel.find(where).populate({path: 'laporan', match: {'pt.pembina.id': idPembina} }).lean())
|
|
|
+ // .filter(e => e.laporan)
|
|
|
+ // .map(e => {
|
|
|
+ // let step = 'Sanksi'
|
|
|
+ // if (e.pengajuan?.cabut_sanksi) step = 'Cabut Sanksi'
|
|
|
+ // else if (e.pengajuan?.keberatan && !e.sanksi?.pengajuan?.banding) step = 'Keberatan'
|
|
|
+ // else if (e.pengajuan?.banding) step = 'Banding'
|
|
|
+ // else if (e.aktif === false && !e.masa_berlaku?.from_date) step = 'Selesai'
|
|
|
+ // else if (e.aktif === false && e.jawaban?.cabut_sanksi?.status === 'Diterima') step = 'Diterima'
|
|
|
+ // return { ...e, step }
|
|
|
+ // })
|
|
|
+ // } else {
|
|
|
+ // laporan = (await laporanModel.find({ ...where, 'pt.pembina.id': idPembina }).lean().populate('sanksi').lean())
|
|
|
+ // .filter(e => e.sanksi)
|
|
|
+ // .map(e => {
|
|
|
+ // let step = 'Pelaporan'
|
|
|
+ // if (e.jadwal && !e.evaluasi.length) step = 'Penjadwalan'
|
|
|
+ // else if (e.evaluasi.length && !e.sanksi) step = 'Pemeriksaan'
|
|
|
+ // else if (e.sanksi?.pengajuan?.cabut_sanksi) step = 'Cabut Sanksi'
|
|
|
+ // else if (e.sanksi?.pengajuan?.keberatan && !e.sanksi?.pengajuan?.banding) step = 'Keberatan'
|
|
|
+ // else if (e.sanksi?.aktif === false && !e.sanksi?.masa_berlaku?.from_date) step = 'Selesai'
|
|
|
+ // else if (e.sanksi?.aktif === false && e.jawaban?.cabut_sanksi?.status === 'Diterima') step = 'Diterima'
|
|
|
+ // else if (e.sanksi?.pengajuan?.banding) step = 'Banding'
|
|
|
+ // else if (e.sanksi) step = 'Sanksi'
|
|
|
+ // return { ...e, step }
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+
|
|
|
+ // const [laporan, dataSanksi] = await Promise.all([
|
|
|
+ // (async () => {
|
|
|
+ // let laporan = isLaporan
|
|
|
+ // ? await cekBanyakDataLaporan(user, {
|
|
|
+ // 'pt.pembina.id': idPembina,
|
|
|
+ // all: true,
|
|
|
+ // ...where,
|
|
|
+ // }, {lean: true})
|
|
|
+ // : []
|
|
|
+ // if (!laporan.length) return []
|
|
|
+
|
|
|
+ // return laporan
|
|
|
+ // })(),
|
|
|
+ // (async () =>
|
|
|
+ // isSanksi
|
|
|
+ // ? (
|
|
|
+ // await cekBanyakDataSanksi(
|
|
|
+ // user,
|
|
|
+ // { all: true, ...where },
|
|
|
+ // {
|
|
|
+ // ['pt.pembina.id']: idPembina,
|
|
|
+ // }
|
|
|
+ // )
|
|
|
+ // ).filter((e) => e.laporan != null)
|
|
|
+ // : [])(),
|
|
|
+ // ])
|
|
|
|
|
|
return response.success(res, {
|
|
|
message: 'berhasil get laporan by pembina',
|
|
|
- data: { laporan, sanksi: dataSanksi },
|
|
|
+ data: laporan,
|
|
|
})
|
|
|
})
|
|
|
|