Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function inup_pembelajaran_tugas(request, reply) {
- let validation = new validator(request.body, {
- id_jurnal: 'required',
- kd_jenis_tugas: 'required',
- nama_tugas: 'required',
- })
- if (!validation.fails()) {
- try {
- let id_pembelajaran
- if (request.body.id_pembelajaran == null) {
- id_pembelajaran = null
- } else {
- id_pembelajaran = request.body.id_pembelajaran
- }
- let id_jurnal = request.body.id_jurnal
- let id_user = request.user.id
- let kd_jenis_tugas = request.body.kd_jenis_tugas
- let nama_tugas = request.body.nama_tugas
- let deskripsi = request.body.deskripsi
- let url = request.body.url
- let file_berkas = null
- let tgl_mulai = request.body.tgl_mulai
- let tgl_akhir = request.body.tgl_akhir
- if (isUrl(url)) {
- url = {"url": url}
- if (isEmpty(request.body.file)) {
- url = null
- file_berkas = null
- } else {
- file_berkas = new Buffer(request.body.file, 'base64')
- let worthExists = await Promise.all([
- Storage.exists('mmp/temp' + id_jurnal + '.pdf'),
- Storage.exists('mmp/' + id_jurnal + '.pdf')
- ])
- if (worthExists[0] === false && worthExists[1] === true) {
- await Storage.copy('mmp/' + id_user + '.pdf', 'mmp/temp/' + id_jurnal + '.pdf');
- }
- let pathFile = 'mmp/' + id_jurnal + '.pdf'
- await Promise.all([
- Storage.put(file_berkas, id_user + '.pdf', pathFile)
- ])
- url = null
- let filesPath = {"file": pathFile}
- file_berkas = JSON.stringify(filesPath)
- }
- } else {
- res.isError('Link URL tidak valid!!', reply, 400)
- }
- // buat nampilin param ke response 200 hanya untuk cek saja
- let data = {
- id_pembelajaran,
- id_jurnal,
- id_user,
- kd_jenis_tugas,
- nama_tugas,
- deskripsi,
- url,
- file_berkas,
- tgl_mulai,
- tgl_akhir
- }
- res.isSuccess(data, "sukses", reply)
- // let insertPembelajaranTugas = await jurnal.inup_pembelajran_tugasM(
- // id_pembelajaran,
- // id_jurnal,
- // id_user,
- // kd_jenis_tugas,
- // nama_tugas,
- // deskripsi,
- // url,
- // file_berkas,
- // tgl_mulai,
- // tgl_akhir
- // )
- //
- // var data = insertPembelajaranTugas[0].data
- // var errCode = insertPembelajaranTugas[0].errcode
- // var errMsg = insertPembelajaranTugas[0].errmessage
- //
- // console.log("CODE ERROR >> ", errCode)
- //
- // switch (errCode) {
- // case '1':
- // res.isSuccess(data, errMsg, reply)
- // break
- // case '2':
- // res.isSuccess(data, errMsg, reply)
- // break
- // default:
- // res.isError(errMsg, reply, 400)
- // break
- // }
- } catch (error) {
- res.isError(error, reply)
- }
- } else {
- res.isError('Terdapat Paramater Kurang / Tidak Valid', reply, validation.errors(), 403)
- }
- }
Add Comment
Please, Sign In to add comment