mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
fixing bigint issue with creating portfolio
This commit is contained in:
parent
e0161d1b5f
commit
3afc4ba49e
6 changed files with 25 additions and 8 deletions
|
|
@ -8,9 +8,10 @@ import {
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { db } from "@/app/db/db";
|
||||
import { z } from "zod";
|
||||
import { serializeBigInt } from "@/app/utils";
|
||||
|
||||
const createPortfolioSchema = z.object({
|
||||
userId: z.bigint(),
|
||||
userId: z.string(),
|
||||
portfolioName: z.string(),
|
||||
budget: z.number().optional(),
|
||||
goal: z.enum(PortfolioGoal),
|
||||
|
|
@ -53,7 +54,7 @@ export async function POST(request: NextRequest) {
|
|||
const response = await db
|
||||
.insert(portfolioUsers)
|
||||
.values({
|
||||
userId: userId,
|
||||
userId: BigInt(userId),
|
||||
portfolioId: newPortfolioId,
|
||||
role: role,
|
||||
})
|
||||
|
|
@ -62,7 +63,10 @@ export async function POST(request: NextRequest) {
|
|||
if (response.length !== 1) {
|
||||
throw new Error("Got back more than one row from insert - investigate");
|
||||
}
|
||||
return new NextResponse(JSON.stringify(response[0]), { status: 201 });
|
||||
|
||||
return new NextResponse(JSON.stringify(response[0], serializeBigInt), {
|
||||
status: 201,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return new NextResponse(JSON.stringify({ msg: "Insternal server error" }), {
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ const createPortfolio = async ({
|
|||
status,
|
||||
role,
|
||||
}: CreatePortfolioArgs) => {
|
||||
// We convert the the bigint to a string since big ints are not serialisable and we don't want to loose precision
|
||||
const requestBody = JSON.stringify({
|
||||
userId: userId,
|
||||
userId: userId.toString(),
|
||||
portfolioName: portfolioName,
|
||||
budget: budget,
|
||||
goal: goal,
|
||||
|
|
|
|||
|
|
@ -155,6 +155,13 @@
|
|||
"when": 1690902069171,
|
||||
"tag": "0021_eager_titanium_man",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 22,
|
||||
"version": "5",
|
||||
"when": 1690906901377,
|
||||
"tag": "0022_smiling_callisto",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -135,8 +135,8 @@ export const propertyDetailsEpc = pgTable("property_details_epc", {
|
|||
windowsRating: smallint("windows_rating"),
|
||||
heating: text("heating"),
|
||||
heatingRating: smallint("heating_rating"),
|
||||
heatingContols: text("heating_contols"),
|
||||
heatingContolsRating: smallint("heating_contols_rating"),
|
||||
heatingControls: text("heating_controls"),
|
||||
heatingControlsRating: smallint("heating_controls_rating"),
|
||||
hotWater: text("hot_water"),
|
||||
hotWaterRating: smallint("hot_water_rating"),
|
||||
lighting: text("lighting"),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
export const serializeBigInt = (_: any, value: any): string | any => {
|
||||
// Simple utility function to convert BigInts to strings with JSON.stringify
|
||||
return typeof value === "bigint" ? value.toString() : value;
|
||||
};
|
||||
|
||||
export function sapToEpc(sapPoints: number): string {
|
||||
if (sapPoints <= 0 || sapPoints > 100) {
|
||||
throw new Error("SAP points should be between 1 and 100.");
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es5",
|
||||
// "target": "ESNext",
|
||||
// "target": "es5",
|
||||
"target": "ESNext",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue