Created
March 15, 2018 19:31
-
-
Save luizhenriquesoares/d78c05a17a7783525b12af1c2c07d9df to your computer and use it in GitHub Desktop.
range date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.dateRange = async (req, res) => { | |
const month = moment(req.departureDate, "YYYY-MM-DD"); | |
var count = 0; | |
const nextMonth = month.range("month"); | |
const nextMonthFormated = Moment(nextMonth.end).format("YYYY-MM-DD"); | |
const range = moment.range(req.departureDate, nextMonthFormated); | |
const existDateArray = []; | |
for (let month of range.by("day")) { | |
req.departureDate = month.format("YYYY-MM-DD"); | |
const data = await getDates(req, res); | |
this.data = data; | |
existDateArray.push(existDate(data, req)); | |
console.log(month); | |
console.log("================================"); | |
console.log(req.originAirportCode); | |
console.log(req.destinationAirportCode); | |
console.log("================================"); | |
console.log("await"); | |
if (existDateArray[count].hasDate == "YES") { | |
const bot = createNewBot(dataTelegram.token); | |
const dataJSON = JSON.stringify(existDateArray[count]); | |
bot.sendMessage(dataTelegram.liveloGroup, dataJSON); | |
} | |
count++; | |
} | |
return existDateArray; | |
}; | |
const existDate = (data, req) => { | |
const airline = []; | |
if (data.requestedFlightSegmentList[0] != "undefined") { | |
const existDate = data.requestedFlightSegmentList[0].flightList.length; | |
if (existDate > 0) { | |
for (var i = 0; i < existDate; i++) { | |
airline.push({ | |
airline: data.requestedFlightSegmentList[0].flightList[i].airline.name | |
}); | |
} | |
} | |
} | |
if (airline.map(el => el.airline).indexOf(req.airline) !== -1) { | |
return { | |
from: req.originAirportCode, | |
to: req.destinationAirportCode, | |
hasDate: "YES", | |
date: data.departureDate | |
}; | |
} else { | |
return { | |
from: req.originAirportCode, | |
to: req.destinationAirportCode, | |
hasDate: "NO", | |
date: data.departureDate | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment