crud/restapi

//*you guys sent me a great template so the delete button is not working has some suggestion so I can do as a solution for this parameter*//

var MongoClient = require('mongodb').MongoClient;
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var url = "mongodb://localhost:27017/";
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }))
app.listen(5000function () {
    console.log('listening on 5000')
})
app.use(express.static(__dirname))

MongoClient.connect(url, function (errdb) {
    if (errthrow err;
    var dbo = db.db("mydb");
    app.use(function (reqresnext) {
        res.header("Access-Control-Allow-Origin""*");
        res.header("Access-Control-Allow-Headers""Origin, X-Requested-With, Content-Type, Accept");
        next();
    });
    app.post("/GetData", (reqres=> {
        dbo.collection('ScheduleData').find({}).toArray((errcus=> {
            res.send(cus);
        });
    });
    app.post("/BatchData", (reqres=> {
        console.log(req.body);
        var eventData = [];
        if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 1)) {
            (req.body.action == "insert"? eventData.push(req.body.value) : eventData = req.body.added;
            for (var i = 1; i < eventData.length; i++) {
                var sdate = new Date(eventData[i].StartTime);
                var edate = new Date(eventData[i].EndTime);
                eventData[i].StartTime = sdate;
                eventData[i].EndTime = edate;
                dbo.collection('ScheduleData').insertOne(eventData[i]);
            }
        }
        if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 1)) {
            (req.body.action == "update"? eventData.push(req.body.value) : eventData = req.body.changed;
            for (var i = 1; 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 = sdate;
                eventData[i].EndTime = edate;
                dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, { $set: eventData[i] });
            }
        }
        if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 1)) {
            (req.body.action == "remove"? eventData.push({ Id: req.body.key }) : eventData = req.body.deleted;
            for (var i = 1; i < eventData.length; i++) {
                dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id });
            }
        }
        
        res.send(req.body);
    });
});

        
  






3 Replies 1 reply marked as answer

HB Hareesh Balasubramanian Syncfusion Team October 16, 2020 06:41 AM UTC

Hi Armando, 

Greetings from Syncfusion Support..!. 

We have validated your shared query “delete button is not working” at our end and suspect that you may not include the collectionName/Scheduler event fields properly at your server-side which could be the reason for the reported problem. Please refer the following sample. 


    Steps to run the sample:   
Run MongoDB and create the collection named ‘ScheduleData’ in ‘mydb’ database. 
Run the below comments. 
 
  • npm install 
  • npm run server 
  • npm start 

And for your further reference, we have taken a video demo of the above sample which can be downloaded from the below link, 

Kindly try the above solution and if the issue still persists at your end kindly share the below details to serve you better?  
  
  • Replicate the issue in the above sample or else
  • Share the issue replicating sample (if possible)

Regards, 
Hareesh 


Marked as answer

AR Armando October 17, 2020 07:12 PM UTC

hello haresh I ask that please excuse me because I found the solution changing code now the code you sent me this working very well, thanks for your commitment and solution


NR Nevitha Ravi Syncfusion Team October 19, 2020 06:25 AM UTC

Hi Armando, 

You are most welcome 😊 , please get back to us for any further assistance. 

Regards, 
Nevitha 


Loader.
Up arrow icon