|
@@ -8,7 +8,11 @@ const { validate } = require('../utils/validation')
|
|
|
const { notifWA } = require('../utils/notifFunction')
|
|
const { notifWA } = require('../utils/notifFunction')
|
|
|
const { addManyDokumen } = require('../utils/dokumenFunction')
|
|
const { addManyDokumen } = require('../utils/dokumenFunction')
|
|
|
const userModel = require('../model/user.model')
|
|
const userModel = require('../model/user.model')
|
|
|
-const { cekSatuDataLaporan, cekBanyakDataLaporan } = require('../utils/cekData')
|
|
|
|
|
|
|
+const {
|
|
|
|
|
+ cekSatuDataLaporan,
|
|
|
|
|
+ cekBanyakDataLaporan,
|
|
|
|
|
+ cekBanyakDataSanksi,
|
|
|
|
|
+} = require('../utils/cekData')
|
|
|
const { TEMPLATE_LAPORAN } = require('../utils/constanta')
|
|
const { TEMPLATE_LAPORAN } = require('../utils/constanta')
|
|
|
const logModel = require('../model/log.model')
|
|
const logModel = require('../model/log.model')
|
|
|
const kontakModel = require('../model/kontak.model')
|
|
const kontakModel = require('../model/kontak.model')
|
|
@@ -297,11 +301,14 @@ exports.public = handleError(async (req, res) => {
|
|
|
exports.getAll = handleError(async (req, res) => {
|
|
exports.getAll = handleError(async (req, res) => {
|
|
|
const user = req.user
|
|
const user = req.user
|
|
|
const where = {}
|
|
const where = {}
|
|
|
- const { no_laporan, pt_id, jadwal, evaluasi, aktif, delegasi } = req.query
|
|
|
|
|
|
|
+ const { no_laporan, pt_id, jadwal, evaluasi, aktif, delegasi, all, sanksi } =
|
|
|
|
|
+ req.query
|
|
|
if (no_laporan) where.no_laporan = no_laporan
|
|
if (no_laporan) where.no_laporan = no_laporan
|
|
|
if (pt_id) where['pt.id'] = pt_id
|
|
if (pt_id) where['pt.id'] = pt_id
|
|
|
if (aktif) where.aktif = aktif === 'true'
|
|
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') {
|
|
if (jadwal === 'true') {
|
|
|
where.jadwal = {
|
|
where.jadwal = {
|
|
|
$exists: true,
|
|
$exists: true,
|
|
@@ -315,6 +322,11 @@ exports.getAll = handleError(async (req, res) => {
|
|
|
$size: 0,
|
|
$size: 0,
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (sanksi === 'true') {
|
|
|
|
|
+ where.sanksi = {
|
|
|
|
|
+ $exists: true,
|
|
|
|
|
+ $ne: null,
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
let data = await cekBanyakDataLaporan(user, where)
|
|
let data = await cekBanyakDataLaporan(user, where)
|
|
|
return response.success(res, {
|
|
return response.success(res, {
|
|
@@ -326,10 +338,11 @@ exports.getAll = handleError(async (req, res) => {
|
|
|
exports.getOne = handleError(async (req, res) => {
|
|
exports.getOne = handleError(async (req, res) => {
|
|
|
const { id } = req.params
|
|
const { id } = req.params
|
|
|
const user = req.user
|
|
const user = req.user
|
|
|
- const { aktif, delegasi } = req.query
|
|
|
|
|
|
|
+ const { aktif, delegasi, all } = req.query
|
|
|
const where = {}
|
|
const where = {}
|
|
|
if (aktif) where.aktif = aktif === 'true'
|
|
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)
|
|
const data = await cekSatuDataLaporan(res, user, id, where)
|
|
|
if (!data) return
|
|
if (!data) return
|
|
|
return response.success(res, {
|
|
return response.success(res, {
|
|
@@ -428,3 +441,31 @@ exports.jumlahLaporan = handleError(async (req, res) => {
|
|
|
data: laporan,
|
|
data: laporan,
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
|
|
+ const { idPembina } = req.params
|
|
|
|
|
+ const user = req.user
|
|
|
|
|
+
|
|
|
|
|
+ const [laporan, sanksi] = await Promise.all([
|
|
|
|
|
+ (async () =>
|
|
|
|
|
+ await cekBanyakDataLaporan(user, {
|
|
|
|
|
+ 'pt.pembina.id': idPembina,
|
|
|
|
|
+ all: true,
|
|
|
|
|
+ }))(),
|
|
|
|
|
+ (async () =>
|
|
|
|
|
+ (
|
|
|
|
|
+ await cekBanyakDataSanksi(
|
|
|
|
|
+ user,
|
|
|
|
|
+ { all: true },
|
|
|
|
|
+ {
|
|
|
|
|
+ ['pt.pembina.id']: idPembina,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ ).filter((e) => e.laporan != null))(),
|
|
|
|
|
+ ])
|
|
|
|
|
+
|
|
|
|
|
+ return response.success(res, {
|
|
|
|
|
+ message: 'berhasil get laporan by pembina',
|
|
|
|
|
+ data: { laporan, sanksi },
|
|
|
|
|
+ })
|
|
|
|
|
+})
|