const kontakModel = require('../../model/kontak.model') const { TEMPLATE_LAPORAN } = require('../../utils/constanta') const logModel = require('../../model/log.model') const { enqueueWa } = require('../waJob.service') exports.sendWaCreateLaporan = async ({ user, pt, keterangan, no_laporan }) => { let contacts = await kontakModel.find() const contactNames = contacts.map((e) => e.nama).join(', ') const formattedContacts = contacts.map((e) => ({ name: e.nama, number: e.no_hp })) try { const body = [ { 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 }, ] await enqueueWa(TEMPLATE_LAPORAN, formattedContacts, body, 'CREATE_LAPORAN') await logModel.create({ aktivitas: `Job notif wa Pembuatan Laporan berhasil dijadwalkan untuk ${contactNames}`, }) } catch (error) { await logModel.create({ aktivitas: `Gagal menjadwalkan job notif wa Pembuatan Laporan untuk ${contactNames}, Error: ${error.message}`, }) } }