Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: api/*/update系の必須キーを最低限に #13824

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

yupix
Copy link
Contributor

@yupix yupix commented May 12, 2024

What

close #13398

上記の問題を解決します

Why

部分的な更新を行う際に元々の値を show などを用いて取得し、bodyに付けてから更新を行わないと予期せぬ上書きなどを起こしてしまい大変不便なため。

Additional info (optional)

webhookに関してなのですが、以下のようにsecret を nullableにして nullを空文字、undefinedは更新を見送るといった挙動にしたかったのですが、undefinedになった際以下のようなエラーが出てしまってよく分からなかったため見送ってます。何かご存じでしたらご教授いただければ幸いです。

				secret: ps.secret === null ? '' : ps.secret ? ps.secret : undefined,
  e: {
    message: 'Cannot perform update query because update values are not defined. Call "qb.set(...)" method to specify updated values.',
    code: 'UpdateValuesMissingError',
    stack: 'UpdateValuesMissingError: Cannot perform update query because update values are not defined. Call "qb.set(...)" method to specify updated values.\n' +
      '    at UpdateQueryBuilder.createUpdateExpression (/workspace/node_modules/.pnpm/typeorm@0.3.20_ioredis@5.4.1_pg@8.11.5/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:430:19)\n' +
      '    at UpdateQueryBuilder.getQuery (/workspace/node_modules/.pnpm/typeorm@0.3.20_ioredis@5.4.1_pg@8.11.5/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:34:21)\n' +
      '    at UpdateQueryBuilder.getQueryAndParameters (/workspace/node_modules/.pnpm/typeorm@0.3.20_ioredis@5.4.1_pg@8.11.5/node_modules/typeorm/query-builder/QueryBuilder.js:262:28)\n' +
      '    at UpdateQueryBuilder.execute (/workspace/node_modules/.pnpm/typeorm@0.3.20_ioredis@5.4.1_pg@8.11.5/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:81:50)\n' +
      '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
      '    at async file:///workspace/packages/backend/built/server/api/endpoints/i/webhooks/update.js:87:13\n' +
      '    at async ApiCallService.call (file:///workspace/packages/backend/built/server/api/ApiCallService.js:317:16)',
    id: 'b087f1df-5d27-4571-92c2-c1c8be21893f'
  }
}

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@github-actions github-actions bot added packages/backend Server side specific issue/PR packages/misskey-js labels May 12, 2024
Copy link

codecov bot commented May 12, 2024

Codecov Report

Attention: Patch coverage is 23.33333% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 66.49%. Comparing base (acf84a2) to head (ed2326c).

Files Patch % Lines
...d/src/server/api/endpoints/gallery/posts/update.ts 6.66% 14 Missing ⚠️
...s/backend/src/server/api/endpoints/pages/update.ts 14.28% 6 Missing ⚠️
...ackend/src/server/api/endpoints/admin/ad/update.ts 33.33% 2 Missing ⚠️
...kend/src/server/api/endpoints/i/webhooks/update.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #13824      +/-   ##
===========================================
+ Coverage    65.15%   66.49%   +1.34%     
===========================================
  Files          985      988       +3     
  Lines       112139   116659    +4520     
  Branches      4457     5802    +1345     
===========================================
+ Hits         73059    77573    +4514     
- Misses       39049    39055       +6     
  Partials        31       31              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented May 12, 2024

このPRによるapi.jsonの差分

差分はこちら
--- base
+++ head
@@ -2077,16 +2077,7 @@
                   }
                 },
                 "required": [
-                  "id",
-                  "memo",
-                  "url",
-                  "imageUrl",
-                  "place",
-                  "priority",
-                  "ratio",
-                  "expiresAt",
-                  "startsAt",
-                  "dayOfWeek"
+                  "id"
                 ]
               }
             }
@@ -14159,20 +14150,7 @@
                   }
                 },
                 "required": [
-                  "roleId",
-                  "name",
-                  "description",
-                  "color",
-                  "iconUrl",
-                  "target",
-                  "condFormula",
-                  "isPublic",
-                  "isModerator",
-                  "isAdministrator",
-                  "asBadge",
-                  "canEditMembersByModerator",
-                  "displayOrder",
-                  "policies"
+                  "roleId"
                 ]
               }
             }
@@ -27734,8 +27712,7 @@
                   }
                 },
                 "required": [
-                  "clipId",
-                  "name"
+                  "clipId"
                 ]
               }
             }
@@ -36884,9 +36861,7 @@
                   }
                 },
                 "required": [
-                  "postId",
-                  "title",
-                  "fileIds"
+                  "postId"
                 ]
               }
             }
@@ -49550,9 +49525,11 @@
                     "maxLength": 1024
                   },
                   "secret": {
-                    "type": "string",
-                    "maxLength": 1024,
-                    "default": ""
+                    "type": [
+                      "string",
+                      "null"
+                    ],
+                    "maxLength": 1024
                   },
                   "on": {
                     "type": "array",
@@ -49575,11 +49552,7 @@
                   }
                 },
                 "required": [
-                  "webhookId",
-                  "name",
-                  "url",
-                  "on",
-                  "active"
+                  "webhookId"
                 ]
               }
             }
@@ -60671,12 +60644,7 @@
                   }
                 },
                 "required": [
-                  "pageId",
-                  "title",
-                  "name",
-                  "content",
-                  "variables",
-                  "script"
+                  "pageId"
                 ]
               }
             }

Get diff files from Workflow Page

@yupix yupix marked this pull request as draft May 12, 2024 08:44
@syuilo
Copy link
Member

syuilo commented May 12, 2024

undefinedになった際以下のようなエラーが出てしまってよく分からなかったため見送ってます。何かご存じでしたらご教授いただければ幸いです。

{
  ...(ps.secret === null ? { secret: '' } : ps.secret ? { secret: ps.secret } : {})
}

のように書かないとダメそう

@yupix
Copy link
Contributor Author

yupix commented May 12, 2024

undefinedになった際以下のようなエラーが出てしまってよく分からなかったため見送ってます。何かご存じでしたらご教授いただければ幸いです。

{
  ...(ps.secret === null ? { secret: '' } : ps.secret ? { secret: ps.secret } : {})
}

のように書かないとダメそう

実際に以下のように変えてみましたが、同様のエラーが発生するみたいです...

await this.webhooksRepository.update(webhook.id, {
	name: ps.name,
	url: ps.url,
	on: ps.on,
	active: ps.active,
	...(ps.secret === null ? { secret: '' } : ps.secret ? { secret: ps.secret } : {}),
});

@syuilo
Copy link
Member

syuilo commented May 12, 2024

🤯

@yupix
Copy link
Contributor Author

yupix commented May 12, 2024

お恥ずかしながらid以外に適当なキーを付与したら動きました。お騒がせしてすみません。
webhook以外にもadをやってなかったことに気づいたのでそれだけやったらdraft解除します。

@yupix yupix marked this pull request as ready for review May 12, 2024 09:52
@yupix
Copy link
Contributor Author

yupix commented May 12, 2024

できました

@yupix yupix force-pushed the refactor/improved-update-convenience branch 2 times, most recently from f8e50f1 to f861c0b Compare May 20, 2024 05:14
@yupix yupix force-pushed the refactor/improved-update-convenience branch from f861c0b to ed2326c Compare May 20, 2024 05:16
@yupix yupix changed the title refactor: improved update convenience refactor: api/*/update系の必須キーを最低限に May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages/backend Server side specific issue/PR packages/misskey-js
Projects
None yet
Development

Successfully merging this pull request may close these issues.

APIにPOSTする際に要求される冗長な必須項目を減らして欲しい
2 participants