TypeError: undefined不是一个函数GET请求/数据库调用

TypeError: undefined is not a function GET request/db call

本文关键字:GET 函数 一个 请求 调用 数据库 undefined TypeError      更新时间:2023-09-26

当使用node.js执行GET请求时,我得到一个TypeError。它看起来和我所有其他模块中的所有其他请求一样。在我创建的两个模块之间执行的代码中返回错误,所以我不确定发生了什么。

错误:

TypeError: undefined is not a function
at Object.exports.getFollowingWatches (/Users/M/Desktop/Projects/BX-Server/modules/feed/feeddb.js:23:11)
at /Users/M/Desktop/Projects/BX-Server/modules/feed/index.js:55:5
at Layer.handle [as handle_request] (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/layer.js:95:5)
at /Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:330:12)
at next (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:271:10)
at Function.handle (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:176:3)

Get请求:

router.get("/getFollowingWatches", function(req, res, callback) {
    var userId = req.query.userId;
    var position = req.query.pos;
    if ((!(userId >= 1 && userId <= 9223372036854775807)) || (userId == undefined)) { //max signed
        res.status(400).send("userId invalid");
        return;
    }
    if (!(position >= 0 && position <= 100000)) { //what is the optimal max number? should do something elegant when this number is reached
        res.status(400).send("max position number exceeded");
        return;
    }
    db.getFollowingWatches(userId, position, function(feed) {
        if (!feed) {
            res.status(404).send("feed could not be loaded");
        } else {
            res.json(feed);
        }
    });
});

db call:

exports.getFollowingWatches = function(userId, position, callback) {
    //@TODO: update interval time
    var sql = "SELECT  p.profilename AS watchname, p.idperson AS watchid, b.idbounty, b.description, b.idcreatedfor, b.contenttype " +
        "FROM bounty b " +
        "INNER JOIN watch w ON b.idbounty = w.idbounty " +
        "INNER JOIN person p ON p.idperson = w.idperson " +
        "WHERE w.idperson IN (select beingfollowed from follow where isfollowing = ?) " +
        "AND timewatched >= CURDATE() - INTERVAL 100 YEAR " +
        "AND b.iscomplete = 0 " +
        "LIMIT BY ?, ?";
    var inserts = [userId, parseInt(position), 20];
    sql = mysql.format(sql, inserts);
    console.log("getFollowingWatches db function running... " + sql);
    dbcommon.executestatement(pool, sql, callback); //this line executes but an error is returned before the if statement is hit back in the GET request
};

dbcommon.executestatement……正在执行,但在GET请求中执行if语句之前,错误被击中

我没有大写dbcommon.executeStatement中的S。这个问题现在解决了。编程,lol。