从解析db获取日期返回undefined

时间:2015-11-04 05:07:44

标签: javascript parse-platform cloud-code

我遇到了一个问题,在使用query.first()获取行之后,我想从db访问字段codeExpiry并将其与日期和时间进行比较。获取的日期始终记录为未定义。

以下是代码:

Parse.Cloud.define("SmsCodeVerification", function(request, response) {

    console.log("Code from User: " +request.params.code);

    var id = request.params.userId;

    var userQuery = new Parse.Query("User");
    userQuery.equalTo("objectId", id);

    var object = {};

    var temp = userQuery.first().then(function(result){

        object = result.toJSON();

        console.log("Code expiry from database: " + **object.codeExpiry**);

        var date = new Date();

        var exp = **object["codeExpiry"];**

        console.log("Date of received code: " + date);

        console.log("Expiry: " + exp);

        if(object.cellVerificationCode == request.params.code){

            console.log(+exp+ " Expiry Date,");
            console.log(+date+ " Current Date,");

                if(exp > date){

                    response.success("Code expiry date has passed. The system will now generate a new code.");

                } else {

                    console.log("Code Received.");

                    result.set("isCellNoVerified", true);

                    result.save(null, { useMasterKey: true }).then(function() {
                            response.success("Save Successful.");

                            }, function(error){
                                response.error(error);  
                    }); 
                }
            } else {

                response.error("Code not recognized.");
            }       

    }); 

    temp.then(function(){

        console.log("End of execution!!");
    });

});

此处,Object.codeExpiry和result.codeExpiry始终记录为undefined或[object Object]

1 个答案:

答案 0 :(得分:0)

解析用户类Parse.User的名称,而不是“用户”。将查询初始化为:

 var userQuery = new Parse.Query(Parse.User);