mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
refactor(server): plan 4 — narrow TripMembersRepository.remove/TripsRepository.setOwner to number
Both accepted trip_id: number | string per 3c's carry note (their "stays
loose for other callers" reasoning), pending the guard-level single parse
landing first. Re-checked every caller directly: setOwner's one production
caller (trip-members.service.ts#transferOwnership) already passes trip.id,
a real number resolved earlier in the same transaction; remove's callers
are trips.rpc.ts (num(), already a validated number), trips.mcp.ts (Zod-
typed tool input, already a number) and TripMembersController.removeMember
(the one genuine raw-string caller, :id off the route with no class-level
TripAccessGuard on this controller by design).
TripMembersController.removeMember now parses :id once (toRowId, not
Number() — rule 15's NaN-into-SQL trap) and threads the parsed number to
both its own access check and removeMember, instead of passing the raw
string through twice. TripMembersService.removeMember and both repository
methods narrow to number accordingly; setOwner's WHERE also moves off its
raw-bind escape hatch onto nativeUpdate now that trip_id is typed, and
remove's trip_id half moves onto a typed .where({ trip: trip_id }) filter
(user_id keeps its own raw bind — a different, still-live NaN-safety seam,
unrelated to this narrowing).
TRIPREPO-018 and TMEMREPO-023, which pinned the retired string-bind seam
on setOwner/remove, no longer typecheck against the narrowed signatures
and are removed with an explanatory comment in their place.
This commit is contained in:
@@ -306,14 +306,14 @@ describe('TripMembersRepository.addIgnoringConflict / remove (TM8/TM14/TM15, sec
|
||||
await expect(tripMembers.remove(trip.id, 999999)).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('TMEMREPO-023: remove binds a string trip id raw, the same seam rosterUserIds/listUserIdsByTrip document', async () => {
|
||||
const { user: owner } = createUser(testDb);
|
||||
const { user: member } = createUser(testDb);
|
||||
const trip = createTrip(testDb, owner.id);
|
||||
addTripMember(testDb, trip.id, member.id);
|
||||
await tripMembers.remove(String(trip.id), member.id);
|
||||
expect(testDb.prepare('SELECT id FROM trip_members WHERE trip_id = ? AND user_id = ?').get(trip.id, member.id)).toBeUndefined();
|
||||
});
|
||||
// TMEMREPO-023 used to pin remove's `number | string` raw-bind seam on
|
||||
// `trip_id` (`remove(String(trip.id), ...)`) — retired by Plan 4 Task 8a's
|
||||
// narrowing to `trip_id: number` (its own docstring covers why: its last
|
||||
// raw-string caller, TripMembersController.removeMember, now parses its
|
||||
// route param once itself). `String(trip.id)` no longer typechecks
|
||||
// against `remove`'s signature, so there is nothing left to pin here.
|
||||
// `user_id` keeps its own raw bind (TMEMREPO-024 below), a different,
|
||||
// still-live seam — see remove's own docstring.
|
||||
});
|
||||
|
||||
// Rule 15's exact trap, caught on a compiled boot (`DELETE /api/trips/:id/
|
||||
|
||||
@@ -193,13 +193,12 @@ describe('TripsRepository — TripMembersService / TripReadModelService (Plan 3c
|
||||
expect((testDb.prepare('SELECT user_id FROM trips WHERE id = ?').get(trip.id) as { user_id: number }).user_id).toBe(newOwner.id);
|
||||
});
|
||||
|
||||
it('TRIPREPO-018: setOwner binds a string trip id raw — the same seam its docstring documents', async () => {
|
||||
const { user: owner } = createUser(testDb);
|
||||
const { user: newOwner } = createUser(testDb);
|
||||
const trip = createTrip(testDb, owner.id);
|
||||
await trips.setOwner(String(trip.id), newOwner.id);
|
||||
expect((testDb.prepare('SELECT user_id FROM trips WHERE id = ?').get(trip.id) as { user_id: number }).user_id).toBe(newOwner.id);
|
||||
});
|
||||
// TRIPREPO-018 used to pin setOwner's `number | string` raw-bind seam
|
||||
// (`setOwner(String(trip.id), ...)`) — retired by Plan 4 Task 8a's
|
||||
// narrowing to `trip_id: number` (its own docstring covers why: its one
|
||||
// production caller already passes a real `trip.id` number, never the
|
||||
// route's raw string). `String(trip.id)` no longer typechecks against
|
||||
// `setOwner`'s signature, so there is nothing left to pin here.
|
||||
|
||||
describe('findRaw (TR-B, shared with TripsService.getRaw once Task 7 lands)', () => {
|
||||
it('TRIPREPO-019: every scalar column comes back, feed_token included (the JS strip is the caller\'s job)', async () => {
|
||||
|
||||
Reference in New Issue
Block a user