[Solved]Unknown error of Meteor.call

Hi Experts, i found unexpected error after i clicked update event button as displayed on the picture below

.

Just a couple days ago, before today ( today i added command → meteor add http), this event was worked normally.

Just after i added the aforementioned command, i found typeerror : cannot read property ‘call’ of undefined

i modified the original code, and added line code Meteor.call(‘editEvent’,update) that executing

Meteor.methods({
  // Allows an event to be edited.
  editEvent( event ) {
    try {
      console.log(event);
      return EventData.update( event._id, {
        $set: event
      });
    } catch ( exception ) {
      throw new Meteor.Error( '500', `${ exception }` );
    }
  },
});

Thank you for your help.

Can you post the code for the file where Meteor.call is actually called? (Including import statements)

Here it is @coagmano

import { EventData, EventDataSchema } from ‘…/…/api/eventdata/eventdata’;
import { SimpleSchema } from ‘meteor/aldeed:simple-schema’;

Meteor.methods({
  // Allows an event to be edited.
  editEvent( event ) {
    try {
      console.log(event);
      return EventData.update( event._id, {
        $set: event
      });
    } catch ( exception ) {
      throw new Meteor.Error( '500', `${ exception }` );
    }
  },
});

import { Tracker } from ‘meteor/tracker’;
import { EventData } from ‘…/…/api/eventdata/eventdata’;

// Define a function that checks whether a moment has already passed.
let isPast = (date) => {
let today = moment().format();
return moment(today).isAfter(date);
};

Template.Calendar_Page.onCreated(() => {
Template.instance().subscribe(‘EventData’);
});

Template.Calendar_Page.helpers({
greeting: function() {
return Session.get(‘usernameaut’);
}
})
Template.Calendar_Page.onRendered(() => {

// Initialize the calendar.
$(’#event-calendar’).fullCalendar({
// Define the navigation buttons.
header: {
left: ‘title’,
center: ‘’,
right: ‘today prev,next’
},
// Add events to the calendar.
events(start, end, timezone, callback) {
let data = EventData.find().fetch().map((session) => {

    // Don't allow already past study events to be editable.
    session.editable = !isPast(session.start);
    return session;     
  });

  if (data) {
    callback(data);
  }
},

// Configure the information displayed for an "event."
eventRender(session, element) {
  element.find('.fc-content').html(
      `<h4 class="title">${session.title}</h4>
      <p class="time">${session.startString}</p>
      <p class="time">${session.endString}</p>
      <p class="time">${session.pic}</p>
    `
  );
},

// Triggered when a day is clicked on.
dayClick(date, session) {
  // Store the date so it can be used when adding an event to the EventData collection.
  Session.set('eventModal', { type: 'add', date: date.format() });
  // If the date has not already passed, show the create event modal.
  if(moment(date.format()).isSameOrAfter(moment(), 'day')) {
    var countdata = EventData.find({start:date.format()}).count();
    console.log(countdata);

    $('#create-event-modal').modal({ blurring: true }).modal('show');
  }
},

    // Delete an event if it is clicked on.
eventClick(event) {
  var picUpdate = EventData.find({}, { _id :event._id}).fetch()[0].pic;
  console.log(picUpdate);
 
 
  if (event.pic==picUpdate ){
    if (moment(event.start.format()).isSameOrAfter(moment(), 'day')){
      Session.set("dateupdate",event.start.format());
      Session.set("updateId",event._id);
      Session.set("pic",event.pic);
      $('#create-event-modal input[name="title"]').val(event.title);
      $("#create-event-modal div.text:first").val(event.startString);
      $("#create-event-modal div.text:first").text(event.startString);
      $("#create-event-modal div.text:last").val(event.endString);
      $("#create-event-modal div.text:last").text(event.endString);
      $('#create-event-modal input[name="pic"]').val(event.pic);
      $('#create-event-modal .ui.dividing.header').html('Update an event');
      $('#create-event-modal button.ui.teal.button').html("Update Event");
      $('#create-event-modal').modal({ blurring: true }).modal('show');
    }
    else
    {
      alert("Can not update, this is a past event");
      return;
   
    }
  }
  else
  {
   
      alert("Can not update, this schedule is belongs to "+event.pic);
   
    
    return;
  }
  //EventData.remove({ _id: event._id });
},

// Allow events to be dragged and dropped.
eventDrop(session, delta, revert) {
  var picUpdate = EventData.find({}, { _id : session._id}).fetch()[0].pic;

  if (session.pic ==picUpdate)
  {
    let date = session.start.format();

    if (!isPast(date)) {
      let update = {
        _id: session._id,
        start: date,
        end: date
      };

      // Update the date of the event.

Meteor.call('editEvent', update);
} else {
revert();
}
}
else
{
alert(“You can not change the schedule which is not belong to you”);
revert();
}
},
});

// Updates the calendar if there are changes.
Tracker.autorun(() => {
EventData.find().fetch();
$(’#event-calendar’).fullCalendar(‘refetchEvents’);
});
});

Where is that alertbox called from, the one in your screenshot?

it came from Meteor.call(‘editEvent’,update) which executed these line

Meteor.methods({
  // Allows an event to be edited.
  editEvent( event ) {
    try {
      console.log(event);
      return EventData.update( event._id, {
        $set: event
      });
    } catch ( exception ) {
      throw new Meteor.Error( '500', `${ exception }` );
    }
  },
});

That happens on the server, but where is the actual ‘alert()’ call that displays the alert? How do you know the error came from that method?

It would also be nice if you formatted all of your code in your earlier post, it is very hard to read now.

What is this last update argument? I dont see it defined anywhere

i just got a message “Cannot read property ‘call’ of undefined”

The alert showed cannot read property call of undefined in Meteor.call

Meteor was undefined, why it can be? i was using import { Meteor } from ‘meteor/mongo’;

That should be import { Meteor } from 'meteor/meteor';

Yes, it is working. Can you explain why it is incorrect? because i remember that i have not changed that line before and the apps worked normally.

import { Meteor } from 'meteor/mongo'; would never have worked. However, if you previously did not have an import { Meteor } statement at all, that would have worked because of Meteor’s backwards compatibility.

Maybe try looking back through your commit history to see where the error crept in?

1 Like

Thank you @robfallows, @coagmano, @jorgeer

1 Like

Note that is is exactly why I specifically asked for code including import statements.
If you had included the incorrect import statement in the code you posted, we could have spotted it straight away.

There were some import statements, but the key one was missing. Which misled me to think that you had included all the imports and so we spent extra time poring over the code snippet, trying to understand the content, structure, and intent as well as looking for errors.

We’re happy to help you, but I would appreciate if you help us help you as well

2 Likes

Dear @coagmano, noted Sir. I am sorry for my recklessness.

1 Like