fix(metadata): persist a cleared air_timezone instead of skipping it

Clearing a previously-set air timezone sent JSON null, which decodes to a
nil *string that UpdateMetadata treats as "skip this column", so the old
value remained. The dialog now sends "" (accepted by ValidateAirTimezone),
and UpdateMetadata maps air_timezone through NULLIF so an empty value
persists as SQL NULL (matching the nullable column) rather than "".

Addresses PR #21 review (P2).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Quick
2026-05-28 20:26:15 -04:00
co-authored by Claude Opus 4.8
parent a4c394b827
commit 9fceae63fc
2 changed files with 14 additions and 2 deletions
+10 -1
View File
@@ -1240,6 +1240,15 @@ func (r *ItemRepository) UpdateMetadata(ctx context.Context, contentID string, u
argIdx++
}
}
// addNullableString behaves like addString but stores an empty string as SQL
// NULL (via NULLIF), so clearing a nullable column persists as NULL.
addNullableString := func(col string, val *string) {
if val != nil {
setClauses = append(setClauses, fmt.Sprintf("%s = NULLIF($%d, '')", col, argIdx))
args = append(args, *val)
argIdx++
}
}
addInt := func(col string, val *int) {
if val != nil {
setClauses = append(setClauses, fmt.Sprintf("%s = $%d", col, argIdx))
@@ -1289,7 +1298,7 @@ func (r *ItemRepository) UpdateMetadata(ctx context.Context, contentID string, u
addString("first_air_date", upd.FirstAirDate)
addString("last_air_date", upd.LastAirDate)
addString("air_time", upd.AirTime)
addString("air_timezone", upd.AirTimezone)
addNullableString("air_timezone", upd.AirTimezone)
addString("status", upd.Status)
addString("show_status", upd.ShowStatus)
addString("imdb_id", upd.ImdbID)
+4 -1
View File
@@ -185,7 +185,10 @@ export default function EditMetadataDialog({ item, open, onOpenChange }: EditMet
data.last_air_date = form.last_air_date || null;
if (form.air_time !== originalForm.air_time) data.air_time = form.air_time || null;
if (form.air_timezone !== originalForm.air_timezone)
data.air_timezone = form.air_timezone || null;
// Send "" (not null) when cleared: the server treats null as "skip", so
// clearing a previously-set timezone would not persist. "" is accepted by
// validation and normalized to NULL server-side.
data.air_timezone = form.air_timezone;
if (form.air_date !== originalForm.air_date) data.air_date = form.air_date || null;
if (form.status !== originalForm.status) data.status = form.status;
if (form.rating_imdb !== originalForm.rating_imdb) data.rating_imdb = form.rating_imdb;