yazid138 %!s(int64=2) %!d(string=hai) anos
pai
achega
d18a1efcb5
Modificáronse 1 ficheiros con 36 adicións e 36 borrados
  1. 36 36
      controller/sanksi.controller.js

+ 36 - 36
controller/sanksi.controller.js

@@ -103,42 +103,42 @@ exports.create = handleError(async (req, res) => {
     }
   })
 
-  // if (coba.decrypt(process.env.CXQSB) === 'production' && data) {
-  //   try {
-  //     await axios.post(
-  //       `https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${laporan.pt.kode}/sanksi`,
-  //       {
-  //         noSanksi: no_sanksi,
-  //         tmtBerlaku: from_date,
-  //         tstBerlaku: tanggal_terima_sanksi,
-  //         idJenisSanksi: Math.max(...pelanggaran.map(e => e.level_sanksi)),
-  //         alasan: 'Penetapan sanksi'
-  //       }, {
-  //         'Content-Type': 'application/json',
-  //       })
-  //     await logModel.create({
-  //       user: user._id,
-  //       aktivitas: `Server berhasil mengirimkan data Ke API PDDIKTI untuk update Status PT ${laporan.pt.nama}`
-  //     })
-  //   } catch (e) {
-  //     await Promise.all([
-  //       laporanModel.updateOne({
-  //         _id: laporan._id
-  //       }, {
-  //         sanksi: null
-  //       }), sanksiModel.deleteOne({
-  //         _id: data._id
-  //       }), logModel.create({
-  //         user: user._id,
-  //         aktivitas: `Server gagal mengirimkan data Ke API PDDIKTI untuk update Status PT ${laporan.pt.nama}`
-  //       })
-  //     ])
-  //     return response.error(res, {
-  //       message: 'Gagal Membuat Sanksi',
-  //       error: e.message
-  //     })
-  //   }
-  // }
+  if (coba.decrypt(process.env.CXQSB) === 'production' && data) {
+    try {
+      await axios.post(
+        `https://api.kemdikbud.go.id:8243/pddikti/1.2/pt/${laporan.pt.kode}/sanksi`,
+        {
+          noSanksi: no_sanksi,
+          tmtBerlaku: from_date,
+          tstBerlaku: tanggal_terima_sanksi,
+          idJenisSanksi: Math.max(...pelanggaran.map(e => e.level_sanksi)),
+          alasan: 'Penetapan sanksi'
+        }, {
+          'Content-Type': 'application/json',
+        })
+      await logModel.create({
+        user: user._id,
+        aktivitas: `Server berhasil mengirimkan data Ke API PDDIKTI untuk update Status PT ${laporan.pt.nama}`
+      })
+    } catch (e) {
+      await Promise.all([
+        laporanModel.updateOne({
+          _id: laporan._id
+        }, {
+          sanksi: null
+        }), sanksiModel.deleteOne({
+          _id: data._id
+        }), logModel.create({
+          user: user._id,
+          aktivitas: `Server gagal mengirimkan data Ke API PDDIKTI untuk update Status PT ${laporan.pt.nama}`
+        })
+      ])
+      return response.error(res, {
+        message: 'Gagal Membuat Sanksi',
+        error: e.message
+      })
+    }
+  }
 
   await laporanModel.findByIdAndUpdate(laporan._id, {
     sanksi: data._id