can i override a method defined in node_modules file?












0















I am using sync Fusion’s React schedule to build a scheduler application using Meteor/React.



In my meteor application, in client/components folder, there lies a file ’schedule.js’.



It has the following piece of code :



function onEventRendered(args) {
categoryColor=args.data.Teacher;
console.log(args.data, );
if (!args.element || !categoryColor) {
return;
}
if (this.currentView === 'Agenda') {
(args.element.firstChild).style.borderLeftColor = categoryColor;
} else {
args.element.style.backgroundColor = categoryColor;
}
}


Whenever onEventRendered triggers, it automatically calls one of the methods that lie in node_modules/ej2-schedule/src/schedule/actions/crud.js



Crud.prototype.addEvent = function (eventData) {
var fields = this.parent.eventFields;
var promise = null;
var editParms = { addedRecords: , changedRecords: , deletedRecords: };
var args = {
cancel: false,
data: (eventData instanceof Array) ? eventData : [eventData],
requestType: 'eventCreate'
};
this.parent.trigger(events.actionBegin, args);
if (args.cancel) {
return;
}
if (eventData instanceof Array) {
for (var _i = 0, _a = eventData; _i < _a.length; _i++) {
var event_1 = _a[_i];
this.processCrudTimezone(event_1);
editParms.addedRecords.push(event_1);
}
promise =
this.parent.dataModule.dataManager.saveChanges(editParms, fields.id, this.getTable(), this.getQuery());
}
else {
this.processCrudTimezone(eventData);
promise = this.parent.dataModule.dataManager.insert(eventData, this.getTable(), this.getQuery());
}
var crudArgs = { requestType: 'eventCreated', cancel: false, data: eventData, promise: promise };
this.refreshData(crudArgs);
};


I want to just add a line to call a meteor method ‘event.add’ in this method, so that data can be saved in database. How can this be achieved?










share|improve this question























  • It wouldn't be a good idea, your node_modules package is a specific release of a project, which will sustain further changes and improvements over time, it's designed to expose an API for specific purposes and the above methods are designed to do their own work independently of your implementation. If you change node_modules it will get overwritten by any package rebuilding triggered by running an npm or yarn install/add/update.. etc. You don't want to tie your custom logic to the package by modifying it, instead write your logic in your React component lifecycle where it will fit best.

    – Dimitar Nikovski
    Nov 18 '18 at 11:48











  • @DimitarNikovski Do you have any idea about how can I extend 'Crud.prototype.addEvent = function (eventData)'

    – Pooja Chawla
    Nov 18 '18 at 13:54
















0















I am using sync Fusion’s React schedule to build a scheduler application using Meteor/React.



In my meteor application, in client/components folder, there lies a file ’schedule.js’.



It has the following piece of code :



function onEventRendered(args) {
categoryColor=args.data.Teacher;
console.log(args.data, );
if (!args.element || !categoryColor) {
return;
}
if (this.currentView === 'Agenda') {
(args.element.firstChild).style.borderLeftColor = categoryColor;
} else {
args.element.style.backgroundColor = categoryColor;
}
}


Whenever onEventRendered triggers, it automatically calls one of the methods that lie in node_modules/ej2-schedule/src/schedule/actions/crud.js



Crud.prototype.addEvent = function (eventData) {
var fields = this.parent.eventFields;
var promise = null;
var editParms = { addedRecords: , changedRecords: , deletedRecords: };
var args = {
cancel: false,
data: (eventData instanceof Array) ? eventData : [eventData],
requestType: 'eventCreate'
};
this.parent.trigger(events.actionBegin, args);
if (args.cancel) {
return;
}
if (eventData instanceof Array) {
for (var _i = 0, _a = eventData; _i < _a.length; _i++) {
var event_1 = _a[_i];
this.processCrudTimezone(event_1);
editParms.addedRecords.push(event_1);
}
promise =
this.parent.dataModule.dataManager.saveChanges(editParms, fields.id, this.getTable(), this.getQuery());
}
else {
this.processCrudTimezone(eventData);
promise = this.parent.dataModule.dataManager.insert(eventData, this.getTable(), this.getQuery());
}
var crudArgs = { requestType: 'eventCreated', cancel: false, data: eventData, promise: promise };
this.refreshData(crudArgs);
};


I want to just add a line to call a meteor method ‘event.add’ in this method, so that data can be saved in database. How can this be achieved?










share|improve this question























  • It wouldn't be a good idea, your node_modules package is a specific release of a project, which will sustain further changes and improvements over time, it's designed to expose an API for specific purposes and the above methods are designed to do their own work independently of your implementation. If you change node_modules it will get overwritten by any package rebuilding triggered by running an npm or yarn install/add/update.. etc. You don't want to tie your custom logic to the package by modifying it, instead write your logic in your React component lifecycle where it will fit best.

    – Dimitar Nikovski
    Nov 18 '18 at 11:48











  • @DimitarNikovski Do you have any idea about how can I extend 'Crud.prototype.addEvent = function (eventData)'

    – Pooja Chawla
    Nov 18 '18 at 13:54














0












0








0








I am using sync Fusion’s React schedule to build a scheduler application using Meteor/React.



In my meteor application, in client/components folder, there lies a file ’schedule.js’.



It has the following piece of code :



function onEventRendered(args) {
categoryColor=args.data.Teacher;
console.log(args.data, );
if (!args.element || !categoryColor) {
return;
}
if (this.currentView === 'Agenda') {
(args.element.firstChild).style.borderLeftColor = categoryColor;
} else {
args.element.style.backgroundColor = categoryColor;
}
}


Whenever onEventRendered triggers, it automatically calls one of the methods that lie in node_modules/ej2-schedule/src/schedule/actions/crud.js



Crud.prototype.addEvent = function (eventData) {
var fields = this.parent.eventFields;
var promise = null;
var editParms = { addedRecords: , changedRecords: , deletedRecords: };
var args = {
cancel: false,
data: (eventData instanceof Array) ? eventData : [eventData],
requestType: 'eventCreate'
};
this.parent.trigger(events.actionBegin, args);
if (args.cancel) {
return;
}
if (eventData instanceof Array) {
for (var _i = 0, _a = eventData; _i < _a.length; _i++) {
var event_1 = _a[_i];
this.processCrudTimezone(event_1);
editParms.addedRecords.push(event_1);
}
promise =
this.parent.dataModule.dataManager.saveChanges(editParms, fields.id, this.getTable(), this.getQuery());
}
else {
this.processCrudTimezone(eventData);
promise = this.parent.dataModule.dataManager.insert(eventData, this.getTable(), this.getQuery());
}
var crudArgs = { requestType: 'eventCreated', cancel: false, data: eventData, promise: promise };
this.refreshData(crudArgs);
};


I want to just add a line to call a meteor method ‘event.add’ in this method, so that data can be saved in database. How can this be achieved?










share|improve this question














I am using sync Fusion’s React schedule to build a scheduler application using Meteor/React.



In my meteor application, in client/components folder, there lies a file ’schedule.js’.



It has the following piece of code :



function onEventRendered(args) {
categoryColor=args.data.Teacher;
console.log(args.data, );
if (!args.element || !categoryColor) {
return;
}
if (this.currentView === 'Agenda') {
(args.element.firstChild).style.borderLeftColor = categoryColor;
} else {
args.element.style.backgroundColor = categoryColor;
}
}


Whenever onEventRendered triggers, it automatically calls one of the methods that lie in node_modules/ej2-schedule/src/schedule/actions/crud.js



