Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
2
Indexable
Never
export const uploadBAP = async (req, res, next) => {
  upload.single('bap-bukti')(req, res, async (err) => {
    if (err) {
      // something error
      return res.status(500).json({
        message: err,
        data: {}
      })
    }


    /*
    if (req.file === undefined) {
      // file undefined
      return res.status(400).json({
        message: 'Bad request : No File Selected',
        data: {}
      })
    }
    */

    const { nip, materi, kegiatan, tanggal, idPerkuliahan, idJadwal } = req.body

    try {
      
      // Bypass upload
      // const url = req.file.path
      // Skip
      const url = "Bypassed"

      const results = await DosenService.uploadBAP(nip, materi, kegiatan, url, tanggal, idPerkuliahan, idJadwal)
      const rows = results[0]
      res.json({
        message: `Dosen dengan nip ${nip} mengupload bap pada tgl ${tanggal} untuk idPerkuliahan ${idPerkuliahan} dan idJadwal ${idJadwal}`,
        data: rows
      })
    } catch (error) {
      res.status(500).json({ error })
    }
  })
}