I'm not sure how to get return value from the below code. I want to get the return value from authorizeAndListEventsNew method which was obtained from createEvent.
How should i get the return value promises within the promises, I tried using async and await along with promises but dosent work out.
function authorizeAndListEventsNew(createEvent,name,d,loc,mobile){
return fs.readFile("credentials.json",(err,content)=>{
if(err) return console.log('Error loading client secret file',err);
const {client_secret, client_id, javascript_origins} = credentials.web;
const oAuth2Client = new google.auth.OAuth2(
client_id, client_secret, javascript_origins);
return fs.readFile(TOKEN_PATH, (err, token) => {
if (err) return getAccessToken(oAuth2Client, callback);
oAuth2Client.setCredentials(JSON.parse(token));
callback(oAuth2Client,name,d,loc,mobile);
});
});
}
function createEvent(auth,pname,std,loc,desc){
const calendar = google.calendar({version: 'v3', auth});
listUpcommingEvents(calendar,std).then((res)=>{
var newDt=new Date(std);
if(res.length>0){
var sortEvts = res.sort((a,b)=> a - b);
var lastEle = sortEvts.slice(-1).pop();
newDt.setTime(lastEle.getTime());
} else {
newDt.setHours(09,0,0);
}
var endTime = new Date();
var d = new Date(newDt);
var endTime = moment(d).add(10,"m").toDate();
var event = {
'summary': pname,
'location': loc,
'description': desc,
'start': {
'dateTime': d.toISOString(),
'timeZone': 'xxx'
},
'end': {
'dateTime': endTime.toISOString(),
'timeZone': 'xxx'
},
};
calendar.events.insert({
auth: auth,
calendarId: CALENDAR_ID,
resource: event,
}, function(err, event) {
if (err) {
console.log('There was an error contacting the Calendar service: ' + err);
return true;
}
console.log('Event created: %s', event);
return false;
});
});
};