sequelize事务因完成状态提交而失败

时间:2018-09-08 11:31:07

标签: node.js sequelize.js

我的代码如下所示:

const up = (x, y, isZ) => {

    let Info = parseFloat(y).toFixed(2);
    return new Promise((resolve, reject) => {

        return db.sequelize.transaction((t) => {
            return db.test.find({where: {id: x}}).then((info) => {
                if (isZ) {
                    info.test_balance = (parseFloat(info.test_balance) - parseFloat(Info)).toFixed(2);
                }
                else {
                    info.test_balance = (parseFloat(info.test_balance) + parseFloat(Info)).toFixed(2);
                }

                return info.save({transaction: t, autocommit: false, lock: t.LOCK.UPDATE});
            }).then(() => {
                return t.commit();
            }).then(() => {
                resolve();
            }).catch(() => {
                t.rollback();
                reject();
            })
        })
    });


};

对于此代码,它给了我这个错误:

0|app      | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
0|app      | Error: Transaction cannot be committed because it has been finished with state: commit

0 个答案:

没有答案