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 (
"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
}
+4 -8
View File
@@ -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)
@@ -36,12 +36,7 @@
let loading = $state(true);
let serviceErrors = $state<Record<string, string>>({});
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';
}