| 1234567891011121314151617181920212223242526272829303132333435 |
- const kontakModel = require('../../model/kontak.model')
- const { notifWA } = require('../../utils/v1/notifFunction')
- const { TEMPLATE_LAPORAN } = require('../../utils/constanta')
- const logModel = require('../../model/log.model')
- exports.sendWaCreateLaporan = async ({ user, pt, keterangan, no_laporan }) => {
- let contacts = await kontakModel.find()
- contacts = contacts.map((e) => e.nama).join(', ')
- try {
- const notif = await notifWA(TEMPLATE_LAPORAN, [
- {
- 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 },
- ])
- if (notif[0].status === 'success') {
- await logModel.create({
- aktivitas: `Server berhasil mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan`,
- })
- } else {
- await logModel.create({
- aktivitas: `Server gagal mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan, Error: ${JSON.stringify(notif)}`,
- })
- }
- } catch (error) {
- await logModel.create({
- aktivitas: `Server gagal mengirim notif wa kepada ${contacts} untuk Pembuatan Laporan, Error: ${error.message}`,
- })
- }
- }
|