handling bigint errors

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-01 16:27:19 +01:00
parent abad7ad893
commit e0161d1b5f
8 changed files with 14 additions and 12 deletions

View file

@ -10,7 +10,7 @@ import { db } from "@/app/db/db";
import { z } from "zod";
const createPortfolioSchema = z.object({
userId: z.number(),
userId: z.bigint(),
portfolioName: z.string(),
budget: z.number().optional(),
goal: z.enum(PortfolioGoal),
@ -52,7 +52,11 @@ export async function POST(request: NextRequest) {
const response = await db
.insert(portfolioUsers)
.values({ userId: userId, portfolioId: newPortfolioId, role: role })
.values({
userId: userId,
portfolioId: newPortfolioId,
role: role,
})
.returning();
if (response.length !== 1) {

View file

@ -16,7 +16,7 @@ const styles = {
};
interface CardProps {
id: number;
id: bigint;
title: string;
image: string;
budget: number | null;

View file

@ -19,7 +19,7 @@ export default function CardTiles({
const image_idx = index % 5;
return (
<Card
key={portfolio.id}
key={portfolio.id.toString()}
id={portfolio.id}
title={portfolio.name}
image={`house-icon-${image_idx}.svg`}

View file

@ -10,7 +10,7 @@ import {
import { useSession } from "next-auth/react";
type CreatePortfolioArgs = {
userId: number;
userId: bigint;
portfolioName: string;
budget: number | undefined;
goal: (typeof PortfolioGoal)[number];

View file

@ -196,7 +196,7 @@ export type Property = InferModel<typeof property, "select">;
// This type is used for the getProperties function in src/app/portfolio/[slug]/utils.ts
export interface PropertyWithTarget {
status: string | null;
id: number;
id: bigint;
portfolioId: number;
creationStatus: string;
address: string | null;

View file

@ -1,12 +1,10 @@
import { portfolioUsers, PortfolioUsers } from "./../db/schema/portfolio";
import { portfolioUsers } from "./../db/schema/portfolio";
import { eq } from "drizzle-orm";
import { user } from "@/app/db/schema/users";
import { db } from "@/app/db/db";
import { NextRequest, NextResponse } from "next/server";
import { portfolio } from "@/app/db/schema/portfolio";
import type { Portfolio } from "@/app/db/schema/portfolio";
export async function getPortfolios(userId: number): Promise<Portfolio[]> {
export async function getPortfolios(userId: bigint): Promise<Portfolio[]> {
const userPortfolios = await db
.select()
.from(portfolio)

View file

@ -9,7 +9,7 @@ export async function getPortfolio(portfolioId: number): Promise<Portfolio> {
const data = await db
.select()
.from(portfolio)
.where(eq(portfolio.id, portfolioId));
.where(eq(portfolio.id, BigInt(portfolioId)));
if (data.length === 0) {
throw new Error("Portfolio not found");

View file

@ -9,6 +9,6 @@ declare module "next-auth" {
} & DefaultSession["user"];
}
interface User {
dbId: number;
dbId: bigint;
}
}