The code returns the following error:
metric.weight.toFixed is not a function
at (/app/admin/metrics/page)
at MetricsPage (/app/admin/metrics/page)
Revise the code to address the error.
I was previewing: /admin/metrics
Let me read the full metrics page to find all instances where .toFixed() is being called on the weight field.
I found it! There's still one place at line 851 where metric.weight.toFixed(1) is being called without converting to a number first. Let me also check if there are any other instances I need to fix:
I can see both places:
m.weight directly in reduce, which is fine for addition but the result needs conversionLet me fix both places to ensure the weight is converted to a number before calling .toFixed():
I've fixed all instances where weight.toFixed() was being called without proper type conversion. The PostgreSQL NUMERIC type returns values as strings in JavaScript, so I've added Number() conversion in both the average weight calculation (line 692) and the individual metric weight display (line 851) to ensure .toFixed() can be called successfully.
The code returns the following error:
Server Action: Error fetching controls: sql.array is not a function
at fetchControlsForStandards (/app/admin/metrics/actions)
at async fetchControls (/app/admin/metrics/page)
Revise the code to address the error.
I was previewing: /admin/metrics
Let me check the debug logs and the metrics actions file to understand the SQL query issue.
I can see the issue! The @neondatabase/serverless driver doesn't have a sql.array() method. Instead, I need to construct the SQL query differently to handle the array parameter. Let me check how other parts of the code handle arrays with the neon driver:
Now I understand the issue. The @neondatabase/serverless driver doesn't have a sql.array() method. I need to use a different approach to pass arrays to PostgreSQL. The proper way is to use JSON.stringify for the array and cast it, or construct the query with proper parameter substitution. Let me fix all instances of sql.array() in the metrics actions:
I've fixed the sql.array() errors by removing the non-existent method calls. For the frameworks field, I'm now using JSON.stringify() to store the array as JSON in the database. For the fetchControlsForStandards function, I replaced the ANY(sql.array()) syntax with a proper IN clause using parameterized placeholders, which is the correct approach for the @neondatabase/serverless driver that doesn't support the sql.array() helper method.
Remove the option "Compliance Frameworks" from the "Add Metric" option.