fix(admin): patchDriverStatus 正規化回傳值(型別原本在說謊) - #28
Merged
Conversation
admin REST 形狀對帳(2026-07-28,真後端逐端點抓回應)發現: PATCH /admin/drivers/:id/status 回的是**混合大小寫**—— ID/Name/Status 走 Go 欄位名,vehicle_type/plate_number/vehicle_review_status 走 json tag,而且**不含** rating_avg/rating_count。 前端卻宣告它回 `Driver`(全 PascalCase)且不正規化:車輛三欄與評價都會是 undefined。 目前呼叫端只 invalidateQueries、不看回傳值所以 runtime 沒出事—— 但型別在說謊,哪天有人拿它去 setQueryData,那一列的車種車牌就會憑空消失。 這正是今天修的那幾個 bug 的前身形狀(東西在、只是那條路徑沒人走過)。 修法:改回 Record<string, unknown> 並走 normalizeDriver,讓宣告的型別成真。 測試強化:mock 換成從真後端抓下來的混合大小寫形狀(舊 mock 只有 PascalCase, 所以測不出來),斷言車輛三欄與 RatingAvg/RatingCount 補 0 而非 undefined。 反向驗證:改回不正規化 → 該案 FAIL。 驗收:npm test 134 passed、lint 乾淨、tsc --noEmit 通過。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
怎麼找到的
admin REST 形狀對帳:起真後端,逐端點抓實際回應比對前端的型別與 normalizer。
結論是 admin 的契約基本乾淨(詳見下方),只揪出這一個型別謊言。
問題
PATCH /admin/drivers/:id/status實際回:{"driver":{"ID":1,"LineUserID":"...","Name":"...","Phone":"","Status":3, "vehicle_type":"sedan","plate_number":"LI-3748", "vehicle_review_status":"approved","vehicle_review_note":"", "CreatedAt":"...","UpdatedAt":"..."}}混合大小寫(
ID/Name/Status走 Go 欄位名,車輛欄位走 json tag),而且不含rating_avg/rating_count。前端卻宣告它回
Driver(全 PascalCase)且不正規化——VehicleType/PlateNumber/VehicleReviewStatus/RatingAvg/RatingCount全是undefined。目前 runtime 沒出事:兩個 mutation 都丟掉回傳值只做
invalidateQueries,重抓那條有normalizeDriver。但型別在說謊——哪天有人拿它去setQueryData做樂觀更新,那一列的車種車牌就會憑空消失,而且不會有任何錯誤。這正是今天修的那幾個 bug 的前身形狀。修法
改吃
Record<string, unknown>並走normalizeDriver,讓宣告的型別成真(reviewDriverVehicle本來就是這樣做的,兩支現在一致)。測試
mock 換成從真後端抓下來的混合大小寫形狀——舊 mock 只有 PascalCase,所以這個問題測不出來。斷言車輛三欄正確、
RatingAvg/RatingCount補 0 而非 undefined(表格排序吃 undefined 會壞)。反向驗證:改回不正規化 → 該案 FAIL。
驗收:
npm test134 passed、npm run lint乾淨、tsc --noEmit通過。這輪 admin REST 對帳驗過乾淨的部分
/admin/rides列表 8 個鍵 vsRideRowstatus=9→0、不存在關鍵字→0、未來日期→0)totallimit=1時仍回全量 2,antd 分頁不會壞/admin/rides/:id頂層events/ride/track_geojson/stops/ratingfetchRideDetail的解析一致;rating造一筆評分過的訂單驗到 score/comment/created_atDailyReportRow/MonthlyReportRow完全一致/admin/lost-items13 個鍵LostItem完全一致(含 customer_name/driver_name)MembershipInvoice一致;period鍵名正確/admin/drivers列表normalizeDriver兩種都吃🤖 Generated with Claude Code