| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- const laporanModel = require('../model/laporan.model')
- const handleError = require('../utils/handleError')
- const response = require('../utils/responseHandler')
- const { validate } = require('../utils/validation')
- exports.update = handleError(async (req, res) => {
- const user = req.user
- const { id } = req.params
- const isValid = validate(res, req.body, {
- judul: 'string',
- dari_tanggal: { type: 'date', convert: true },
- sampai_tanggal: { type: 'date', convert: true },
- warna: 'string',
- })
- if (!isValid) return
- const { judul, dari_tanggal, sampai_tanggal, warna } = req.body
- let laporan = await laporanModel.findOne({ _id: id })
- if (
- laporan &&
- !(
- (user.role.id === 2021 &&
- laporan.role_data === 'lldikti' &&
- laporan.pt.pembina.id === user.lembaga.id &&
- laporan.aktif === true) ||
- (user.role.id === 2020 &&
- laporan.role_data === 'dikti' &&
- laporan.aktif === true)
- )
- ) {
- return response.error(res, {
- message: 'laporan_id tidak ada',
- code: 404,
- })
- }
- const data = await laporanModel.findByIdAndUpdate(
- laporan._id,
- {
- jadwal: {
- judul,
- dari_tanggal,
- sampai_tanggal,
- warna,
- },
- },
- {
- new: true,
- }
- )
- return response.success(res, {
- message: 'Berhasil ubah jadwal',
- data,
- })
- })
|