Bladeren bron

perubahan di pembuatan laporan publik

yazid138 3 jaren geleden
bovenliggende
commit
4f9b4e7cbf
4 gewijzigde bestanden met toevoegingen van 43 en 18 verwijderingen
  1. 1 0
      controller/auth.controller.js
  2. 12 4
      controller/laporan.controller.js
  3. 29 14
      controller/user.controller.js
  4. 1 0
      model/user.model.js

+ 1 - 0
controller/auth.controller.js

@@ -46,6 +46,7 @@ exports.login = handleError(async (req, res) => {
       role: user.peran[0].peran,
       isPublic: false,
       isPrivate: false,
+      priority: 'medium',
     })
   }
 

+ 12 - 4
controller/laporan.controller.js

@@ -179,13 +179,13 @@ exports.public = handleError(async (req, res) => {
     pt_id: 'string',
     pelanggaran_id: 'string',
     keterangan: 'string',
-    no_verifikasi: 'string',
+    // no_verifikasi: 'string',
   })
   if (!isValid) return
 
   const { pt_id, keterangan, no_verifikasi } = req.body
   let { pelanggaran_id } = req.body
-  if (user.no_verifikasi !== no_verifikasi) {
+  if (no_verifikasi && user.no_verifikasi !== no_verifikasi) {
     return response.error(res, {
       message: 'no_verifikasi tidak sesuai',
       error: { no_verifikasi: 'No. Verifikasi tidak sesuai' },
@@ -234,9 +234,17 @@ exports.public = handleError(async (req, res) => {
     for_pt: false,
   })
 
-  await userModel.findByIdAndUpdate(user._id, { verified: true })
+  if (no_verifikasi)
+    await userModel.findByIdAndUpdate(user._id, {
+      verified: true,
+      priority: 'hight',
+    })
   await notifWA('d5609c3c-e9e9-4dbe-9a4e-e8fa772d6770', [
-    { key: '1', value: 'nama', value_text: user.nama },
+    {
+      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 },

+ 29 - 14
controller/user.controller.js

@@ -9,19 +9,20 @@ const jwt = require('jsonwebtoken')
 
 exports.addUserPublic = handleError(async (req, res) => {
   const { no_laporan, pt_id, nama, email, no_hp, alamat, is_private } = req.body
-  const no_hp2 =
-    no_hp.substring(0, 1) === '0' ? '62' + no_hp.substring(1) : no_hp
   const isValid = validate(res, req.body, {
     no_laporan: 'string',
     pt_id: 'string',
-    nama: 'string',
-    email: 'email',
+    // nama: 'string',
+    // email: 'email',
     no_hp: 'string',
-    alamat: 'string',
+    // alamat: 'string',
     is_private: { type: 'string', enum: ['true', 'false'] },
   })
   if (!isValid) return
 
+  const no_hp2 =
+    no_hp.substring(0, 1) === '0' ? '62' + no_hp.substring(1) : no_hp
+
   const pt = await axios.get(
     `https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${pt_id}`
   )
@@ -30,16 +31,14 @@ exports.addUserPublic = handleError(async (req, res) => {
       message: 'pt_id tidak ditemukan',
     })
 
+  let foto_id = null
   const foto = req.file
-  if (!foto) {
-    return response.error(res, {
-      message: 'foto harus ada',
-    })
+  if (foto) {
+    foto_id = await addDokumen(foto)
   }
-  const foto_id = await addDokumen(foto)
 
   const no_verifikasi = Math.floor(Math.random() * 1000000)
-  const user = await userModel.create({
+  let data = {
     nama,
     email,
     no_hp,
@@ -49,11 +48,27 @@ exports.addUserPublic = handleError(async (req, res) => {
     foto: foto_id,
     no_verifikasi,
     verified: false,
-  })
+    priority: 'low',
+  }
+
+  if (
+    no_laporan &&
+    pt_id &&
+    nama &&
+    email &&
+    no_hp &&
+    alamat &&
+    is_private &&
+    foto_id
+  ) {
+    data.priority = 'hight'
+  }
+
+  const user = await userModel.create(data)
 
   await notifWA2(
     '37a9ccba-e1bc-4d02-86e0-3be4c718af2a',
-    { nama, no_hp: no_hp2 },
+    { nama: nama || 'rahasia', no_hp: no_hp2 },
     [
       { key: '1', value: 'pt', value_text: pt[0].nama },
       { key: '3', value: 'no_verifikasi', value_text: no_verifikasi },
@@ -69,7 +84,7 @@ exports.addUserPublic = handleError(async (req, res) => {
     }
   )
 
-  const data = {
+  data = {
     token: `Bearer ${accessToken}`,
   }
 

+ 1 - 0
model/user.model.js

@@ -20,6 +20,7 @@ module.exports = mongoose.model(
     isPrivate: Boolean,
     no_verifikasi: String,
     verified: Boolean,
+    priority: { type: String, enum: ['hight', 'medium', 'low'] },
   }),
   'user'
 )