andifebri 3 tahun lalu
induk
melakukan
b8a596d9a1

+ 10 - 7
controller/pt.controller.js

@@ -19,12 +19,13 @@ exports.getAll = handleError(async (req, res) => {
   }
 
   let data = await axios.get(url)
-  if (user.role.id === 2022) {
-    data = data[0]
-  }
+
   return response.success(res, {
     message: 'Berhasil mengambil data Perguruan Tinggi',
-    data,
+    data:
+      user.role.id === 2022
+        ? data[0]
+        : data.filter((e) => e.id !== '4B4B23C1-8E0C-4825-89FA-765401C5E9C5'),
   })
 })
 
@@ -58,9 +59,11 @@ exports.public = handleError(async (req, res) => {
     url += parseURL.join('&')
   }
   let data = await axios.get(url)
-  data = data.map((e) => {
-    return { id: e.id, nama: e.nama }
-  })
+  data = data
+    .map((e) => {
+      return { id: e.id, nama: e.nama }
+    })
+    .filter((e) => e.id !== '4B4B23C1-8E0C-4825-89FA-765401C5E9C5')
   return response.success(res, {
     message: 'Berhasil mengambil data Perguruan Tinggi',
     data,

+ 34 - 0
middleware/verifyTokenPublic.js

@@ -0,0 +1,34 @@
+const jwt = require('jsonwebtoken')
+const userModel = require('../model/user.model')
+const response = require('../utils/responseHandler')
+
+module.exports = (req, res, next) => {
+  const authHeader = req.headers.authorization
+  const token = authHeader && authHeader.split(' ')[1]
+
+  if (!token)
+    return response.error(res, {
+      code: 401,
+      message: 'Token tidak ada',
+    })
+
+  jwt.verify(token, process.env.SECRET, async (err, data) => {
+    if (err)
+      return response.error(res, {
+        code: 401,
+        message: 'Unauthorized',
+      })
+    try {
+      const user = await userModel.findById(data._id)
+      req.user = user
+      req.no_laporan = data.no_laporan
+      req.level = data.level
+      next()
+    } catch (error) {
+      return response.error(res, {
+        code: 401,
+        message: 'Unauthorized',
+      })
+    }
+  })
+}

+ 13 - 0
model/kontak.model.js

@@ -0,0 +1,13 @@
+const mongoose = require('mongoose')
+const { Schema } = mongoose
+
+module.exports = mongoose.model(
+  'Kontak',
+  new Schema({
+    nama: String,
+    no_hp: Number,
+    role: Object,
+    lembaga: Object,
+  }),
+  'kontak'
+)

+ 35 - 0
utils/notifFunction.js

@@ -0,0 +1,35 @@
+const axios = require('../utils/axios')
+const kontakModel = require('../model/kontak.model')
+
+exports.notifWA = async (templateId, data, where = {}) => {
+  const kontak = await kontakModel.find(where)
+  const contacts = kontak.map((e) => {
+    return { name: e.nama, number: e.no_hp }
+  })
+  const send = await axios.post(
+    'https://api.kemdikbud.go.id:8243/qontak/1.0/send',
+    {
+      templateId,
+      contacts,
+      body: data,
+    }
+  )
+  return send
+}
+
+exports.notifWA2 = async (templateId, { nama, no_hp }, data) => {
+  const send = await axios.post(
+    'https://api.kemdikbud.go.id:8243/qontak/1.0/send',
+    {
+      templateId,
+      contacts: [
+        {
+          name: nama,
+          number: no_hp,
+        },
+      ],
+      body: data,
+    }
+  )
+  return send
+}