|  | @@ -11,6 +11,9 @@ 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',
 | 
	
	
		
			
				|  | @@ -24,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)
 | 
	
	
		
			
				|  | @@ -45,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,
 | 
	
	
		
			
				|  | @@ -72,61 +73,136 @@ 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
 | 
	
		
			
				|  |  | +  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 (user.no_verifikasi !== no_verifikasi) {
 | 
	
		
			
				|  |  | +    return response.error(res, {
 | 
	
		
			
				|  |  | +      message: 'no_verifikasi tidak sesuai',
 | 
	
		
			
				|  |  | +      error: { no_verifikasi: 'No. Verifikasi tidak sesuai' },
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |    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(',')
 | 
	
	
		
			
				|  | @@ -153,16 +229,19 @@ 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,
 | 
	
		
			
				|  |  |    })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  await userModel.findByIdAndUpdate(user._id, { verified: true })
 | 
	
		
			
				|  |  |    await notifWA('d5609c3c-e9e9-4dbe-9a4e-e8fa772d6770', [
 | 
	
		
			
				|  |  | -    { key: '1', value: 'nama', value_text: nama },
 | 
	
		
			
				|  |  | +    { key: '1', value: 'nama', value_text: 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,
 |