How to get the response of the updateTimeTable API

I have written a backend api which inserts the schedule value into the mongodB


router.post("/updatetimetabledata", (req, res) => {
let otherdetailsarray = [];
otherdetailsarray = req.body.OtherDetails.split(" ")

var eventData = [];
let duplicateFlag = false;
dbo.collection('ScheduleData').find({'User':req.body.user}).toArray((err, cus) => {
cus.forEach(cusss => {
req.body.added.forEach(element => {
const starttimeelement = new Date(element.StartTime);
const starttimecus = new Date(cusss.StartTime);
const endtimeelement = new Date(element.EndTime);
const endtimecus = new Date(cusss.EndTime);
if(element.TeacherName == cusss.TeacherName && (starttimeelement.getTime() + 330) === starttimecus.getTime() && (endtimeelement.getTime() +330) === endtimecus.getTime()){
duplicateFlag = true;
console.log('Duplicate schedule');
}
});
})
if(err) {
return next(err);
}
if(!duplicateFlag){
if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) {
(req.body.action == "insert") ? eventData.push(req.body.value) : eventData = req.body.added;
for (var i = 0; i < eventData.length; i++) {
var sdate = new Date(eventData[i].StartTime);
var edate = new Date(eventData[i].EndTime);
eventData[i].StartTime = (new Date(+sdate - (sdate.getTimezoneOffset() * 1)));
console.log('Event[i]',eventData[i])
eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 1)));
eventData[i].OtherDetails = req.body.OtherDetails;
eventData[i].User = req.body.user;
console.log('Duplciate Flaggg',duplicateFlag);
dbo.collection('ScheduleData').insertOne(eventData[i]);
}
res.send(req.body);
}
if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) {
(req.body.action == "update") ? eventData.push(req.body.value) : eventData = req.body.changed;
for (var i = 0; i < eventData.length; i++) {
delete eventData[i]._id;
var sdate = new Date(eventData[i].StartTime);
var edate = new Date(eventData[i].EndTime);
eventData[i].StartTime = (new Date(+sdate - (sdate.getTimezoneOffset() * 60000)));
eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
eventData[i].OtherDetails = req.body.OtherDetails;
dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, { $set: eventData[i] });
}
res.send(req.body);
}
if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) {
(req.body.action == "remove") ? eventData.push({ Id: req.body.key }) : eventData = req.body.deleted;
for (var i = 0; i < eventData.length; i++) {
dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id });
}
res.send(req.body);
}
} else {
res.send({errorMessage:"Duplicate Schedule for the teacher"});
}
})

 I have linked this api in the angular using the dataManager 

 private dataManager: DataManager = new DataManager({ url: 'http://localhost:4000/timetable/gettimetabledata',  crudUrl: 'http://localhost:4000/timetable/updatetimetabledata', // tslint:disable-next-line:new-parens  adaptor: new UrlAdaptor, crossDomain: true, }) 


 Here I need to get the api response of the updateTimeTable API....how can I get that??


3 Replies

VD Vinitha Devi Murugan Syncfusion Team July 12, 2021 11:38 AM UTC

Hi Aadhitya, 
 
Greetings from Syncfusion Support. 
 
We can get the api response of the updateTimeTable API by making use of dataBinding event of our Scheduler and same can be available below link. 
 
 
 
 (dataBinding)='onDataBinding($event)' 
 
 onDataBinding(args) { 
    // Here we can get the API response 
    console.log(args.result); 
  } 
 
Also, we suggest you to refer the quick start project that available in the below link helps you to create the Syncfusion Angular Scheduler with Mongo DB.  
Kindly try with the above sample and get back to us if you need any further assistance 
 
Regards, 
Vinitha 



AA Aadhitya July 12, 2021 06:39 PM UTC

Thanks mam...Your solution really helped me to solve the problem



NR Nevitha Ravi Syncfusion Team July 13, 2021 05:04 AM UTC

Hi Aadhitya, 

You are most welcome..! We are glad that our provided solution helped you, please let us know for further assistance. 

Regards, 
Nevitha 


Loader.
Up arrow icon