Files

11 lines
600 B
TypeScript
Raw Permalink Normal View History

import type { AuthUser } from './auth.ts';
export type DemandViewer = Pick<AuthUser, 'userId' | 'role'>;
// Read access only: admin visibility must never grant business/developer writes.
// The owner can read drafts; everyone else's access requires a formal demand.
export const readableDemandWhere = "(owner_id = ? OR (json_extract(payload, '$.status') != '草稿' AND (? = 1 OR json_extract(payload, '$.review.developer.userId') = ?)))";
export function readableDemandBindings(user: DemandViewer): [string, number, string] {
return [user.userId, user.role === 'admin' ? 1 : 0, user.userId];
}