fix(plan): correct admin role check (roleName not role) + drop stale category casts
isAdminLike read authData.role, which doesn't exist on AuthData (it's roleName; role is on JwtPayload), so admins were always self-scoped on /entries and /overrides. Typed the param (no more any). Also removed 4 'category: input.category as any' casts now that category is a String column. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
} from "../../middleware/auth";
|
||||
import { success, error, parseId } from "../../utils/response";
|
||||
import { parseBody } from "../../schemas/common";
|
||||
import { AuthData } from "../../types";
|
||||
import { logAudit } from "../../services/audit";
|
||||
import {
|
||||
CreatePlanEntrySchema,
|
||||
@@ -40,8 +41,12 @@ import {
|
||||
|
||||
const MAX_RANGE_DAYS = 92;
|
||||
|
||||
function isAdminLike(authData: any): boolean {
|
||||
return authData?.role === "admin";
|
||||
// NOTE: AuthData carries `roleName` (not `role` — that lives on JwtPayload).
|
||||
// The previous `authData.role` read was always undefined, so admins were
|
||||
// wrongly scoped to their own plan rows on the /entries and /overrides
|
||||
// endpoints. Typed (not `any`) so this can't silently regress.
|
||||
function isAdminLike(authData: AuthData | undefined): boolean {
|
||||
return authData?.roleName === "admin";
|
||||
}
|
||||
|
||||
function forceFromQuery(query: unknown): boolean {
|
||||
|
||||
Reference in New Issue
Block a user