fix: resolve compilation errors in frontend and backend

This commit is contained in:
2026-05-29 17:46:15 +01:00
parent f36497090a
commit f5c2c26fe4
3 changed files with 14 additions and 23 deletions
+8 -8
View File
@@ -3,10 +3,10 @@ package admin
import ( import (
"crussell/db" "crussell/db"
"crussell/internal/validators" "crussell/internal/validators"
"crussell/mw"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"net/http" "net/http"
"strconv"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
) )
@@ -117,38 +117,38 @@ func UpdatePatchTest(w http.ResponseWriter, r *http.Request) {
i := 1 i := 1
if req.Name != nil { if req.Name != nil {
query += "name = $" + string(rune('0'+i)) + ", " query += "name = $" + strconv.Itoa(i) + ", "
args = append(args, *req.Name) args = append(args, *req.Name)
i++ i++
} }
if req.Description != nil { if req.Description != nil {
query += "description = $" + string(rune('0'+i)) + ", " query += "description = $" + strconv.Itoa(i) + ", "
args = append(args, *req.Description) args = append(args, *req.Description)
i++ i++
} }
if req.NoticeDurationHours != nil { if req.NoticeDurationHours != nil {
query += "notice_duration_hours = $" + string(rune('0'+i)) + ", " query += "notice_duration_hours = $" + strconv.Itoa(i) + ", "
args = append(args, *req.NoticeDurationHours) args = append(args, *req.NoticeDurationHours)
i++ i++
} }
if req.ExpiryMonths != nil { if req.ExpiryMonths != nil {
query += "expiry_months = $" + string(rune('0'+i)) + ", " query += "expiry_months = $" + strconv.Itoa(i) + ", "
args = append(args, *req.ExpiryMonths) args = append(args, *req.ExpiryMonths)
i++ i++
} }
if req.ServiceIDs != nil { if req.ServiceIDs != nil {
query += "service_ids = $" + string(rune('0'+i)) + ", " query += "service_ids = $" + strconv.Itoa(i) + ", "
args = append(args, req.ServiceIDs) args = append(args, req.ServiceIDs)
i++ i++
} }
query = query[:len(query)-2] query = query[:len(query)-2]
query += " WHERE id = $" + string(rune('0'+i)) query += " WHERE id = $" + strconv.Itoa(i)
args = append(args, id) args = append(args, id)
_, err := db.DB.Exec(r.Context(), query, args...) _, err := db.DB.Exec(r.Context(), query, args...)
if err != nil { 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 return
} }
+4 -8
View File
@@ -4,9 +4,6 @@
package admin package admin
import ( import (
"bytes"
"context"
"encoding/json"
"net/http" "net/http"
"testing" "testing"
@@ -14,6 +11,7 @@ import (
"crussell/testutils/fixtures" "crussell/testutils/fixtures"
) )
func TestPatchTests_CRUD(t *testing.T) { func TestPatchTests_CRUD(t *testing.T) {
resetTestData(t) resetTestData(t)
@@ -30,8 +28,7 @@ func TestPatchTests_CRUD(t *testing.T) {
ExpiryMonths: 6, ExpiryMonths: 6,
ServiceIDs: []string{serviceID}, ServiceIDs: []string{serviceID},
} }
body, _ := json.Marshal(req) w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", req)
w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", bytes.NewReader(body))
if w.Code != http.StatusCreated { if w.Code != http.StatusCreated {
t.Fatalf("expected 201, got %d", w.Code) t.Fatalf("expected 201, got %d", w.Code)
} }
@@ -54,10 +51,9 @@ func TestPatchTests_CRUD(t *testing.T) {
newName := "Updated Name" newName := "Updated Name"
updateReq := UpdatePatchTestRequest{Name: &newName} updateReq := UpdatePatchTestRequest{Name: &newName}
updateBody, _ := json.Marshal(updateReq) w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, updateReq)
w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, bytes.NewReader(updateBody))
if w.Code != http.StatusNoContent { 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) w = makeAdminRequest(http.HandlerFunc(DeletePatchTest), "DELETE", "/api/admin/patch-tests/"+created.ID, nil)
@@ -36,12 +36,7 @@
let loading = $state(true); let loading = $state(true);
let serviceErrors = $state<Record<string, string>>({}); let serviceErrors = $state<Record<string, string>>({});
function validateDuration(val: any, field: string) { function validatePrice(price: any): string {
if (typeof val !== 'number' || val < 0) return 'Duration must be a positive number';
return '';
}
const numPrice = parseFloat(price); const numPrice = parseFloat(price);
if (isNaN(numPrice)) { if (isNaN(numPrice)) {
return 'Price must be a valid number'; return 'Price must be a valid number';
@@ -52,7 +47,7 @@
} }
const decimalRegex = /^\d+(\.\d{1,2})?$/; const decimalRegex = /^\d+(\.\d{1,2})?$/;
if (!decimalRegex.test(price)) { if (!decimalRegex.test(price.toString())) {
return 'Price can have up to 2 decimal places'; return 'Price can have up to 2 decimal places';
} }