NodeJS в ожидании выполнения запросов к базе данных перед проверкой загруженных файлов Multer - PullRequest
0 голосов
/ 03 апреля 2020

Здравствуйте. Я пытаюсь вставить форму req.body в базу данных перед проверкой файлов Multer с предыдущей страницы, а затем загрузить путь к сохраненным файлам в базу данных.

exports.postSupply = async (req, res) => {

    multer.uploadPicture( async function(req,res,err){
        if (err) { //If something went wrong
          res.status(400).send({ 
            error: err
          })
          return
        }

    if (!req.files) { //If there's isn't any files uploaded from previous page
        res.status(500).send({
          error: 'SERVER ERROR: CANNOT CREATE FILE'
        });

      }
      var equipment = req.body;

      //names used for bodyPraser from previous page
      equipmentName = equipment["equipmentName"];
      contactSurname = equipment["contactSurname"];
      description = equipment["equipmentDes"];
      stock_amount = equipment["quatity"];
      dimension = equipment["dimension"];

    try{
        await database.insertEquipment(equipmentName,contactSurname,description,stock_amount,dimension); //Insert into database
    }
    catch(error){
        console.log(error);
    }

    return res.json(equipment);

    }); 
}

Вот мой журнал ошибок

(node:60301) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:60301) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'transfer-encoding' of undefined
(node:60301) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

Любая помощь приветствуется.

...