fullstack-tutorial icon indicating copy to clipboard operation
fullstack-tutorial copied to clipboard

Bug in cancelTrip method from User datasource

Open aruprakshit opened this issue 6 years ago • 0 comments

https://github.com/apollographql/fullstack-tutorial/blob/66431a74abbdfd432157ec36a2fb7cd9f0b80be4/start/server/src/datasources/user.js#L60

Due to this line cancelTrip throws an error.

{
  "errors": [
    {
      "message": "Cannot read property 'flight_number' of undefined",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "cancelTrip"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: Cannot read property 'flight_number' of undefined",
      // ....

Following change will fix the error.

async cancelTrip({ launchId }) {
    const userId = this.context.user.id;
    const numberOfDeletedTrips = await this.store.trips.destroy({ where: { userId, launchId } });
    return numberOfDeletedTrips !== 0;
  }

As per the doc of destroy it returns number of deleted resources wrapped in Promise. So it should be resolved to get the count to decide if resources are deleted or not.

aruprakshit avatar Jan 10 '20 13:01 aruprakshit