Skip to content

Add bulk stat import route#920

Merged
tudddorrr merged 1 commit intodevelopfrom
bulk-stat-import
Apr 8, 2026
Merged

Add bulk stat import route#920
tudddorrr merged 1 commit intodevelopfrom
bulk-stat-import

Conversation

@tudddorrr
Copy link
Copy Markdown
Collaborator

No description provided.

@tudddorrr tudddorrr added the enhancement New feature or request label Apr 7, 2026
@claude
Copy link
Copy Markdown

claude Bot commented Apr 7, 2026

PR Review: Add bulk stat import route

The refactor to extract createStatHandler is clean, and the test coverage is solid — permission checks, partial success, duplicate detection, error resilience, and the empty array guard are all there. A few things worth addressing:


🟡 No upper bound on the stats array

The schema accepts any non-empty array with no maximum size:

// bulk-create.ts
body: z.object({
  stats: z.array(createStatBodySchema(z)).nonempty(),
}),

Each stat is processed sequentially in a for loop, including two await em.flush() calls per item. A large payload (hundreds of stats) would block the request for a significant amount of time. Add a practical upper bound:

stats: z.array(createStatBodySchema(z)).nonempty().max(100),

🔵 stats response is not index-aligned with errors

The errors array is indexed 1:1 with the input, but stats only contains successes as a flat list. When some inputs fail, the client can't trivially map stats[n] back to the original input index without scanning errors for empty entries:

// Input:  [A, B, C]  where B fails
// Output: { stats: [statA, statC], errors: [[], ['B failed'], []] }
// stats[0] → input[0], stats[1] → input[2] — requires client-side reconstruction

An index-aligned format would be cleaner:

// stats: [statA, null, statC]
// errors: [[], ['B failed'], []]

Alternatively, since internalName is returned in each stat object, clients can match by that — but it should be documented as the intended correlation key if so.


🔵 Test helper uses Partial<GameStat> instead of a request-body type

// bulk-create.test.ts
function statPayload(overrides?: Partial<GameStat>) {

Partial<GameStat> allows entity-specific fields (id, createdAt, etc.) as overrides that have no meaning in a request body. Using a type scoped to the request shape (or just Record<string, unknown>) would prevent confusing test failures if someone passes an entity-only field expecting it to take effect.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.41%. Comparing base (6fa00a3) to head (e30e404).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #920   +/-   ##
========================================
  Coverage    97.40%   97.41%           
========================================
  Files          405      406    +1     
  Lines         6627     6641   +14     
  Branches       877      878    +1     
========================================
+ Hits          6455     6469   +14     
  Misses          88       88           
  Partials        84       84           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tudddorrr tudddorrr merged commit be27c79 into develop Apr 8, 2026
16 of 18 checks passed
@tudddorrr tudddorrr deleted the bulk-stat-import branch April 8, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant