|
|
@@ -16,6 +16,7 @@ const {
|
|
|
const { TEMPLATE_LAPORAN } = require('../utils/constanta')
|
|
|
const logModel = require('../model/log.model')
|
|
|
const kontakModel = require('../model/kontak.model')
|
|
|
+const { isValidObjectId } = require('mongoose')
|
|
|
|
|
|
exports.create = handleError(async (req, res) => {
|
|
|
const user = req.user
|
|
|
@@ -81,10 +82,10 @@ exports.create = handleError(async (req, res) => {
|
|
|
{ key: '3', value: 'keterangan', value_text: keterangan },
|
|
|
{ key: '4', value: 'no_laporan', value_text: no_laporan },
|
|
|
])
|
|
|
-
|
|
|
+
|
|
|
if (notif[0].status == 'success') {
|
|
|
await logModel.create({
|
|
|
- aktivitas: `Server berhasil mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan`,
|
|
|
+ aktivitas: `Server berhasil mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan`,
|
|
|
})
|
|
|
} else {
|
|
|
await logModel.create({
|
|
|
@@ -318,19 +319,25 @@ exports.public = handleError(async (req, res) => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
-exports.getLaporanByNoLaporan = handleError(async (req, res) => {
|
|
|
- const { no_laporan } = req.params
|
|
|
- const data = await laporanModel.findOne({
|
|
|
- no_laporan,
|
|
|
- evaluasi: { $exists: true, $ne: [] },
|
|
|
- })
|
|
|
- if (!data) {
|
|
|
- return response.error(res, {
|
|
|
- message: 'no_laporan tidak ada',
|
|
|
- code: 404,
|
|
|
- })
|
|
|
- }
|
|
|
- return response.success(res, {
|
|
|
+exports.getLaporanByNoLaporanAndId = handleError(async (req, res) => {
|
|
|
+ const { no_laporan } = req.params
|
|
|
+ let where = { evaluasi: { $exists: true, $ne: [] } }
|
|
|
+ if (isValidObjectId(no_laporan)) where._id = no_laporan
|
|
|
+ else where.no_laporan = no_laporan
|
|
|
+ const data = await laporanModel.findOne(where)
|
|
|
+ .populate({ path: 'user', populate: 'foto' })
|
|
|
+ .populate({ path: 'pelanggaran', select: 'pelanggaran' })
|
|
|
+ .populate({ path: 'sanksi', populate: ['pelanggaran'] })
|
|
|
+ .populate('dokumen')
|
|
|
+ .populate('peserta_penetapan_sanksi.ttd')
|
|
|
+ .populate({ path: 'evaluasi', populate: ['user', 'dokumen'] })
|
|
|
+ if (!data) {
|
|
|
+ return response.error(res, {
|
|
|
+ message: 'no_laporan atau id tidak ada',
|
|
|
+ code: 404,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return response.success(res, {
|
|
|
message: 'Berhasil ambil data laporan',
|
|
|
data,
|
|
|
})
|
|
|
@@ -409,9 +416,8 @@ exports.update = handleError(async (req, res) => {
|
|
|
const keterangan2 = req.body.keterangan
|
|
|
if (change_role === 'true') {
|
|
|
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) {
|
|
|
@@ -557,22 +563,22 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
(async () =>
|
|
|
isLaporan
|
|
|
? await cekBanyakDataLaporan(user, {
|
|
|
- 'pt.pembina.id': idPembina,
|
|
|
- all: true,
|
|
|
- ...where,
|
|
|
- })
|
|
|
+ 'pt.pembina.id': idPembina,
|
|
|
+ all: true,
|
|
|
+ ...where,
|
|
|
+ })
|
|
|
: [])(),
|
|
|
(async () =>
|
|
|
isSanksi
|
|
|
? (
|
|
|
- await cekBanyakDataSanksi(
|
|
|
- user,
|
|
|
- { all: true, ...where },
|
|
|
- {
|
|
|
- ['pt.pembina.id']: idPembina,
|
|
|
- }
|
|
|
- )
|
|
|
- ).filter((e) => e.laporan != null)
|
|
|
+ await cekBanyakDataSanksi(
|
|
|
+ user,
|
|
|
+ { all: true, ...where },
|
|
|
+ {
|
|
|
+ ['pt.pembina.id']: idPembina,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ ).filter((e) => e.laporan != null)
|
|
|
: [])(),
|
|
|
])
|
|
|
|
|
|
@@ -581,3 +587,24 @@ exports.laporanByPembina = handleError(async (req, res) => {
|
|
|
data: { laporan, sanksi: dataSanksi },
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+exports.getOneLaporanPublic = handleError(async (req, res) => {
|
|
|
+ const { id } = req.params
|
|
|
+ const data = await laporanModel.findById(id)
|
|
|
+ .populate({ path: 'user', populate: 'foto' })
|
|
|
+ .populate({ path: 'pelanggaran', select: 'pelanggaran' })
|
|
|
+ .populate({ path: 'sanksi', populate: ['pelanggaran'] })
|
|
|
+ .populate('dokumen')
|
|
|
+ .populate('peserta_penetapan_sanksi.ttd')
|
|
|
+ .populate({ path: 'evaluasi', populate: ['user', 'dokumen'] })
|
|
|
+ console.log(data)
|
|
|
+ if (!data) return response.error(res, {
|
|
|
+ code: 404,
|
|
|
+ message: 'laporan_id tidak ada'
|
|
|
+ })
|
|
|
+
|
|
|
+ return response.success(res, {
|
|
|
+ message: 'Berhasil ambil satu data Laporan',
|
|
|
+ data,
|
|
|
+ })
|
|
|
+})
|