apollographql / apollographql/fullstack-tutorial

Bug in cancelTrip method from User datasource

オープン
#116 コメント 0 件 リアクション 0 件 担当者 1 名 @stemmlerjs が担当を希望しています GitHub で見る
bug
主要言語
TypeScript
スター
1.2k
フォーク
808
PR マージ指標
30日以内にマージされた PR はありません

説明

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

Due to this line `cancelTrip` throws an error.

```sh
{
"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`](https://sequelize.org/master/class/lib/model.js~Model.html#static-method-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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。