Skip to content

Bug in cancelTrip method from User datasource #116

@aruprakshit

Description

@aruprakshit

return !!this.store.trips.destroy({ where: { userId, launchId } });

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions