Skip to content

Commit f029e6f

Browse files
AdaInTheLabLyricCarmel
committed
FIX [SCMS] wire card_style through public mapper for LabNote cards 😼✨
co-authored-by: Lyric <lyric@thehumanpatternlab.com> co-authored-by: Carmel <carmel@thehumanpatternlab.com>
1 parent 218473c commit f029e6f

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

src/mappers/labNotesMapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export function mapToLabNoteView(note: LabNoteRecord, tags: string[]) {
138138

139139
created_at: note.created_at,
140140
updated_at: note.updated_at,
141+
card_style: note.card_style ?? undefined,
141142
};
142143
}
143144

@@ -184,5 +185,6 @@ export function mapToLabNotePreview(note: LabNoteRecord, tags: string[]) {
184185

185186
created_at: note.created_at,
186187
updated_at: note.updated_at,
188+
card_style: note.card_style ?? undefined,
187189
};
188190
}

src/routes/adminRoutes.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
2525
.prepare(
2626
`
2727
SELECT
28-
id, slug, title, locale,
28+
id, slug, title, subtitle, card_style, locale,
2929
type, status, dept,
3030
category, excerpt, summary,
3131
department_id, shadow_density, coherence_score,
@@ -62,7 +62,7 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
6262
.prepare(
6363
`
6464
SELECT
65-
id, slug, title, locale,
65+
id, slug, title, subtitle, card_style, locale,
6666
type, status, dept,
6767
category, excerpt, summary,
6868
content_markdown,
@@ -94,6 +94,8 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
9494
const {
9595
id,
9696
title,
97+
subtitle,
98+
card_style,
9799
slug,
98100
locale,
99101
category,
@@ -114,6 +116,13 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
114116
if (!title) return res.status(400).json({ error: "title is required" });
115117
if (!slug) return res.status(400).json({ error: "slug is required" });
116118

119+
const incomingSubtitle =
120+
typeof subtitle === "string" ? subtitle.trim() : null;
121+
122+
// Allow "" to mean “auto”, store NULL
123+
const incomingCardStyle =
124+
typeof card_style === "string" && card_style.trim() ? card_style.trim().toLowerCase() : null;
125+
117126
const noteLocale = normalizeLocale(locale);
118127
const noteType = String(type ?? "labnote");
119128
const noteStatus = String(status ?? (published_at ? "published" : "draft"));
@@ -157,7 +166,7 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
157166
// 1) Upsert metadata row (NO content_html writes, NO content_markdown column)
158167
db.prepare(`
159168
INSERT INTO lab_notes (
160-
id, title, slug, locale,
169+
id, title, subtitle, card_style, slug, locale,
161170
type, status, dept,
162171
category, excerpt, summary,
163172
department_id, shadow_density, coherence_score,
@@ -166,14 +175,16 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
166175
)
167176
VALUES (
168177
?, ?, ?, ?,
169-
?, ?, ?,
178+
?, ?, ?, ?, ?,
170179
?, ?, ?,
171180
?, ?, ?,
172181
?, ?, ?,
173182
strftime('%Y-%m-%dT%H:%M:%fZ','now')
174183
)
175184
ON CONFLICT(slug, locale) DO UPDATE SET
176185
title=excluded.title,
186+
subtitle = COALESCE(excluded.subtitle, lab_notes.subtitle),
187+
card_style = COALESCE(excluded.card_style, lab_notes.card_style),
177188
type=excluded.type,
178189
status=excluded.status,
179190
dept = COALESCE(excluded.dept, lab_notes.dept),
@@ -190,12 +201,14 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
190201
`).run(
191202
noteId,
192203
title,
204+
subtitle,
205+
card_style,
193206
slug,
194207
noteLocale,
195208

196-
noteType,
209+
resolvedType,
197210
noteStatus,
198-
dept ?? null,
211+
resolvedDepartment,
199212

200213
category || "Uncategorized",
201214
excerpt || "",
@@ -240,9 +253,10 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
240253
slug,
241254
locale: noteLocale,
242255
type: noteType,
243-
title,
256+
subtitle: incomingSubtitle ?? undefined,
257+
card_style: incomingCardStyle ?? undefined,
244258
status: noteStatus,
245-
published: normalizedPublishedAt ?? undefined,
259+
published_at: normalizedPublishedAt ?? undefined,
246260
dept: dept ?? null,
247261
department_id: resolvedDepartment,
248262
shadow_density: shadow_density ?? 0,
@@ -362,8 +376,6 @@ export function registerAdminRoutes(app: any, db: Database.Database) {
362376
}
363377
});
364378

365-
366-
367379
// ---------------------------------------------------------------------------
368380
// Admin: Publish Lab Note (protected)
369381
// ---------------------------------------------------------------------------

src/routes/labNotesRoutes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function registerLabNotesRoutes(app: any, db: Database.Database) {
3131
id, slug, locale, type, status,
3232
title, subtitle, summary, excerpt,
3333
department_id, dept, shadow_density, safer_landing, read_time_minutes,
34-
published_at, created_at, updated_at
34+
published_at, created_at, updated_at, card_style
3535
FROM v_lab_notes
3636
WHERE status = 'published'
3737
${orderBy}
@@ -42,7 +42,7 @@ export function registerLabNotesRoutes(app: any, db: Database.Database) {
4242
id, slug, locale, type, status,
4343
title, subtitle, summary, excerpt,
4444
department_id, dept, shadow_density, safer_landing, read_time_minutes,
45-
published_at, created_at, updated_at
45+
published_at, created_at, updated_at, card_style
4646
FROM v_lab_notes
4747
WHERE locale = ?
4848
AND status = 'published'
@@ -86,7 +86,7 @@ export function registerLabNotesRoutes(app: any, db: Database.Database) {
8686
title, subtitle, summary, excerpt, category,
8787
department_id, dept, shadow_density, coherence_score,
8888
safer_landing, read_time_minutes,
89-
published_at, created_at, updated_at,
89+
published_at, created_at, updated_at, card_style,
9090
content_markdown
9191
FROM v_lab_notes
9292
WHERE slug = ?

src/types/labNotes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface LabNoteRecord {
4242
status?: LabNoteStatus | null;
4343

4444
dept?: string | null;
45+
card_style?: string | null;
4546
locale?: string | null;
4647

4748
author_kind?: "human" | "ai" | "hybrid" | null;
@@ -83,4 +84,5 @@ export interface LabNoteView {
8384

8485
created_at?: string;
8586
updated_at?: string;
87+
card_style?: string;
8688
}

0 commit comments

Comments
 (0)