|  | @@ -5,7 +5,8 @@ const laporanModel = require('../model/laporan.model')
 | 
	
		
			
				|  |  |  const pelanggaranModel = require('../model/pelanggaran.model')
 | 
	
		
			
				|  |  |  const pemantauanModel = require('../model/pemantauan.model')
 | 
	
		
			
				|  |  |  const { validate } = require('../utils/validation')
 | 
	
		
			
				|  |  | -const { addManyDokumen } = require('../utils/dokumenFunction')
 | 
	
		
			
				|  |  | +const { addDokumen, addManyDokumen } = require('../utils/dokumenFunction')
 | 
	
		
			
				|  |  | +const userModel = require('../model/user.model')
 | 
	
		
			
				|  |  |  const { cekSatuDataLaporan, cekBanyakDataLaporan } = require('../utils/cekData')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  exports.create = handleError(async (req, res) => {
 | 
	
	
		
			
				|  | @@ -70,6 +71,98 @@ 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,
 | 
	
		
			
				|  |  | +  })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  return response.success(res, {
 | 
	
		
			
				|  |  | +    message: 'Berhasil menambah laporan',
 | 
	
		
			
				|  |  | +    data,
 | 
	
		
			
				|  |  | +  })
 | 
	
		
			
				|  |  | +})
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  exports.getAll = handleError(async (req, res) => {
 | 
	
		
			
				|  |  |    const user = req.user
 | 
	
		
			
				|  |  |    const where = {}
 |