|
|
@@ -12,7 +12,7 @@ const {
|
|
|
TEMPLATE_KEBERATAN,
|
|
|
TEMPLATE_BANDING,
|
|
|
TEMPLATE_REMINDER,
|
|
|
- TEMPLATE_REMINDER2,
|
|
|
+ TEMPLATE_REMINDER2
|
|
|
} = require('../utils/constanta')
|
|
|
const moment = require('moment')
|
|
|
const autoSaveModel = require('../model/autoSave.model')
|
|
|
@@ -21,28 +21,30 @@ const userModel = require('../model/user.model')
|
|
|
const { addManyDokumen } = require('../utils/dokumenFunction')
|
|
|
const logModel = require('../model/log.model')
|
|
|
const kontakModel = require('../model/kontak.model')
|
|
|
+const childProcess = require('child_process')
|
|
|
+const { validate } = require('../utils/validation')
|
|
|
|
|
|
exports.keberatan = handleError(async (req, res) => {
|
|
|
const dataSanksi = await sanksiModel
|
|
|
.find({
|
|
|
'tanggal_akhir_keberatan': {
|
|
|
- $lt: moment().add(-1, 'day').toISOString(),
|
|
|
+ $lt: moment().add(-1, 'day').toISOString()
|
|
|
},
|
|
|
'is_pengajuan_keberatan': {
|
|
|
$exists: false,
|
|
|
- $eq: null,
|
|
|
+ $eq: null
|
|
|
},
|
|
|
'pengajuan.cabut_sanksi': {
|
|
|
$exists: false,
|
|
|
- $eq: null,
|
|
|
- },
|
|
|
+ $eq: null
|
|
|
+ }
|
|
|
})
|
|
|
.populate('user')
|
|
|
.populate('laporan')
|
|
|
|
|
|
if (!dataSanksi.length) {
|
|
|
return response.success(res, {
|
|
|
- message: 'Tidak ada notifikasi yg dikirim',
|
|
|
+ message: 'Tidak ada notifikasi yg dikirim'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -51,12 +53,12 @@ exports.keberatan = handleError(async (req, res) => {
|
|
|
async (sanksi) =>
|
|
|
await sanksiModel.findByIdAndUpdate(sanksi._id, {
|
|
|
is_pengajuan_keberatan: false,
|
|
|
- last_step: "Dokumen Perbaikan"
|
|
|
+ last_step: 'Dokumen Perbaikan'
|
|
|
})
|
|
|
)
|
|
|
)
|
|
|
return response.success(res, {
|
|
|
- message: 'Notifikasi berhasil terkirim',
|
|
|
+ message: 'Notifikasi berhasil terkirim'
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -64,27 +66,27 @@ exports.banding = handleError(async (req, res) => {
|
|
|
const dataSanksi = await sanksiModel
|
|
|
.find({
|
|
|
'tanggal_akhir_banding': {
|
|
|
- $lt: moment().add(-1, 'day').toISOString(),
|
|
|
+ $lt: moment().add(-1, 'day').toISOString()
|
|
|
},
|
|
|
'is_pengajuan_banding': {
|
|
|
$exists: false,
|
|
|
- $eq: null,
|
|
|
+ $eq: null
|
|
|
},
|
|
|
'batas_waktu.jawaban_keberatan': {
|
|
|
$exists: true,
|
|
|
- $ne: null,
|
|
|
+ $ne: null
|
|
|
},
|
|
|
['pengajuan.cabut_sanksi']: {
|
|
|
$exists: false,
|
|
|
- $eq: null,
|
|
|
- },
|
|
|
+ $eq: null
|
|
|
+ }
|
|
|
})
|
|
|
.populate('user')
|
|
|
.populate('laporan')
|
|
|
|
|
|
if (!dataSanksi.length) {
|
|
|
return response.success(res, {
|
|
|
- message: 'Tidak ada notifikasi yg dikirim',
|
|
|
+ message: 'Tidak ada notifikasi yg dikirim'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -110,13 +112,13 @@ exports.banding = handleError(async (req, res) => {
|
|
|
// ])
|
|
|
await sanksiModel.findByIdAndUpdate(sanksi._id, {
|
|
|
is_pengajuan_banding: false,
|
|
|
- last_step: "Dokumen Perbaikan"
|
|
|
+ last_step: 'Dokumen Perbaikan'
|
|
|
})
|
|
|
}
|
|
|
)
|
|
|
)
|
|
|
return response.success(res, {
|
|
|
- message: 'Notifikasi berhasil terkirim',
|
|
|
+ message: 'Notifikasi berhasil terkirim'
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -125,12 +127,12 @@ exports.reminderKeberatan = handleError(async (req, res) => {
|
|
|
.find({
|
|
|
'batas_waktu.jawaban_keberatan': {
|
|
|
$exists: true,
|
|
|
- $ne: null,
|
|
|
+ $ne: null
|
|
|
},
|
|
|
'jawaban.keberatan': {
|
|
|
$exists: false,
|
|
|
- $eq: null,
|
|
|
- },
|
|
|
+ $eq: null
|
|
|
+ }
|
|
|
})
|
|
|
.populate('user')
|
|
|
.populate('laporan')
|
|
|
@@ -146,28 +148,28 @@ exports.reminderKeberatan = handleError(async (req, res) => {
|
|
|
{
|
|
|
key: '1',
|
|
|
value: 'no_laporan',
|
|
|
- value_text: e.laporan.no_laporan,
|
|
|
+ value_text: e.laporan.no_laporan
|
|
|
},
|
|
|
{
|
|
|
key: '2',
|
|
|
value: 'keterangan',
|
|
|
- value_text: 'Proses Menjawab Pengajuan Keberatan',
|
|
|
+ value_text: 'Proses Menjawab Pengajuan Keberatan'
|
|
|
},
|
|
|
{
|
|
|
key: '3',
|
|
|
value: 'pt',
|
|
|
- value_text: e.laporan.pt.nama,
|
|
|
+ value_text: e.laporan.pt.nama
|
|
|
},
|
|
|
{
|
|
|
key: '4',
|
|
|
value: 'masa',
|
|
|
- value_text: `menjawab pengajuan keberatan tersisa ${dayLeft} hari lagi.`,
|
|
|
- },
|
|
|
+ value_text: `menjawab pengajuan keberatan tersisa ${dayLeft} hari lagi.`
|
|
|
+ }
|
|
|
])
|
|
|
} catch (error) {
|
|
|
return response.error(res, {
|
|
|
message: 'Notifikasi gagal terkirim',
|
|
|
- error: error.message,
|
|
|
+ error: error.message
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -184,7 +186,7 @@ exports.reminderKeberatan = handleError(async (req, res) => {
|
|
|
}
|
|
|
|
|
|
return response.success(res, {
|
|
|
- message,
|
|
|
+ message
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -193,12 +195,12 @@ exports.reminderBanding = handleError(async (req, res) => {
|
|
|
.find({
|
|
|
'batas_waktu.jawaban_banding': {
|
|
|
$exists: true,
|
|
|
- $ne: null,
|
|
|
+ $ne: null
|
|
|
},
|
|
|
'jawaban.banding': {
|
|
|
$exists: false,
|
|
|
- $eq: null,
|
|
|
- },
|
|
|
+ $eq: null
|
|
|
+ }
|
|
|
})
|
|
|
.populate('user')
|
|
|
.populate('laporan')
|
|
|
@@ -214,28 +216,28 @@ exports.reminderBanding = handleError(async (req, res) => {
|
|
|
{
|
|
|
key: '1',
|
|
|
value: 'no_laporan',
|
|
|
- value_text: e.laporan.no_laporan,
|
|
|
+ value_text: e.laporan.no_laporan
|
|
|
},
|
|
|
{
|
|
|
key: '2',
|
|
|
value: 'keterangan',
|
|
|
- value_text: 'Proses Menjawab Pengajuan Banding',
|
|
|
+ value_text: 'Proses Menjawab Pengajuan Banding'
|
|
|
},
|
|
|
{
|
|
|
key: '3',
|
|
|
value: 'pt',
|
|
|
- value_text: e.laporan.pt.nama,
|
|
|
+ value_text: e.laporan.pt.nama
|
|
|
},
|
|
|
{
|
|
|
key: '4',
|
|
|
value: 'masa',
|
|
|
- value_text: `menjawab pengajuan banding tersisa ${dayLeft} hari lagi.`,
|
|
|
- },
|
|
|
+ value_text: `menjawab pengajuan banding tersisa ${dayLeft} hari lagi.`
|
|
|
+ }
|
|
|
])
|
|
|
} catch (error) {
|
|
|
return response.error(res, {
|
|
|
message: 'Notifikasi gagal terkirim',
|
|
|
- error: error.message,
|
|
|
+ error: error.message
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -252,28 +254,28 @@ exports.reminderBanding = handleError(async (req, res) => {
|
|
|
}
|
|
|
|
|
|
return response.success(res, {
|
|
|
- message,
|
|
|
+ message
|
|
|
})
|
|
|
})
|
|
|
|
|
|
exports.updateStatusSanksi = handleError(async (req, res) => {
|
|
|
const sanksi = await sanksiModel.find({
|
|
|
'masa_berlaku.to_date': {
|
|
|
- $lte: new Date().toISOString(),
|
|
|
+ $lte: new Date().toISOString()
|
|
|
},
|
|
|
- aktif: true,
|
|
|
+ aktif: true
|
|
|
})
|
|
|
|
|
|
Promise.all(
|
|
|
sanksi.map(async (e) =>
|
|
|
sanksiModel.findByIdAndUpdate(e._id, {
|
|
|
- aktif: false,
|
|
|
+ aktif: false
|
|
|
})
|
|
|
)
|
|
|
)
|
|
|
|
|
|
return response.success(res, {
|
|
|
- message: 'update status sanksi berhasil',
|
|
|
+ message: 'update status sanksi berhasil'
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -282,20 +284,20 @@ exports.save = handleError(async (req, res) => {
|
|
|
const { laporan: isLaporan, sanksi: isSanksi } = req.query
|
|
|
const user = req.user
|
|
|
|
|
|
- let autoData = null;
|
|
|
- let laporan = null;
|
|
|
- let sanksi = null;
|
|
|
+ let autoData = null
|
|
|
+ let laporan = null
|
|
|
+ let sanksi = null
|
|
|
if (isLaporan === 'true') {
|
|
|
- laporan = await cekSatuDataLaporan(res, user, id);
|
|
|
+ laporan = await cekSatuDataLaporan(res, user, id)
|
|
|
if (!laporan) return
|
|
|
- autoData = await autoSaveModel.findOne({ laporan_id: laporan._id });
|
|
|
+ autoData = await autoSaveModel.findOne({ laporan_id: laporan._id })
|
|
|
} else if (isSanksi === 'true') {
|
|
|
- sanksi = await cekSatuDataSanksi(res, user, id);
|
|
|
+ sanksi = await cekSatuDataSanksi(res, user, id)
|
|
|
if (!sanksi) return
|
|
|
- autoData = await autoSaveModel.findOne({ sanksi_id: sanksi._id });
|
|
|
+ autoData = await autoSaveModel.findOne({ sanksi_id: sanksi._id })
|
|
|
} else {
|
|
|
return response.error(res, {
|
|
|
- message: 'query harus sanksi atau laporan yg bernilai true',
|
|
|
+ message: 'query harus sanksi atau laporan yg bernilai true'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -308,7 +310,7 @@ exports.save = handleError(async (req, res) => {
|
|
|
dataSuratBA: req.body?.PenetapanSanksi?.dataSuratBA || dataSave.laporan.PenetapanSanksi?.dataSuratBA,
|
|
|
dataUpload: req.body?.PenetapanSanksi?.dataUpload || dataSave.laporan.PenetapanSanksi?.dataUpload,
|
|
|
dataPelanggaran: req.body?.PenetapanSanksi?.dataPelanggaran || dataSave.laporan.PenetapanSanksi?.dataPelanggaran,
|
|
|
- activeStep: req.body?.PenetapanSanksi?.activeStep || dataSave.laporan.PenetapanSanksi?.activeStep,
|
|
|
+ activeStep: req.body?.PenetapanSanksi?.activeStep || dataSave.laporan.PenetapanSanksi?.activeStep
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -324,7 +326,7 @@ exports.save = handleError(async (req, res) => {
|
|
|
}
|
|
|
|
|
|
return response.success(res, {
|
|
|
- message: 'Berhasil menyimpan data auto save',
|
|
|
+ message: 'Berhasil menyimpan data auto save'
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -332,26 +334,26 @@ exports.getSave = handleError(async (req, res) => {
|
|
|
const { id } = req.params
|
|
|
const { laporan: isLaporan, sanksi: isSanksi } = req.query
|
|
|
|
|
|
- let data = null;
|
|
|
- let laporan = null;
|
|
|
- let sanksi = null;
|
|
|
+ let data = null
|
|
|
+ let laporan = null
|
|
|
+ let sanksi = null
|
|
|
if (isLaporan === 'true') {
|
|
|
laporan = await laporanModel.findById(id)
|
|
|
if (!laporan) return response.error(res, {
|
|
|
code: 404,
|
|
|
message: 'laporan_id tidak ada'
|
|
|
})
|
|
|
- data = (await autoSaveModel.findOne({ laporan_id: laporan._id })).laporan;
|
|
|
+ data = (await autoSaveModel.findOne({ laporan_id: laporan._id })).laporan
|
|
|
} else if (isSanksi === 'true') {
|
|
|
sanksi = await sanksiModel.findById(id)
|
|
|
if (!sanksi) return response.error(res, {
|
|
|
code: 404,
|
|
|
message: 'sanksi_id tidak ada'
|
|
|
})
|
|
|
- data = (await autoSaveModel.findOne({ sanksi_id: sanksi._id })).sanksi;
|
|
|
+ data = (await autoSaveModel.findOne({ sanksi_id: sanksi._id })).sanksi
|
|
|
} else {
|
|
|
return response.error(res, {
|
|
|
- message: 'harus terdapat query sanksi atau laporan yg bernilai true',
|
|
|
+ message: 'harus terdapat query sanksi atau laporan yg bernilai true'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -362,69 +364,47 @@ exports.getSave = handleError(async (req, res) => {
|
|
|
})
|
|
|
|
|
|
exports.backup = handleError(async (req, res) => {
|
|
|
- const dataBakup = await Promise.all([
|
|
|
- (async () => {
|
|
|
- const path = 'backup/' + new Date().getTime() + '-sanksi.json'
|
|
|
- const sanksi = await sanksiModel.find()
|
|
|
- fs.writeFileSync(path, JSON.stringify(sanksi))
|
|
|
- const { size } = fs.statSync(path)
|
|
|
- const mimetype = 'application/json'
|
|
|
- const buffer = fs.readFileSync(path)
|
|
|
- return { buffer, mimetype, size, originalname: 'sanksi.json' }
|
|
|
- })(),
|
|
|
- (async () => {
|
|
|
- const path = 'backup/' + new Date().getTime() + '-laporan.json'
|
|
|
- const laporan = await laporanModel.find()
|
|
|
- fs.writeFileSync(path, JSON.stringify(laporan))
|
|
|
- const { size } = fs.statSync(path)
|
|
|
- const mimetype = 'application/json'
|
|
|
- const buffer = fs.readFileSync(path)
|
|
|
- return { buffer, mimetype, size, originalname: 'laporan.json' }
|
|
|
- })(),
|
|
|
- (async () => {
|
|
|
- const path = 'backup/' + new Date().getTime() + '-user.json'
|
|
|
- const user = await userModel.find()
|
|
|
- fs.writeFileSync(path, JSON.stringify(user))
|
|
|
- const { size } = fs.statSync(path)
|
|
|
- const mimetype = 'application/json'
|
|
|
- const buffer = fs.readFileSync(path)
|
|
|
- return { buffer, mimetype, size, originalname: 'user.json' }
|
|
|
- })(),
|
|
|
- (async () => {
|
|
|
- const path = 'backup/' + new Date().getTime() + '-chunk.json'
|
|
|
- const chunk = await chunkModel.find().lean()
|
|
|
- fs.writeFileSync(path, JSON.stringify(chunk))
|
|
|
- // const { size } = fs.statSync(path)
|
|
|
- // const mimetype = 'application/json'
|
|
|
- // const buffer = fs.readFileSync(path)
|
|
|
- // return { buffer, mimetype, size, originalname: 'chunk.json' }
|
|
|
- })(),
|
|
|
- (async () => {
|
|
|
- const path = 'backup/' + new Date().getTime() + '-dokumen.json'
|
|
|
- const dokumen = await dokumenModel.find()
|
|
|
- fs.writeFileSync(path, JSON.stringify(dokumen))
|
|
|
- const { size } = fs.statSync(path)
|
|
|
- const mimetype = 'application/json'
|
|
|
- const buffer = fs.readFileSync(path)
|
|
|
- return { buffer, mimetype, size, originalname: 'dokumen.json' }
|
|
|
- })(),
|
|
|
- (async () => {
|
|
|
- const path = 'backup/' + new Date().getTime() + '-pemantauan.json'
|
|
|
- const pemantauan = await dokumenModel.find()
|
|
|
- fs.writeFileSync(path, JSON.stringify(pemantauan))
|
|
|
- const { size } = fs.statSync(path)
|
|
|
- const mimetype = 'application/json'
|
|
|
- const buffer = fs.readFileSync(path)
|
|
|
- return { buffer, mimetype, size, originalname: 'pemantauan.json' }
|
|
|
- })(),
|
|
|
- ])
|
|
|
- // const dokumen = await addManyDokumen(dataBakup)
|
|
|
- // const tes = await backupModel.create({
|
|
|
- // dokumen: dokumen.map(e => e._id)
|
|
|
- // })
|
|
|
+ let db = 'ptb-db'
|
|
|
+ const baseUrl = coba.decrypt(process.env.W8A1C)
|
|
|
+ if (baseUrl.includes('dev')) db = 'ptb-db-dev'
|
|
|
+
|
|
|
+ let cmd = `mongodump -d ${db} -o backup/${moment().format('YYYY-MM-DD')}`
|
|
|
+
|
|
|
+ const akun = coba.decrypt(process.env.MYDSY).match(/\/\/(.*?)@/i)
|
|
|
+ if (akun?.length) {
|
|
|
+ const [username, password] = akun[1].split(':')
|
|
|
+ cmd += ` -u ${username} -p ${password} --authenticationDatabase admin`
|
|
|
+ }
|
|
|
+
|
|
|
+ childProcess.execSync(cmd)
|
|
|
return response.success(res, {
|
|
|
- message: 'berhasil membuat backup',
|
|
|
- // data: tes
|
|
|
+ message: 'berhasil membuat backup'
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+exports.restore = handleError(async (req, res) => {
|
|
|
+ const isValid = validate(res, {
|
|
|
+ tanggal: { type: 'date', convert: true }
|
|
|
+ }, req.query)
|
|
|
+ if (!isValid) return
|
|
|
+
|
|
|
+ const { tanggal } = req.query
|
|
|
+ let db = 'ptb-db'
|
|
|
+ const baseUrl = coba.decrypt(process.env.W8A1C)
|
|
|
+ if (baseUrl.includes('dev')) db = 'ptb-db-dev'
|
|
|
+
|
|
|
+ let cmd = `mongorestore -d ${db}`
|
|
|
+
|
|
|
+ const akun = coba.decrypt(process.env.MYDSY).match(/\/\/(.*?)@/i)
|
|
|
+ if (akun?.length) {
|
|
|
+ const [username, password] = akun[1].split(':')
|
|
|
+ cmd += ` -u ${username} -p ${password} --authenticationDatabase admin`
|
|
|
+ }
|
|
|
+ cmd += ` backup/${tanggal}`
|
|
|
+
|
|
|
+ childProcess.execSync(cmd)
|
|
|
+ return response.success(res, {
|
|
|
+ message: 'berhasil membuat backup'
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -434,7 +414,7 @@ exports.getBackup = handleError(async (req, res) => {
|
|
|
const data = await backupModel.findById(id).populate('dokumen')
|
|
|
if (!data) return response.error(res, {
|
|
|
code: 404,
|
|
|
- message: 'Not Found',
|
|
|
+ message: 'Not Found'
|
|
|
})
|
|
|
|
|
|
return response.success(res, {
|
|
|
@@ -444,11 +424,13 @@ exports.getBackup = handleError(async (req, res) => {
|
|
|
})
|
|
|
|
|
|
exports.berakhirSanksi = handleError(async (req, res) => {
|
|
|
- const sanksi = await sanksiModel.find({'masa_berlaku.to_date': {
|
|
|
+ const sanksi = await sanksiModel.find({
|
|
|
+ 'masa_berlaku.to_date': {
|
|
|
$ne: null,
|
|
|
$exists: true
|
|
|
- }}).populate('laporan')
|
|
|
- let count = 0;
|
|
|
+ }
|
|
|
+ }).populate('laporan')
|
|
|
+ let count = 0
|
|
|
|
|
|
await Promise.all(sanksi.map(async e => {
|
|
|
const dayLeft = moment(e.masa_berlaku.to_date).diff(
|
|
|
@@ -474,11 +456,11 @@ exports.berakhirSanksi = handleError(async (req, res) => {
|
|
|
value_text: `habis masa berlaku sanksi tersisa ${dayLeft} hari lagi.`
|
|
|
}
|
|
|
])
|
|
|
- count++;
|
|
|
+ count++
|
|
|
} catch (error) {
|
|
|
return response.error(res, {
|
|
|
message: 'Notifikasi gagal terkirim',
|
|
|
- error: error.message,
|
|
|
+ error: error.message
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -490,6 +472,6 @@ exports.berakhirSanksi = handleError(async (req, res) => {
|
|
|
aktivitas: `Server berhasil mengirim notif wa kepada ${contacts.map((e) => e.nama).join(', ')} untuk reminder berakhirnya sanksi`
|
|
|
})
|
|
|
return response.success(res, {
|
|
|
- message,
|
|
|
+ message
|
|
|
})
|
|
|
})
|