mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
Server-side prep for the next iOS TestFlight build. Five surfaces land together so the iOS engineer can pick them up in one cut-over: a locked externalId shape for daily-aggregated cumulative HealthKit rows, the SyncMode foundation columns + handshake + bulk-backfill endpoints, a first-class MoodEntry.note column that replaces the legacy tag-based workaround, a cross-source workout dedup helper, and two new MeasurementType enums plus the shared category overlay that drives the iOS permission picker and the future Insights nav.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
/**
|
|
* v1.4.30 — pure helper for the `MoodEntry.note` backfill (R-E H-5).
|
|
*
|
|
* Pulls the first `note:<text>` entry out of a JSON-encoded tags array
|
|
* and returns the cleaned tags JSON alongside the extracted note. Used
|
|
* by `scripts/backfill-mood-note-column.ts` (CLI) — kept in `src/lib/`
|
|
* so unit tests can exercise the bucketing without booting `dotenv`
|
|
* + the Prisma client.
|
|
*/
|
|
export function extractNoteAndSlimTags(tagsJson: string): {
|
|
note: string | null;
|
|
newTags: string | null;
|
|
} {
|
|
let parsed: unknown;
|
|
try {
|
|
parsed = JSON.parse(tagsJson);
|
|
} catch {
|
|
return { note: null, newTags: tagsJson };
|
|
}
|
|
if (!Array.isArray(parsed)) {
|
|
return { note: null, newTags: tagsJson };
|
|
}
|
|
let extracted: string | null = null;
|
|
const remaining: string[] = [];
|
|
for (const tag of parsed) {
|
|
if (typeof tag !== "string") {
|
|
remaining.push(String(tag));
|
|
continue;
|
|
}
|
|
if (extracted === null && tag.startsWith("note:")) {
|
|
extracted = tag.slice("note:".length);
|
|
} else {
|
|
remaining.push(tag);
|
|
}
|
|
}
|
|
return {
|
|
note: extracted,
|
|
newTags: remaining.length > 0 ? JSON.stringify(remaining) : null,
|
|
};
|
|
}
|