handle all not found errors
This commit is contained in:
@@ -8,11 +8,10 @@ module.exports.create = [
|
||||
if (!req.files || !req.files.pdf) return res.status(422).json({validation: {pdf: {msg: v_m['fa'].required.file}}})
|
||||
if (req.files.pdf.mimetype.split('/')[1] !== 'pdf') return res.status(422).json({validation: {pdf: {msg: v_m['fa'].file_types.pdf}}})
|
||||
|
||||
|
||||
MainCatalog.find({}, (err, catalogs) => {
|
||||
if (err) console.log(err)
|
||||
if (catalogs.length) {
|
||||
let firstFile = catalogs[0]
|
||||
|
||||
if (firstFile.file[req.body.locale]) fs.unlink(`./static/${firstFile.file[req.body.locale]}`, err => {
|
||||
if (err) console.log(err)
|
||||
})
|
||||
@@ -24,8 +23,6 @@ module.exports.create = [
|
||||
req.files.pdf.mv(`./static/uploads/pdf/${req.body.locale}_${req.files.pdf.name}`)
|
||||
return res.json(firstFile)
|
||||
})
|
||||
|
||||
|
||||
} else {
|
||||
const data = {created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss'), file: {}}
|
||||
data.file[req.body.locale] = req.body.locale + '_' + req.files.pdf.name
|
||||
|
||||
Reference in New Issue
Block a user