From f5c2c26fe41d5a70af2af5fc9fa302cdc5932f99 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Fri, 29 May 2026 17:46:15 +0100 Subject: [PATCH] fix: resolve compilation errors in frontend and backend --- backend/handlers/admin/patch_tests.go | 16 ++++++++-------- backend/handlers/admin/patch_tests_test.go | 12 ++++-------- .../components/admin/ServicesManagement.svelte | 9 ++------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/backend/handlers/admin/patch_tests.go b/backend/handlers/admin/patch_tests.go index deba7c4..c1d0c3a 100644 --- a/backend/handlers/admin/patch_tests.go +++ b/backend/handlers/admin/patch_tests.go @@ -3,10 +3,10 @@ package admin import ( "crussell/db" "crussell/internal/validators" - "crussell/mw" "database/sql" "encoding/json" "net/http" + "strconv" "github.com/go-chi/chi/v5" ) @@ -117,38 +117,38 @@ func UpdatePatchTest(w http.ResponseWriter, r *http.Request) { i := 1 if req.Name != nil { - query += "name = $" + string(rune('0'+i)) + ", " + query += "name = $" + strconv.Itoa(i) + ", " args = append(args, *req.Name) i++ } if req.Description != nil { - query += "description = $" + string(rune('0'+i)) + ", " + query += "description = $" + strconv.Itoa(i) + ", " args = append(args, *req.Description) i++ } if req.NoticeDurationHours != nil { - query += "notice_duration_hours = $" + string(rune('0'+i)) + ", " + query += "notice_duration_hours = $" + strconv.Itoa(i) + ", " args = append(args, *req.NoticeDurationHours) i++ } if req.ExpiryMonths != nil { - query += "expiry_months = $" + string(rune('0'+i)) + ", " + query += "expiry_months = $" + strconv.Itoa(i) + ", " args = append(args, *req.ExpiryMonths) i++ } if req.ServiceIDs != nil { - query += "service_ids = $" + string(rune('0'+i)) + ", " + query += "service_ids = $" + strconv.Itoa(i) + ", " args = append(args, req.ServiceIDs) i++ } query = query[:len(query)-2] - query += " WHERE id = $" + string(rune('0'+i)) + query += " WHERE id = $" + strconv.Itoa(i) args = append(args, id) _, err := db.DB.Exec(r.Context(), query, args...) if err != nil { - http.Error(w, "Failed to update patch test: "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Failed to update patch test: " + err.Error() + " Query: " + query, http.StatusInternalServerError) return } diff --git a/backend/handlers/admin/patch_tests_test.go b/backend/handlers/admin/patch_tests_test.go index 35229ab..4892026 100644 --- a/backend/handlers/admin/patch_tests_test.go +++ b/backend/handlers/admin/patch_tests_test.go @@ -4,9 +4,6 @@ package admin import ( - "bytes" - "context" - "encoding/json" "net/http" "testing" @@ -14,6 +11,7 @@ import ( "crussell/testutils/fixtures" ) + func TestPatchTests_CRUD(t *testing.T) { resetTestData(t) @@ -30,8 +28,7 @@ func TestPatchTests_CRUD(t *testing.T) { ExpiryMonths: 6, ServiceIDs: []string{serviceID}, } - body, _ := json.Marshal(req) - w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", bytes.NewReader(body)) + w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", req) if w.Code != http.StatusCreated { t.Fatalf("expected 201, got %d", w.Code) } @@ -54,10 +51,9 @@ func TestPatchTests_CRUD(t *testing.T) { newName := "Updated Name" updateReq := UpdatePatchTestRequest{Name: &newName} - updateBody, _ := json.Marshal(updateReq) - w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, bytes.NewReader(updateBody)) + w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, updateReq) if w.Code != http.StatusNoContent { - t.Fatalf("expected 204, got %d", w.Code) + t.Fatalf("expected 204, got %d, body: %s", w.Code, w.Body.String()) } w = makeAdminRequest(http.HandlerFunc(DeletePatchTest), "DELETE", "/api/admin/patch-tests/"+created.ID, nil) diff --git a/frontend/src/lib/components/admin/ServicesManagement.svelte b/frontend/src/lib/components/admin/ServicesManagement.svelte index c7f8373..08fa8f0 100644 --- a/frontend/src/lib/components/admin/ServicesManagement.svelte +++ b/frontend/src/lib/components/admin/ServicesManagement.svelte @@ -36,12 +36,7 @@ let loading = $state(true); let serviceErrors = $state>({}); - function validateDuration(val: any, field: string) { - if (typeof val !== 'number' || val < 0) return 'Duration must be a positive number'; - return ''; - } - - + function validatePrice(price: any): string { const numPrice = parseFloat(price); if (isNaN(numPrice)) { return 'Price must be a valid number'; @@ -52,7 +47,7 @@ } const decimalRegex = /^\d+(\.\d{1,2})?$/; - if (!decimalRegex.test(price)) { + if (!decimalRegex.test(price.toString())) { return 'Price can have up to 2 decimal places'; }