DB_ORG_FIND.byNanoId previously used a boolean-generic signature byNanoId<S extends boolean>(nanoId, includeProjects?, tx?) whose return type was a conditional S extends true ? OrgWithProjects : Org. The implementation passed includeProjects straight into include: { projects: includeProjects } and then forced the result with an as unknown as S extends true ? ... double cast — a structural lie that bypassed Prisma's own return typing.
This PR splits that one method into two non-generic methods in apps/apollo/src/lib/org/dbUtils/findOrg.ts:
byNanoId(nanoId, tx?) -> Result<Org, ...> — findUnique with no include; returns the base Org payload with no cast.byNanoIdWithProjects(nanoId, tx?) -> Result<OrgWithProjects, ...> — findUnique with include: { projects: true }; returns OrgWithProjects with no cast.Both methods now follow the same pattern as the sibling byUUID / byNanoIdWithOrgStripeMapping methods, and the as unknown as cast is gone entirely because Prisma infers each return type correctly.
Call-site migration (all 12 non-test DB_ORG_FIND.byNanoId callers re-verified against the merge base):
true was apps/apollo/src/pages/api/v3/org/payments/incoming_webhook.ts (~161). It was downgraded to byNanoId(orgId) because assignPlanToClient only reads org.nanoId and org.plan (both base Org scalars) and never touches org.projects, so fetching projects was wasted work.false / undefined were updated to drop the positional flag: joinOrgWInviteCode.ts, createProject.ts ((orgNanoId, false, tx) -> (orgNanoId, tx)), userOrgMapping/dbUtils/create.ts and metering/dbUtils/upsertOrgMeteringLimit.ts ((id, undefined/false, tx) -> (id, tx)).byNanoId(nanoId) with a single argument and were unchanged.upsertOrgMeteringLimit.test.ts had its toHaveBeenCalledWith assertion updated to drop the removed boolean arg.A new unit test file apps/apollo/src/lib/org/dbUtils/findOrg.unit.test.ts covers both methods: Ok/NotFound/InternalServerError paths, tx-client pass-through, and an assertion that byNanoId issues no include clause while byNanoIdWithProjects includes projects: true.
node_modules is not installed in the review worktree, so local typecheck/tests were not run; relying on CI check-types and run-vitest-tests.DB_ORG_FIND.byNanoId caller at the merge base: confirmed exactly one true caller (incoming_webhook.ts) and verified that handler reads only base Org fields (nanoId, plan), so the projects fetch was safe to drop.Org = Prisma.OrgGetPayload<{}> and OrgWithProjects = Prisma.OrgGetPayload<{ include: { projects: true } }> in dbUtils/types.ts, so both split methods return the correct payload with no cast.findOrg.unit.test.ts against the implementation; the prisma/wrapPrisma mock matches how the code consumes them and the file is picked up by the apollo vitest glob.🤖 Generated with Claude Code