获取Clients.findById不是函数错误,也不知道为什么

时间:2019-10-22 15:20:44

标签: node.js reactjs database redux

我有一个用于存储数据和从MS SQL数据库检索的api。我可以从数据库中检索所有客户端,但是当我尝试仅提取一个客户端时,我会得到 Clients.findById不是函数

这是我正在使用的代码:

// Fetch all Clients
exports.findAll = (req, res) => {
    Clients.findAll().then(clients => {
        // Send all Clients to Client
        res.send(clients);
    }).catch(err => {
        res.status(500).send("Error -> " + err);
    })
};

// Find a Customer by Id
exports.findById = (req, res) => {
    Clients.findById(req.params.id).then(client => {
        res.send(client);
    }).catch(err => {
        res.status(500).send("Error -> " + err);
    })
};

...

当我在邮递员中使用 http://localhost:8080/api/clients/0

的网址进行测试时

我得到了错误。我不确定为什么findAll可以正常工作,而findById不能正常工作。

0 个答案:

没有答案