具有Resolve值的节点嵌套promise

时间:2018-03-30 16:11:50

标签: javascript node.js promise

我有三个异步功能,它们应该互相支持。

我的代码:

let companyNameCheck = req.body.name;
let companyNameCheckPromise = new Promise((resolve, reject) => {
    generalHelper.companyExistsHelper(res, companyNameCheck, reject);
    resolve();
});

companyNameCheckPromise.then((data) => {
    // CHECK IF LOGO EXISTS
    if (!req.files)
        return res.status(400).send({
            code: errorHandling.FILE_UPLOAD_CODE,
            message: errorHandling.FILE_UPLOAD_MESSAGE
        });

    //FILE UPLOAD AND GETTING THE FILE NAME WITH PROMISE
    let logo = req.files.logo;
    data = fileHelper.fileUploadHelper(res, logo, "companies_logos");
    console.log(data); //THIS RETURN THE DATA
    return data;
});

companyNameCheckPromise.then((data) => {
    console.log(data); // THIS RETURN UNDEFIND
});

问题:

我想将值从第一个then传递到第二个then

我尝试了什么:

我尝试创建一个全局变量并将Resolve分配给此全局变量,但它仍然不是解决方案。

1 个答案:

答案 0 :(得分:0)

SELECT REPLACE(REPLACE(Col_1, CHAR(13), ''), CHAR(10), '') FROM table_1 需要返回Promise:

companyNameCheckPromise