migrasi.controller.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const sanksiModel = require('../model/sanksi.model')
  2. const dokumenModel = require('../model/dokumen.model')
  3. const handleError = require('../utils/handleError')
  4. const response = require('../utils/responseHandler')
  5. exports.pengajuan = handleError(async (req, res) => {
  6. const [keberatan, banding] = await Promise.all([
  7. (() =>
  8. sanksiModel.find({
  9. ['pengajuan.keberatan']: { $ne: null, $exists: true },
  10. is_pengajuan_keberatan: { $eq: null, $exists: false },
  11. }))(),
  12. (() =>
  13. sanksiModel.find({
  14. ['jawaban.keberatan']: { $ne: null, $exists: true },
  15. ['pengajuan.banding']: { $ne: null, $exists: true },
  16. is_pengajuan_banding: { $eq: null, $exists: false },
  17. }))()
  18. ])
  19. await Promise.all([
  20. ...keberatan.map(async (e) => {
  21. await sanksiModel.findOneAndUpdate({ _id: e._id }, { is_pengajuan_keberatan: true })
  22. }),
  23. ...banding.map(async (e) => {
  24. await sanksiModel.findOneAndUpdate({ _id: e._id }, { is_pengajuan_banding: true })
  25. })
  26. ])
  27. return response.success(res, {
  28. message: 'Berhasil migrasi pengajuan',
  29. })
  30. })
  31. exports.dokumen = handleError(async (req, res) => {
  32. const dokumen = await dokumenModel.find({ path: /api.sidali.sixsenz.net/ })
  33. if (dokumen?.length) await Promise.all(dokumen.map(async e => {
  34. const path = e.path.split('/').slice(3).join('/')
  35. await dokumenModel.findOneAndUpdate({
  36. _id: e._id
  37. }, {
  38. path: `${process.env.BASE_URL}/${path}`
  39. })
  40. }))
  41. return response.success(res, {
  42. message: 'Berhasil migrasi dokumen',
  43. })
  44. })