feat(template): per-experiment daily record template — rename/add/hide fields, custom_fields JSONB

This commit is contained in:
Experiments DB Dev
2026-04-15 13:56:17 -04:00
parent 80fb1c6e27
commit 86a56427b7
10 changed files with 570 additions and 189 deletions
+25
View File
@@ -0,0 +1,25 @@
/**
* The default daily-record template applied to every new experiment
* (and returned as a fallback when an experiment's template is empty).
*
* `builtin: true` — value lives in the named column of daily_statuses
* `builtin: false` — value lives in daily_statuses.custom_fields JSON
* `active: false` — field is hidden (not deleted; data preserved)
*/
const DEFAULT_TEMPLATE = [
{ key: 'experiment_description', label: 'Experiment Description', type: 'textarea', builtin: true, active: true },
{ key: 'vitals', label: 'Vitals', type: 'text', builtin: true, active: true },
{ key: 'treatment', label: 'Treatment', type: 'text', builtin: true, active: true },
{ key: 'notes', label: 'Notes', type: 'textarea', builtin: true, active: true },
];
/**
* Resolve the effective template for an experiment.
* If the stored template is empty (new experiment), return the default.
*/
function resolveTemplate(stored) {
if (!Array.isArray(stored) || stored.length === 0) return DEFAULT_TEMPLATE;
return stored;
}
module.exports = { DEFAULT_TEMPLATE, resolveTemplate };