|
|
@@ -1,4 +1,3 @@
|
|
|
-const axios = require('../../utils/axios')
|
|
|
const handleError = require('../../utils/v1/handleError')
|
|
|
const response = require('../../utils/responseHandler')
|
|
|
const laporanModel = require('../../model/laporan.model')
|
|
|
@@ -11,13 +10,18 @@ const userModel = require('../../model/user.model')
|
|
|
const {
|
|
|
cekSatuDataLaporan,
|
|
|
cekBanyakDataLaporan,
|
|
|
- cekBanyakDataSanksi,
|
|
|
} = require('../../utils/v1/cekData')
|
|
|
-const { TEMPLATE_LAPORAN, PELAPORAN, CREATE_LAPORAN, DIKTI, LLDIKTI, DITUTUP, DELEGASI, TRUE, FALSE, ADD_JADWAL } = require('../../utils/constanta')
|
|
|
+const { TEMPLATE_LAPORAN, PELAPORAN, CREATE_LAPORAN, DIKTI, LLDIKTI, DITUTUP, DELEGASI, TRUE, FALSE, ADD_JADWAL,
|
|
|
+ PTB_DIKTI,
|
|
|
+ PTB_ADMIN,
|
|
|
+ PTB_READ,
|
|
|
+ SUCCESS, UPDATE_LAPORAN, DITERIMA
|
|
|
+} = 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')
|
|
|
+const roleId = require('../../middleware/role')
|
|
|
+const pddiktiService = require('../../services/v2/pddikti.service')
|
|
|
|
|
|
exports.create = handleError(async (req, res) => {
|
|
|
const user = req.user
|
|
|
@@ -33,9 +37,7 @@ exports.create = handleError(async (req, res) => {
|
|
|
|
|
|
const { no_laporan, pt_id, keterangan } = req.body
|
|
|
let { pelanggaran_id } = req.body
|
|
|
- const pt = await axios.get(
|
|
|
- `https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${pt_id}`
|
|
|
- )
|
|
|
+ const pt = await pddiktiService.getPT(pt_id)
|
|
|
if (pt.length === 0)
|
|
|
return response.error(res, {
|
|
|
message: 'pt_id tidak ditemukan',
|
|
|
@@ -86,7 +88,7 @@ exports.create = handleError(async (req, res) => {
|
|
|
{ key: '4', value: 'no_laporan', value_text: no_laporan },
|
|
|
])
|
|
|
|
|
|
- if (notif[0].status == 'success') {
|
|
|
+ if (notif[0].status === SUCCESS) {
|
|
|
await logModel.create({
|
|
|
aktivitas: `Server berhasil mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan`,
|
|
|
})
|
|
|
@@ -127,7 +129,6 @@ exports.public = handleError(async (req, res) => {
|
|
|
pt_id: 'string',
|
|
|
pelanggaran_id: 'string',
|
|
|
keterangan: 'string',
|
|
|
- // no_verifikasi: 'string',
|
|
|
})
|
|
|
if (!isValid) return
|
|
|
|
|
|
@@ -142,9 +143,7 @@ exports.public = handleError(async (req, res) => {
|
|
|
level = 3
|
|
|
}
|
|
|
|
|
|
- const pt = await axios.get(
|
|
|
- `https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${pt_id}`
|
|
|
- )
|
|
|
+ const pt = await pddiktiService.getPT(pt_id)
|
|
|
if (pt.length === 0)
|
|
|
return response.error(res, {
|
|
|
message: 'pt_id tidak ditemukan',
|
|
|
@@ -172,15 +171,15 @@ exports.public = handleError(async (req, res) => {
|
|
|
pt: pt[0],
|
|
|
pelanggaran: pelanggaran_id,
|
|
|
keterangan,
|
|
|
- role_data: 'dikti',
|
|
|
- role_asal: 'dikti',
|
|
|
+ role_data: DIKTI,
|
|
|
+ role_asal: DIKTI,
|
|
|
level,
|
|
|
}
|
|
|
|
|
|
data = await laporanModel.create(data)
|
|
|
await pemantauanModel.create({
|
|
|
laporan: data._id,
|
|
|
- action: 'CREATE LAPORAN',
|
|
|
+ action: CREATE_LAPORAN,
|
|
|
pt_id: pt[0].id,
|
|
|
user: user._id,
|
|
|
keterangan: 'Membuat Laporan',
|
|
|
@@ -204,7 +203,7 @@ exports.public = handleError(async (req, res) => {
|
|
|
{ key: '4', value: 'no_laporan', value_text: no_laporan },
|
|
|
])
|
|
|
|
|
|
- if (notif[0].status == 'success') {
|
|
|
+ if (notif[0].status === SUCCESS) {
|
|
|
await logModel.create({
|
|
|
aktivitas: `Server berhasil mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan`,
|
|
|
})
|
|
|
@@ -256,16 +255,16 @@ exports.getAll = handleError(async (req, res) => {
|
|
|
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 (aktif) where.aktif = aktif === TRUE
|
|
|
if (all) where.all = true
|
|
|
- else if (delegasi) where.delegasi = delegasi === 'true'
|
|
|
+ else if (delegasi) where.delegasi = delegasi === TRUE
|
|
|
|
|
|
- if (jadwal === 'true') {
|
|
|
+ if (jadwal === TRUE) {
|
|
|
where.jadwal = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
}
|
|
|
- } else if (evaluasi === 'true') {
|
|
|
+ } else if (evaluasi === TRUE) {
|
|
|
where.evaluasi = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
@@ -273,39 +272,15 @@ exports.getAll = handleError(async (req, res) => {
|
|
|
$size: 0,
|
|
|
},
|
|
|
}
|
|
|
- } else if (sanksi === 'true') {
|
|
|
+ } else if (sanksi === TRUE) {
|
|
|
where.sanksi = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
}
|
|
|
- } else if (tuntas === 'true') {
|
|
|
+ } else if (tuntas === TRUE) {
|
|
|
let dataLaporan = (await cekBanyakDataLaporan(user, { aktif: 'empty', all: true, }, { lean: true }))
|
|
|
.filter(e => e.aktif === false || e.sanksi?.aktif === false)
|
|
|
.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
|
|
|
@@ -361,15 +336,10 @@ exports.update = handleError(async (req, res) => {
|
|
|
keterangan = `Laporan didelegasi ke ${user.role.id === 2020 ? 'LLDIKTI' : 'DIKTI'}`
|
|
|
alasan = keterangan2
|
|
|
data.alasan_delegasi = keterangan2
|
|
|
- // if (laporan.jadwal) {
|
|
|
- // await laporanModel.findByIdAndUpdate(laporan._id, {
|
|
|
- // $unset: { jadwal: 1 },
|
|
|
- // })
|
|
|
- // }
|
|
|
}
|
|
|
if (aktif) {
|
|
|
let dokumen_id = []
|
|
|
- data.aktif = aktif === 'true'
|
|
|
+ data.aktif = aktif === TRUE
|
|
|
if (files) {
|
|
|
const dokumen = await addManyDokumen(files)
|
|
|
dokumen_id = dokumen.map((e) => e._id)
|
|
|
@@ -390,7 +360,7 @@ exports.update = handleError(async (req, res) => {
|
|
|
const update = await laporanModel.findByIdAndUpdate(laporan._id, data)
|
|
|
if (change_role || aktif) {
|
|
|
await pemantauanModel.create({
|
|
|
- action: 'UPDATE LAPORAN',
|
|
|
+ action: UPDATE_LAPORAN,
|
|
|
laporan: laporan._id,
|
|
|
pt_id: laporan.pt.id,
|
|
|
user: user._id,
|
|
|
@@ -437,7 +407,9 @@ exports.jumlahLaporan = handleError(async (req, res) => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
-exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
+exports.laporanByPembina = [
|
|
|
+ roleId([PTB_DIKTI,PTB_ADMIN, PTB_READ]),
|
|
|
+ handleError(async (req, res) => {
|
|
|
const { idPembina } = req.params
|
|
|
const {
|
|
|
penjadwalan,
|
|
|
@@ -456,7 +428,7 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
let isLaporan = true
|
|
|
let isSanksi = false
|
|
|
|
|
|
- if (penjadwalan === 'true') {
|
|
|
+ if (penjadwalan === TRUE) {
|
|
|
where.jadwal = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
@@ -464,7 +436,7 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
isLaporan = true
|
|
|
isSanksi = false
|
|
|
}
|
|
|
- if (pemeriksaan === 'true') {
|
|
|
+ if (pemeriksaan === TRUE) {
|
|
|
where.evaluasi = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
@@ -475,7 +447,7 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
isLaporan = true
|
|
|
isSanksi = false
|
|
|
}
|
|
|
- if (sanksi === 'true') {
|
|
|
+ if (sanksi === TRUE) {
|
|
|
where.sanksi = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
@@ -483,17 +455,17 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
- if (keberatan === 'true') {
|
|
|
+ if (keberatan === TRUE) {
|
|
|
where2['pengajuan.keberatan'] = { $exists: true, $ne: null }
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
- if (banding === 'true') {
|
|
|
+ if (banding === TRUE) {
|
|
|
where2['pengajuan.banding'] = { $exists: true, $ne: null }
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
- if (cabutSanksi === 'true') {
|
|
|
+ if (cabutSanksi === TRUE) {
|
|
|
where2['pengajuan.cabut_sanksi'] = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
@@ -501,7 +473,7 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
- if (perbaikan === 'true') {
|
|
|
+ if (perbaikan === TRUE) {
|
|
|
where2.perbaikan = {
|
|
|
$exists: true,
|
|
|
$ne: null,
|
|
|
@@ -512,22 +484,22 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
isLaporan = false
|
|
|
isSanksi = true
|
|
|
}
|
|
|
- if (delegasi === 'true') {
|
|
|
+ if (delegasi === TRUE) {
|
|
|
where = {
|
|
|
- role_asal: 'dikti',
|
|
|
- role_data: 'lldikti'
|
|
|
+ role_asal: DIKTI,
|
|
|
+ role_data: LLDIKTI
|
|
|
}
|
|
|
isLaporan = true
|
|
|
isSanksi = false
|
|
|
}
|
|
|
- if (ditutup === 'true') {
|
|
|
+ if (ditutup === TRUE) {
|
|
|
where.aktif = false
|
|
|
isLaporan = true
|
|
|
isSanksi = false
|
|
|
}
|
|
|
- if (diterima === 'true') {
|
|
|
+ if (diterima === TRUE) {
|
|
|
where2 = {
|
|
|
- 'jawaban.cabut_sanksi.status': 'Diterima',
|
|
|
+ 'jawaban.cabut_sanksi.status': DITERIMA,
|
|
|
aktif: false
|
|
|
}
|
|
|
isLaporan = false
|
|
|
@@ -569,7 +541,7 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
message: 'berhasil get laporan by pembina',
|
|
|
data: laporan,
|
|
|
})
|
|
|
-})
|
|
|
+})]
|
|
|
|
|
|
exports.getOneLaporanPublic = handleError(async (req, res) => {
|
|
|
const { id } = req.params
|