Crud.prototype.addEvent = function (eventData) {
var fields = this.parent.eventFields;
var promise = null;
var editParms = { addedRecords: , changedRecords: , deletedRecords: };
var args = {
cancel: false,
data: (eventData instanceof Array) ? eventData : [eventData],
requestType: 'eventCreate'
};
this.parent.trigger(events.actionBegin, args);
if (args.cancel) {
return;
}
if (eventData instanceof Array) {
for (var _i = 0, _a = eventData; _i < _a.length; _i++) {
var event_1 = _a[_i];
this.processCrudTimezone(event_1);
editParms.addedRecords.push(event_1);
}
promise =
this.parent.dataModule.dataManager.saveChanges(editParms, fields.id, this.getTable(), this.getQuery());
}
else {
this.processCrudTimezone(eventData);
promise = this.parent.dataModule.dataManager.insert(eventData, this.getTable(), this.getQuery());
}
var crudArgs = { requestType: 'eventCreated', cancel: false, data: eventData, promise: promise };
this.refreshData(crudArgs);
};


I want to just add a line to call a meteor method ‘event.add’ in this method, so that data can be saved in database. How can this be achieved?







reactjs meteor node-modules syncfusion






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 11:37









Pooja ChawlaPooja Chawla

186




186













  • It wouldn't be a good idea, your node_modules package is a specific release of a project, which will sustain further changes and improvements over time, it's designed to expose an API for specific purposes and the above methods are designed to do their own work independently of your implementation. If you change node_modules it will get overwritten by any package rebuilding triggered by running an npm or yarn install/add/update.. etc. You don't want to tie your custom logic to the package by modifying it, instead write your logic in your React component lifecycle where it will fit best.

    – Dimitar Nikovski
    Nov 18 '18 at 11:48











  • @DimitarNikovski Do you have any idea about how can I extend 'Crud.prototype.addEvent = function (eventData)'

    – Pooja Chawla
    Nov 18 '18 at 13:54



















  • It wouldn't be a good idea, your node_modules package is a specific release of a project, which will sustain further changes and improvements over time, it's designed to expose an API for specific purposes and the above methods are designed to do their own work independently of your implementation. If you change node_modules it will get overwritten by any package rebuilding triggered by running an npm or yarn install/add/update.. etc. You don't want to tie your custom logic to the package by modifying it, instead write your logic in your React component lifecycle where it will fit best.

    – Dimitar Nikovski
    Nov 18 '18 at 11:48











  • @DimitarNikovski Do you have any idea about how can I extend 'Crud.prototype.addEvent = function (eventData)'

    – Pooja Chawla
    Nov 18 '18 at 13:54

















It wouldn't be a good idea, your node_modules package is a specific release of a project, which will sustain further changes and improvements over time, it's designed to expose an API for specific purposes and the above methods are designed to do their own work independently of your implementation. If you change node_modules it will get overwritten by any package rebuilding triggered by running an npm or yarn install/add/update.. etc. You don't want to tie your custom logic to the package by modifying it, instead write your logic in your React component lifecycle where it will fit best.

– Dimitar Nikovski
Nov 18 '18 at 11:48





It wouldn't be a good idea, your node_modules package is a specific release of a project, which will sustain further changes and improvements over time, it's designed to expose an API for specific purposes and the above methods are designed to do their own work independently of your implementation. If you change node_modules it will get overwritten by any package rebuilding triggered by running an npm or yarn install/add/update.. etc. You don't want to tie your custom logic to the package by modifying it, instead write your logic in your React component lifecycle where it will fit best.

– Dimitar Nikovski
Nov 18 '18 at 11:48













@DimitarNikovski Do you have any idea about how can I extend 'Crud.prototype.addEvent = function (eventData)'

– Pooja Chawla
Nov 18 '18 at 13:54





@DimitarNikovski Do you have any idea about how can I extend 'Crud.prototype.addEvent = function (eventData)'

– Pooja Chawla
Nov 18 '18 at 13:54












1 Answer
1






active

oldest

votes


















1














We can perform CRUD using MongoDB in our application level without modifying any source file in node_modules. We have prepared a sample for your reference which can be downloaded from the below location.
http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample1414642222



In the above sample, we have added CRUD actions code snippet in server.js.



