mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
The edit sheet loaded the decrypted note from the single-resource GET and sent note:null on a load miss, silently wiping a note that simply could not be read. The submit path now omits the note key entirely in that case (server preserves the stored ciphertext), disables the textarea, and shows a hint. Decision encoded in a pure resolveNoteForUpdate helper with tests.
25 lines
1015 B
TypeScript
25 lines
1015 B
TypeScript
/**
|
|
* v1.18.1 — note-resolution for the lab-reading edit PUT.
|
|
*
|
|
* The edit sheet loads a row's decrypted note from the single-resource GET.
|
|
* If that load FAILS we must never send `note: null` — an empty editor would
|
|
* then wipe a note we simply couldn't read. This pure helper encodes the
|
|
* three-way decision the submit path uses:
|
|
*
|
|
* - load failed AND the row had a note → `undefined` (omit `note` from the
|
|
* PUT body so the server preserves the stored ciphertext untouched).
|
|
* - editor is empty → `null` (clear the note).
|
|
* - editor has text → the trimmed text (set the note).
|
|
*
|
|
* `undefined` is the signal the caller uses to OMIT the key entirely.
|
|
*/
|
|
export function resolveNoteForUpdate(args: {
|
|
noteLoadFailed: boolean;
|
|
hadNote: boolean;
|
|
editorValue: string;
|
|
}): string | null | undefined {
|
|
if (args.noteLoadFailed && args.hadNote) return undefined;
|
|
const trimmed = args.editorValue.trim();
|
|
return trimmed ? trimmed : null;
|
|
}
|