异步请求定期失败,没有错误

时间:2017-08-28 22:59:22

标签: javascript firebase async.js

我正在尝试在iOS上本地构建一个约会预订系统,最后一步涉及到api的Async,它会检查已经存在的约会及时重叠,如果它没有进行预订。如果没有,它会更新约会对象,说无法进行预订。然而,每当我从应用程序发出请求时,它有时会工作,它只是做出响应而没有任何反应。我将nodejs部署到了Heroku。 api是使用Nodejs构建的,而数据库是使用Firebase。 免责声明:Nodejs的新手

Nodejs代码

function handleAsyncFunctionCall(){
var starCountRefasync = firebase.database().ref('bookings').child(barberShopID);
starCountRefasync.on('value', function(snapshotss){
    var dicCollection = snapshotss.val();
    async.each(dicCollection, function(file, callback) {
    console.log('Processing file');
    var currentTime = momenttz.tz(bookingTimeZone);
    selectStartConv = momenttz.tz(selectStart, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', bookingLocal, bookingTimeZone);
    var selectStartConvVerify = momenttz.tz(selectStart, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', bookingLocal, bookingTimeZone).isValid();
    selectEndConv = momenttz.tz(selectEnd, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', bookingLocal, bookingTimeZone);
    var selectEndConvVerify = momenttz.tz(selectEnd, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', bookingLocal, bookingTimeZone).isValid();

    if (selectStartConvVerify == true && selectEndConvVerify == true) {
            var startTim = momenttz.tz(file.bookingStartTime, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', file.local, file.timezone);
            var startTimVerify = momenttz.tz(file.bookingStartTime, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', file.local, file.timezone).isValid();
            var endTim = momenttz.tz(file.bookingEndTime, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', file.local, file.timezone);
            var endTimVerify = momenttz.tz(file.bookingEndTime, 'ddd DD-MMM-YYYY HH:mm:ss.SSS ZZ', file.local, file.timezone).isValid();


            if (isDateClashing == false) {
                if(startTimVerify == true && endTimVerify == true){
                    console.log('startTime: ',startTim.toString(), 'currentTime: ',currentTime.toString());
                    if(startTim.isAfter(currentTime)){
                        console.log('red mod');
                        console.log('red shoneville');
                        if (selectStartConv.isBefore(startTim)) {
                            console.log('A is earlier than B');
                            if (selectEndConv.isBefore(startTim)) {
                                console.log('dates dont clash', startTim);
                                isDateClashing = false;

                            }else {
                                console.log('Dates clash');
                                isDateClashing = true;

                            }
                        } else if (selectStartConv.isAfter(startTim) ) {
                            console.log('A is later than B');
                            if (selectStartConv.isAfter(endTim)) {
                                console.log('dates dont clash');
                                isDateClashing = false;
                            }else {
                                console.log('Dates clash');
                                isDateClashing = true;
                            }
                        } else if (selectStartConv.isSame(startTim)){
                            console.log('A is equal to B');
                            console.log('Dates clash');
                            isDateClashing = true;
                        } else {
                            console.log('problem lock');
                            isDateClashing = true;
                        }
                    }else {
                        console.log('why me');
                    }
                }
            }

        }

    callback();
}, function() {
    counter.push(1);

    if (counter.length == 1){
        console.log('money tress is a bitch');
        postDataBasedOnAction();
    }
});
});

}

function postDataBasedOnAction(){
async.series([
function(callback) {
    var user = firebase.auth().currentUser;
    if (isDateClashing === true){
        var refToPostDatall = firebase.database().ref('bookings').child(barberShopID);
        var refToBookingStartEndTimell = refToPostDatall.child(bookingID);

        refToBookingStartEndTimell.update({
            'severDidNotMakeBooking': 'YES'

        });

    }else {
        var refToPostData = firebase.database().ref('bookings').child(barberShopID);
        var refToBookingStartEndTime = refToPostData.child(bookingID);

        refToBookingStartEndTime.update({
            'bookingStartTime' : selectStart,
            'bookingEndTime': selectEnd,
            'severDidNotMakeBooking': 'NO'
        });
    }

    callback(null, 'posted');
},
function(callback) {
    var user = firebase.auth().currentUser;
    if (user) {
            user.delete().then(function() {
              firebase.auth().signOut().then(function() {
                }).catch(function(error) {
                  console.log('Sign out failed', error);
                });
            }).catch(function(error) {
            });
        }
    callback(null, 'signed out');
}

],

function(err, results) {
console.log(err);
if (err == null){
    console.log('there was no error');
    counter = [];
}

}); }

0 个答案:

没有答案