From ca9b7e0d0e4e57146df20ed2b301c5fd39bc304d Mon Sep 17 00:00:00 2001 From: Cato <41178744+catomean@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:35:56 +0200 Subject: [PATCH] feat(crew): identify assignment changes that require fresh consent --- src/lib/crew/consent-terms.ts | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/lib/crew/consent-terms.ts diff --git a/src/lib/crew/consent-terms.ts b/src/lib/crew/consent-terms.ts new file mode 100644 index 000000000..abb775cb0 --- /dev/null +++ b/src/lib/crew/consent-terms.ts @@ -0,0 +1,39 @@ +/** + * Crew consent is attached to a specific ask, not to a person in the abstract. + * + * Changing who is asked, what they must do, the deadline, the project, or + * the promised fee invalidates the old ask. The owner must share a fresh link + * and the new/current assignee must answer it. + * + * Pure rules here are consumed by the authoritative, row-locked DB writer. + */ +import type { HumanTask } from "@/db/schema/human-tasks"; + +export const WORK_TERMS_FIELDS = [ + "assigneeId", + "projectId", + "title", + "brief", + "reason", + "dueDate", + "feeAmount", + "feeCurrency", +] as const; + +export type WorkTermsPatch = Partial>; + +function equalValue(before: unknown, after: unknown): boolean { + if (before instanceof Date || after instanceof Date) { + return ( + (before instanceof Date ? before.getTime() : before) === + (after instanceof Date ? after.getTime() : after) + ); + } + return before === after; +} + +export function changesCrewConsentTerms(existing: HumanTask, patch: WorkTermsPatch): boolean { + return WORK_TERMS_FIELDS.some( + (key) => patch[key] !== undefined && !equalValue(existing[key], patch[key]), + ); +}