app.post("/GetData", (req, res) => {  //executes on initial loading and for each CRUD actions
dbo.collection('ScheduleData').find({}).toArray((err, cus) => {
res.send(cus);
});
});
app.post("/BatchData", (req, res) => {
var eventData = ;
if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) { //this block will execute while adding events
(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() * 60000)));
eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
dbo.collection('ScheduleData').insertOne(eventData[i]); //to add the events in MongoDB collection
}
}
if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) { //this block will execute while editing events
(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)));
dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, eventData[i]); //to update the events in MongoDB collection
}
}
if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) { //this block will execute while deleting events
(req.body.action == "remove") ? eventData.push(req.body.value) : eventData = req.body.deleted;
for (var i = 0; i < eventData.length; i++) {
dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id }, eventData[i]); //to delete the events in MongoDB collection
}
}
res.send(req.body);
});


In the below code we have given the GetData and BatchData url path to initial fetching and for performing CRUD actions using UrlAdaptor and assigned it to the scheduler datasource.



let data = new DataManager({ url: 'http://localhost:5000/GetData', crudUrl: 'http://localhost:5000/BatchData', adaptor: new UrlAdaptor, crossDomain: true });



eventSettings={{ dataSource: data }}



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






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360427%2fcan-i-override-a-method-defined-in-node-modules-file%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    We can perform CRUD using MongoDB in our application level without modifying any source file in node_modules. We have prepared a sample for your reference which can be downloaded from the below location.
    http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample1414642222



    In the above sample, we have added CRUD actions code snippet in server.js.



    app.post("/GetData", (req, res) => {  //executes on initial loading and for each CRUD actions
    dbo.collection('ScheduleData').find({}).toArray((err, cus) => {
    res.send(cus);
    });
    });
    app.post("/BatchData", (req, res) => {
    var eventData = ;
    if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) { //this block will execute while adding events
    (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() * 60000)));
    eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
    dbo.collection('ScheduleData').insertOne(eventData[i]); //to add the events in MongoDB collection
    }
    }
    if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) { //this block will execute while editing events
    (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)));
    dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, eventData[i]); //to update the events in MongoDB collection
    }
    }
    if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) { //this block will execute while deleting events
    (req.body.action == "remove") ? eventData.push(req.body.value) : eventData = req.body.deleted;
    for (var i = 0; i < eventData.length; i++) {
    dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id }, eventData[i]); //to delete the events in MongoDB collection
    }
    }
    res.send(req.body);
    });


    In the below code we have given the GetData and BatchData url path to initial fetching and for performing CRUD actions using UrlAdaptor and assigned it to the scheduler datasource.



    let data = new DataManager({ url: 'http://localhost:5000/GetData', crudUrl: 'http://localhost:5000/BatchData', adaptor: new UrlAdaptor, crossDomain: true });



    eventSettings={{ dataSource: data }}



    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






    share|improve this answer




























      1














      We can perform CRUD using MongoDB in our application level without modifying any source file in node_modules. We have prepared a sample for your reference which can be downloaded from the below location.
      http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample1414642222



      In the above sample, we have added CRUD actions code snippet in server.js.



      app.post("/GetData", (req, res) => {  //executes on initial loading and for each CRUD actions
      dbo.collection('ScheduleData').find({}).toArray((err, cus) => {
      res.send(cus);
      });
      });
      app.post("/BatchData", (req, res) => {
      var eventData = ;
      if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) { //this block will execute while adding events
      (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() * 60000)));
      eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
      dbo.collection('ScheduleData').insertOne(eventData[i]); //to add the events in MongoDB collection
      }
      }
      if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) { //this block will execute while editing events
      (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)));
      dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, eventData[i]); //to update the events in MongoDB collection
      }
      }
      if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) { //this block will execute while deleting events
      (req.body.action == "remove") ? eventData.push(req.body.value) : eventData = req.body.deleted;
      for (var i = 0; i < eventData.length; i++) {
      dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id }, eventData[i]); //to delete the events in MongoDB collection
      }
      }
      res.send(req.body);
      });


      In the below code we have given the GetData and BatchData url path to initial fetching and for performing CRUD actions using UrlAdaptor and assigned it to the scheduler datasource.



      let data = new DataManager({ url: 'http://localhost:5000/GetData', crudUrl: 'http://localhost:5000/BatchData', adaptor: new UrlAdaptor, crossDomain: true });



      eventSettings={{ dataSource: data }}



      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






      share|improve this answer


























        1












        1








        1







        We can perform CRUD using MongoDB in our application level without modifying any source file in node_modules. We have prepared a sample for your reference which can be downloaded from the below location.
        http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample1414642222



        In the above sample, we have added CRUD actions code snippet in server.js.



        app.post("/GetData", (req, res) => {  //executes on initial loading and for each CRUD actions
        dbo.collection('ScheduleData').find({}).toArray((err, cus) => {
        res.send(cus);
        });
        });
        app.post("/BatchData", (req, res) => {
        var eventData = ;
        if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) { //this block will execute while adding events
        (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() * 60000)));
        eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
        dbo.collection('ScheduleData').insertOne(eventData[i]); //to add the events in MongoDB collection
        }
        }
        if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) { //this block will execute while editing events
        (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)));
        dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, eventData[i]); //to update the events in MongoDB collection
        }
        }
        if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) { //this block will execute while deleting events
        (req.body.action == "remove") ? eventData.push(req.body.value) : eventData = req.body.deleted;
        for (var i = 0; i < eventData.length; i++) {
        dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id }, eventData[i]); //to delete the events in MongoDB collection
        }
        }
        res.send(req.body);
        });


        In the below code we have given the GetData and BatchData url path to initial fetching and for performing CRUD actions using UrlAdaptor and assigned it to the scheduler datasource.



        let data = new DataManager({ url: 'http://localhost:5000/GetData', crudUrl: 'http://localhost:5000/BatchData', adaptor: new UrlAdaptor, crossDomain: true });



        eventSettings={{ dataSource: data }}



        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






        share|improve this answer













        We can perform CRUD using MongoDB in our application level without modifying any source file in node_modules. We have prepared a sample for your reference which can be downloaded from the below location.
        http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample1414642222



        In the above sample, we have added CRUD actions code snippet in server.js.



        app.post("/GetData", (req, res) => {  //executes on initial loading and for each CRUD actions
        dbo.collection('ScheduleData').find({}).toArray((err, cus) => {
        res.send(cus);
        });
        });
        app.post("/BatchData", (req, res) => {
        var eventData = ;
        if (req.body.action == "insert" || (req.body.action == "batch" && req.body.added.length > 0)) { //this block will execute while adding events
        (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() * 60000)));
        eventData[i].EndTime = (new Date(+edate - (edate.getTimezoneOffset() * 60000)));
        dbo.collection('ScheduleData').insertOne(eventData[i]); //to add the events in MongoDB collection
        }
        }
        if (req.body.action == "update" || (req.body.action == "batch" && req.body.changed.length > 0)) { //this block will execute while editing events
        (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)));
        dbo.collection('ScheduleData').updateOne({ "Id": eventData[i].Id }, eventData[i]); //to update the events in MongoDB collection
        }
        }
        if (req.body.action == "remove" || (req.body.action == "batch" && req.body.deleted.length > 0)) { //this block will execute while deleting events
        (req.body.action == "remove") ? eventData.push(req.body.value) : eventData = req.body.deleted;
        for (var i = 0; i < eventData.length; i++) {
        dbo.collection('ScheduleData').deleteOne({ "Id": eventData[i].Id }, eventData[i]); //to delete the events in MongoDB collection
        }
        }
        res.send(req.body);
        });


        In the below code we have given the GetData and BatchData url path to initial fetching and for performing CRUD actions using UrlAdaptor and assigned it to the scheduler datasource.



        let data = new DataManager({ url: 'http://localhost:5000/GetData', crudUrl: 'http://localhost:5000/BatchData', adaptor: new UrlAdaptor, crossDomain: true });



        eventSettings={{ dataSource: data }}



        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 '18 at 11:48









        KarthigeyanKarthigeyan

        412




        412






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53360427%2fcan-i-override-a-method-defined-in-node-modules-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word