|
|
@@ -5,11 +5,15 @@ 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 { addDokumen, addManyDokumen } = require('../utils/dokumenFunction')
|
|
|
const userModel = require('../model/user.model')
|
|
|
const { cekSatuDataLaporan, cekBanyakDataLaporan } = require('../utils/cekData')
|
|
|
|
|
|
exports.create = handleError(async (req, res) => {
|
|
|
+ const user = req.user
|
|
|
+ const files = req.files
|
|
|
+
|
|
|
const isValid = validate(res, req.body, {
|
|
|
no_laporan: 'string',
|
|
|
pt_id: 'string',
|
|
|
@@ -23,12 +27,11 @@ exports.create = handleError(async (req, res) => {
|
|
|
const pt = await axios.get(
|
|
|
`https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${pt_id}`
|
|
|
)
|
|
|
- if (!pt)
|
|
|
+ if (pt.length === 0)
|
|
|
return response.error(res, {
|
|
|
message: 'pt_id tidak ditemukan',
|
|
|
})
|
|
|
|
|
|
- const files = req.files
|
|
|
let dokumen_id = []
|
|
|
if (files.length) {
|
|
|
const dokumen = await addManyDokumen(files)
|
|
|
@@ -44,7 +47,6 @@ exports.create = handleError(async (req, res) => {
|
|
|
if (!pelanggaran.length)
|
|
|
return response.error(res, { message: 'pelanggaran_id tidak ada' })
|
|
|
|
|
|
- const user = req.user
|
|
|
let data = {
|
|
|
no_laporan,
|
|
|
user: user._id,
|
|
|
@@ -53,6 +55,7 @@ exports.create = handleError(async (req, res) => {
|
|
|
pelanggaran: pelanggaran_id,
|
|
|
keterangan,
|
|
|
role_data: user.role.id === 2020 ? 'dikti' : 'lldikti',
|
|
|
+ level: 2,
|
|
|
}
|
|
|
|
|
|
data = await laporanModel.create(data)
|
|
|
@@ -71,61 +74,140 @@ exports.create = handleError(async (req, res) => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+// exports.public = handleError(async (req, res) => {
|
|
|
+// const isValid = validate(res, req.body, {
|
|
|
+// nama: 'string',
|
|
|
+// email: 'email',
|
|
|
+// alamat: 'string',
|
|
|
+// no_hp: 'string',
|
|
|
+// no_laporan: 'string',
|
|
|
+// pt_id: 'string',
|
|
|
+// pelanggaran_id: 'string',
|
|
|
+// keterangan: 'string',
|
|
|
+// is_private: { type: 'string', enum: ['true', 'false'] },
|
|
|
+// })
|
|
|
+// if (!isValid) return
|
|
|
+
|
|
|
+// const {
|
|
|
+// no_laporan,
|
|
|
+// pt_id,
|
|
|
+// keterangan,
|
|
|
+// nama,
|
|
|
+// email,
|
|
|
+// alamat,
|
|
|
+// no_hp,
|
|
|
+// is_private,
|
|
|
+// } = req.body
|
|
|
+// let { pelanggaran_id } = req.body
|
|
|
+
|
|
|
+// const pt = await axios.get(
|
|
|
+// `https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${pt_id}`
|
|
|
+// )
|
|
|
+// if (!pt) {
|
|
|
+// return response.error(res, {
|
|
|
+// message: 'pt_id tidak ditemukan',
|
|
|
+// })
|
|
|
+// }
|
|
|
+
|
|
|
+// const { dokumen, foto } = req.files
|
|
|
+// if (!foto.length) {
|
|
|
+// return response.error(res, {
|
|
|
+// message: 'foto harus ada',
|
|
|
+// })
|
|
|
+// }
|
|
|
+// const foto_id = await addDokumen(foto[0])
|
|
|
+// const user = await userModel.create({
|
|
|
+// nama,
|
|
|
+// email,
|
|
|
+// no_hp,
|
|
|
+// alamat,
|
|
|
+// isPublic: true,
|
|
|
+// isPrivate: is_private === 'true',
|
|
|
+// foto: foto_id,
|
|
|
+// })
|
|
|
+// let dokumen_id = []
|
|
|
+// if (dokumen?.length) {
|
|
|
+// const dataDokumen = await addManyDokumen(dokumen)
|
|
|
+// dokumen_id = dataDokumen.map((e) => e._id)
|
|
|
+// }
|
|
|
+
|
|
|
+// pelanggaran_id = pelanggaran_id.split(',')
|
|
|
+// const pelanggaran = await pelanggaranModel.find({
|
|
|
+// _id: {
|
|
|
+// $in: pelanggaran_id,
|
|
|
+// },
|
|
|
+// })
|
|
|
+// if (!pelanggaran.length)
|
|
|
+// return response.error(res, { message: 'pelanggaran_id tidak ada' })
|
|
|
+
|
|
|
+// let data = {
|
|
|
+// no_laporan,
|
|
|
+// user: user._id,
|
|
|
+// dokumen: dokumen_id,
|
|
|
+// pt: pt[0],
|
|
|
+// pelanggaran: pelanggaran_id,
|
|
|
+// keterangan,
|
|
|
+// role_data: 'dikti',
|
|
|
+// }
|
|
|
+
|
|
|
+// data = await laporanModel.create(data)
|
|
|
+// await pemantauanModel.create({
|
|
|
+// laporan: data._id,
|
|
|
+// pt_id: pt[0].id,
|
|
|
+// user: user._id,
|
|
|
+// keterangan: 'Mengajukan Laporan',
|
|
|
+// dokumen: dokumen_id,
|
|
|
+// for_pt: false,
|
|
|
+// })
|
|
|
+// await notifWA('d5609c3c-e9e9-4dbe-9a4e-e8fa772d6770', [
|
|
|
+// { key: '1', value: 'nama', value_text: nama },
|
|
|
+// { key: '2', value: 'pt', value_text: pt[0].nama },
|
|
|
+// { key: '3', value: 'keterangan', value_text: keterangan },
|
|
|
+// { key: '4', value: 'no_laporan', value_text: no_laporan },
|
|
|
+// ])
|
|
|
+// return response.success(res, {
|
|
|
+// message: 'Berhasil menambah laporan',
|
|
|
+// data,
|
|
|
+// })
|
|
|
+// })
|
|
|
+
|
|
|
exports.public = handleError(async (req, res) => {
|
|
|
+ const user = req.user
|
|
|
+ const no_laporan = req.no_laporan
|
|
|
+ let level = req.level
|
|
|
+ const files = req.files
|
|
|
+
|
|
|
const isValid = validate(res, req.body, {
|
|
|
- nama: 'string',
|
|
|
- email: 'email',
|
|
|
- alamat: 'string',
|
|
|
- no_hp: 'string',
|
|
|
- no_laporan: 'string',
|
|
|
pt_id: 'string',
|
|
|
pelanggaran_id: 'string',
|
|
|
keterangan: 'string',
|
|
|
- is_private: { type: 'string', enum: ['true', 'false'] },
|
|
|
+ // no_verifikasi: 'string',
|
|
|
})
|
|
|
if (!isValid) return
|
|
|
|
|
|
- const {
|
|
|
- no_laporan,
|
|
|
- pt_id,
|
|
|
- keterangan,
|
|
|
- nama,
|
|
|
- email,
|
|
|
- alamat,
|
|
|
- no_hp,
|
|
|
- is_private,
|
|
|
- } = req.body
|
|
|
+ const { pt_id, keterangan, no_verifikasi } = req.body
|
|
|
let { pelanggaran_id } = req.body
|
|
|
+ if (no_verifikasi && user.no_verifikasi !== no_verifikasi) {
|
|
|
+ return response.error(res, {
|
|
|
+ message: 'no_verifikasi tidak sesuai',
|
|
|
+ error: { no_verifikasi: 'No. Verifikasi tidak sesuai' },
|
|
|
+ })
|
|
|
+ } else if (no_verifikasi && user.no_verifikasi === no_verifikasi) {
|
|
|
+ level = 3
|
|
|
+ }
|
|
|
|
|
|
const pt = await axios.get(
|
|
|
`https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${pt_id}`
|
|
|
)
|
|
|
- if (!pt) {
|
|
|
+ if (pt.length === 0)
|
|
|
return response.error(res, {
|
|
|
message: 'pt_id tidak ditemukan',
|
|
|
})
|
|
|
- }
|
|
|
|
|
|
- const { dokumen, foto } = req.files
|
|
|
- if (!foto.length) {
|
|
|
- return response.error(res, {
|
|
|
- message: 'foto harus ada',
|
|
|
- })
|
|
|
- }
|
|
|
- const foto_id = await addDokumen(foto[0])
|
|
|
- const user = await userModel.create({
|
|
|
- nama,
|
|
|
- email,
|
|
|
- no_hp,
|
|
|
- alamat,
|
|
|
- isPublic: true,
|
|
|
- isPrivate: is_private === 'true',
|
|
|
- foto: foto_id,
|
|
|
- })
|
|
|
let dokumen_id = []
|
|
|
- if (dokumen?.length) {
|
|
|
- const dataDokumen = await addManyDokumen(dokumen)
|
|
|
- dokumen_id = dataDokumen.map((e) => e._id)
|
|
|
+ if (files.length) {
|
|
|
+ const dokumen = await addManyDokumen(files)
|
|
|
+ dokumen_id = dokumen.map((e) => e._id)
|
|
|
}
|
|
|
|
|
|
pelanggaran_id = pelanggaran_id.split(',')
|
|
|
@@ -145,6 +227,7 @@ exports.public = handleError(async (req, res) => {
|
|
|
pelanggaran: pelanggaran_id,
|
|
|
keterangan,
|
|
|
role_data: 'dikti',
|
|
|
+ level,
|
|
|
}
|
|
|
|
|
|
data = await laporanModel.create(data)
|
|
|
@@ -152,11 +235,24 @@ exports.public = handleError(async (req, res) => {
|
|
|
laporan: data._id,
|
|
|
pt_id: pt[0].id,
|
|
|
user: user._id,
|
|
|
- keterangan: 'Mengajukan Laporan',
|
|
|
+ keterangan: 'Membuat Laporan',
|
|
|
dokumen: dokumen_id,
|
|
|
for_pt: false,
|
|
|
})
|
|
|
|
|
|
+ if (no_verifikasi)
|
|
|
+ await userModel.findByIdAndUpdate(user._id, { verified: true })
|
|
|
+ await notifWA('d5609c3c-e9e9-4dbe-9a4e-e8fa772d6770', [
|
|
|
+ {
|
|
|
+ key: '1',
|
|
|
+ value: 'nama',
|
|
|
+ value_text: user.isPrivate || !user.nama ? 'rahasia' : user.nama,
|
|
|
+ },
|
|
|
+ { key: '2', value: 'pt', value_text: pt[0].nama },
|
|
|
+ { key: '3', value: 'keterangan', value_text: keterangan },
|
|
|
+ { key: '4', value: 'no_laporan', value_text: no_laporan },
|
|
|
+ ])
|
|
|
+
|
|
|
return response.success(res, {
|
|
|
message: 'Berhasil menambah laporan',
|
|
|
data,
|
|
|
@@ -195,7 +291,7 @@ exports.getOne = handleError(async (req, res) => {
|
|
|
const { id } = req.params
|
|
|
const user = req.user
|
|
|
const { aktif } = req.query
|
|
|
- const where = { }
|
|
|
+ const where = {}
|
|
|
if (aktif) where.aktif = aktif === 'true'
|
|
|
const data = await cekSatuDataLaporan(res, user, id, where)
|
|
|
if (!data) return
|
|
|
@@ -214,15 +310,21 @@ exports.update = handleError(async (req, res) => {
|
|
|
const isValid = validate(res, req.body, {
|
|
|
change_role: { type: 'string', optional: true, enum: ['true', 'false'] },
|
|
|
aktif: { type: 'string', optional: true, enum: ['true', 'false'] },
|
|
|
+ keterangan: 'string',
|
|
|
})
|
|
|
if (!isValid) return
|
|
|
|
|
|
const data = {}
|
|
|
let keterangan = ''
|
|
|
+ let alasan = ''
|
|
|
const { change_role, aktif } = req.body
|
|
|
+ const keterangan2 = req.body.keterangan
|
|
|
if (change_role === 'true') {
|
|
|
data.role_data = user.role.id === 2020 ? 'lldikti' : 'dikti'
|
|
|
- keterangan = `Delegasi ke ${user.role.id === 2020 ? 'LLDIKTI' : 'DIKTI'}`
|
|
|
+ keterangan = `Laporan didelegasi ke ${
|
|
|
+ user.role.id === 2020 ? 'LLDIKTI' : 'DIKTI'
|
|
|
+ }`
|
|
|
+ alasan = keterangan2
|
|
|
if (laporan.jadwal) {
|
|
|
await laporanModel.findByIdAndUpdate(laporan._id, {
|
|
|
$unset: { jadwal: 1 },
|
|
|
@@ -234,7 +336,8 @@ exports.update = handleError(async (req, res) => {
|
|
|
if (aktif === 'true') {
|
|
|
keterangan = 'Laporan dibuka'
|
|
|
} else {
|
|
|
- keterangan = 'Laporan ditutup'
|
|
|
+ keterangan = `Laporan ditutup`
|
|
|
+ alasan = keterangan2
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -245,6 +348,7 @@ exports.update = handleError(async (req, res) => {
|
|
|
pt_id: laporan.pt.id,
|
|
|
user: user._id,
|
|
|
keterangan,
|
|
|
+ alasan,
|
|
|
for_pt: false,
|
|
|
})
|
|
|
}
|