fix(audit): accept string | string[] in targetIdFromRequest - #1
Merged
Conversation
Express's Request.params values are typed as string | string[], which caused TS2345 errors in ~20 controller call sites (including AdminSandboxController) that pass req.params.* to the @Audit decorator. Root-cause fix: widen AuditContext.targetIdFromRequest return type to accept string[], and coerce the value in AuditInterceptor.resolveTargetId by taking the first element when an array is returned.
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.
Problem
AdminSandboxController.recoverSandbox(and ~20 other controller methods across the codebase) had a TypeScript error:This occurred at every
@Audit({ targetIdFromRequest: (req) => req.params.* })call site.Root Cause
Express's
Request.paramsvalues are typed asstring | string[], butAuditContext.targetIdFromRequestonly acceptedstring | null | undefined. This mismatch caused type errors everywhere the audit decorator accessed route params.Fix
2 files changed, 2 lines each:
audit/decorators/audit.decorator.ts— WidenedAuditContext.targetIdFromRequestreturn type tostring | string[] | null | undefinedaudit/interceptors/audit.interceptor.ts— InresolveTargetId, coerce the value:Array.isArray(targetId) ? targetId[0] : targetIdThis fixes all affected controllers at once rather than patching each call site individually.
Validation
sandbox.controller.ts(admin + non-admin) and all other previously-affected controllersnx build apishows 0 errors related to the audit decorator (remaining errors inmetrics.interceptor.tsare pre-existing and unrelated)