我正在尝试将Parse Promises用于Parse.Cloud.run()方法,但它没有给出任何输出。代码用于保存方法
var RoomObj = Parse.Object.extend("Room");
var obj = new RoomObj();
obj.save({ "demo":123 }).then(
function(object) {
// the object was saved.
console.log("PRomise worked");
},
function(error) {
// saving the object failed.
console.log("PRomise error");
});
Parse.Cloud.run("checkRoomsForAvailableBookingTime", {"bookfromtime":bookfromtime,"booktotime":booktotime, "mac_id":mac_id}, {}).then(
function(object) {
console.log("Result object is : " + object);
},
function(error) {
console.log("Result error is : " + error.message + error.code);
});//then block
============================== checkRoomsForAvailableBookingTime方法
Parse.Cloud.define(“checkRoomsForAvailableBookingTime”,function(request,response){
var BookingObj = Parse.Object.extend("Booking");
var bookingQuery= new Parse.Query(BookingObj);
var flag;
var bookfromtime = request.params.bookfromtime;
var booktotime = request.params.booktotime;
var mac_id = request.params.mac_id;
var starttimeArray = [];
var endtimeArray = [];
var currentDate = new Date();
var todayDate = currentDate.getDate() +'-' + (currentDate.getMonth() + 1 ) + '-' +
currentDate.getFullYear();
bookingQuery.equalTo("book_date",todayDate);
bookingQuery.equalTo("room_mac_id",mac_id);
bookingQuery.ascending("book_fromtime");
bookingQuery.find({
success: function(results) {
console.log("TOTAL BOOKINGS :" + results.length);
for(var i=0 ; i< results.length;i++)
{
starttimeArray[i] = results[i].get('book_fromtime');
endtimeArray[i] = results[i].get('book_totime');
}//for loop
var startAndEndArray={
"start":starttimeArray,
"end":endtimeArray
};
if(results.length == 0)
{
// console.log("No booking is done for today so you can book the room");
// return true;
flag = true;
} //if block
else if(results.length == 1 )
{
if(bookfromtime < starttimeArray[0] && booktotime <= starttimeArray[0])
{
// console.log("You can book rooom");
// return true;
flag = true;
}
else if(bookfromtime >= endtimeArray[0])
{
// console.log("You can book rooom");
// return true;
flag = true;
}
else
{
// console.log("CANNOT BOOK ROOM");
// return false;
flag = false;
}
} //else if block
else if(bookfromtime < starttimeArray[0] && booktotime <= starttimeArray[0]){
// console.log("You can book rooom");
// return true;
flag = true;
}
else if(bookfromtime >= endtimeArray[results.length -1] )
{
// console.log("You can book rooom");
// return true;
flag = true;
}
else
{
console.log("IN ELSE BLOCK");
for(var counter=0 ; counter < results.length ;counter++)
{
if(bookfromtime > starttimeArray[counter] && bookfromtime <= starttimeArray[counter+1])
{
// console.log("First if");
if(bookfromtime >= endtimeArray[counter] && booktotime <= starttimeArray[counter+1])
{
// console.log("You can book the room");
// return true;
flag = true;
}//if block
}//if block
}//for loop block
// console.log("CANNOT BOOK ROOM");
// return false;
flag = false;
} //outer else block
response.success(flag);
},
error: function(error) {
response.error("Error: " + error.code + " " + error.message);
}
});//find block
//query.notContainedIn("user_id",userArray);
});//function block
任何人都可以帮我解决问题吗?感谢。