Zeke
Zeke
Explore posts from servers
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
Interestingly, when removing everything after $extends... It is fixed... May be a Turso issue. No clue.,
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
I AM using Turso! Maybe there is something not supported? Here is my prisma.ts:
import { PrismaClient } from '@prisma/client'
import { PrismaLibSQL } from '@prisma/adapter-libsql'
import { createClient } from '@libsql/client'

const libsql = createClient({
url: `${process.env.TURSO_DATABASE_URL}`,
authToken: `${process.env.TURSO_AUTH_TOKEN}`,
})

const adapter = new PrismaLibSQL(libsql)
const prisma = new PrismaClient({ adapter }).$extends({
query: {
$allModels: {
async $allOperations({ operation, model, args, query }) {
const result = await query(args)

if (['create', 'update', 'delete'].includes(operation)) {
await libsql.sync()
}

return result
}
}
}
})

export default prisma
import { PrismaClient } from '@prisma/client'
import { PrismaLibSQL } from '@prisma/adapter-libsql'
import { createClient } from '@libsql/client'

const libsql = createClient({
url: `${process.env.TURSO_DATABASE_URL}`,
authToken: `${process.env.TURSO_AUTH_TOKEN}`,
})

const adapter = new PrismaLibSQL(libsql)
const prisma = new PrismaClient({ adapter }).$extends({
query: {
$allModels: {
async $allOperations({ operation, model, args, query }) {
const result = await query(args)

if (['create', 'update', 'delete'].includes(operation)) {
await libsql.sync()
}

return result
}
}
}
})

export default prisma
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
I can confirm all the relevant variables are correct. In any other query I run, for example, creating hosts, creating shows, deleting shows, you name it - Anything where a 'create', 'update', or 'delete', is going down - This error occurs.
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
Here is my schema.prisma:
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "sqlite"
url = "file:./dev.db"
}

model Show {
id String @id @default(cuid())
name String
startTime DateTime
endTime DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
hostId String
host Host @relation(fields: [hostId], references: [id], onDelete: Cascade)

@@index([hostId], map: "Show_hostId_fkey")
}

model Host {
id String @id @default(cuid())
name String
imageUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
shows Show[]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "sqlite"
url = "file:./dev.db"
}

model Show {
id String @id @default(cuid())
name String
startTime DateTime
endTime DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
hostId String
host Host @relation(fields: [hostId], references: [id], onDelete: Cascade)

@@index([hostId], map: "Show_hostId_fkey")
}

model Host {
id String @id @default(cuid())
name String
imageUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
shows Show[]
}
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
And, upon catching an error in that query, I get this:
Error deleting host: TypeError: The "payload" argument must be of type object. Received null
at frame (node_modules\next\src\server\patch-error-inspect.ts:89:42)
at getSourcemappedFrameIfPossible (node_modules\next\src\server\patch-error-inspect.ts:179:32)
at parseAndSourceMap (node_modules\next\src\server\patch-error-inspect.ts:234:23)
at exit (node_modules\next\src\server\patch-error-inspect.ts:224:32)
at apply (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:569:32)
at apply (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js:593:32)
at log (app\actions.ts:141:30)
at async deleteHost (app\actions.ts:136:4)
at async (webpack://next/dist/src/server/app-render/action-handler.ts:881:24)
at async handleAction (webpack://next/dist/src/server/app-render/action-handler.ts:617:4)
at async renderToHTMLOrFlightImpl (webpack://next/dist/src/server/app-render/app-render.tsx:1310:34)
at async doRender (node_modules\next\src\server\base-server.ts:2666:21)
at async responseGenerator (node_modules\next\src\server\base-server.ts:3027:21)
at async DevServer.renderToResponseWithComponentsImpl (node_modules\next\src\server\base-server.ts:3039:23)
at async DevServer.renderPageComponent (node_modules\next\src\server\base-server.ts:3597:15)
at async DevServer.renderToResponseImpl (node_modules\next\src\server\base-server.ts:3659:23)
at async DevServer.pipeImpl (node_modules\next\src\server\base-server.ts:1698:20)
at async NextNodeServer.handleCatchallRenderRequest (node_modules\next\src\server\next-server.ts:1034:6)
at async DevServer.handleRequestImpl (node_modules\next\src\server\base-server.ts:1462:8)
at async (node_modules\next\src\server\dev\next-dev-server.ts:514:13)
at async Span.traceAsyncFn (node_modules\next\src\trace\trace.ts:143:13)
at async DevServer.handleRequest (node_modules\next\src\server\dev\next-dev-server.ts:512:19)
at async invokeRender (node_modules\next\src\server\lib\router-server.ts:284:10)
at async handleRequest (node_modules\next\src\server\lib\router-server.ts:530:15)
at async requestHandlerImpl (node_modules\next\src\server\lib\router-server.ts:576:6)
at async Server.requestListener (node_modules\next\src\server\lib\start-server.ts:146:6)
139 | shows: true,
140 | },
> 141 | }).catch(error => console.log(error));
| ^
142 |
143 | return new Response("Success!", { status: 200 })
144 | } catch (error) { {
code: 'ERR_INVALID_ARG_TYPE'
}
⨯ app\actions.ts (146:11) @ deleteHost
⨯ Error: Failed to delete host.
at deleteHost (./app/actions.ts:158:15)
digest: "619090243"
144 | } catch (error) {
145 | console.error("Error deleting host:", error);
> 146 | throw new Error("Failed to delete host.");
| ^
147 | }
148 | }
149 |
Error deleting host: TypeError: The "payload" argument must be of type object. Received null
at frame (node_modules\next\src\server\patch-error-inspect.ts:89:42)
at getSourcemappedFrameIfPossible (node_modules\next\src\server\patch-error-inspect.ts:179:32)
at parseAndSourceMap (node_modules\next\src\server\patch-error-inspect.ts:234:23)
at exit (node_modules\next\src\server\patch-error-inspect.ts:224:32)
at apply (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js:569:32)
at apply (webpack://next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js:593:32)
at log (app\actions.ts:141:30)
at async deleteHost (app\actions.ts:136:4)
at async (webpack://next/dist/src/server/app-render/action-handler.ts:881:24)
at async handleAction (webpack://next/dist/src/server/app-render/action-handler.ts:617:4)
at async renderToHTMLOrFlightImpl (webpack://next/dist/src/server/app-render/app-render.tsx:1310:34)
at async doRender (node_modules\next\src\server\base-server.ts:2666:21)
at async responseGenerator (node_modules\next\src\server\base-server.ts:3027:21)
at async DevServer.renderToResponseWithComponentsImpl (node_modules\next\src\server\base-server.ts:3039:23)
at async DevServer.renderPageComponent (node_modules\next\src\server\base-server.ts:3597:15)
at async DevServer.renderToResponseImpl (node_modules\next\src\server\base-server.ts:3659:23)
at async DevServer.pipeImpl (node_modules\next\src\server\base-server.ts:1698:20)
at async NextNodeServer.handleCatchallRenderRequest (node_modules\next\src\server\next-server.ts:1034:6)
at async DevServer.handleRequestImpl (node_modules\next\src\server\base-server.ts:1462:8)
at async (node_modules\next\src\server\dev\next-dev-server.ts:514:13)
at async Span.traceAsyncFn (node_modules\next\src\trace\trace.ts:143:13)
at async DevServer.handleRequest (node_modules\next\src\server\dev\next-dev-server.ts:512:19)
at async invokeRender (node_modules\next\src\server\lib\router-server.ts:284:10)
at async handleRequest (node_modules\next\src\server\lib\router-server.ts:530:15)
at async requestHandlerImpl (node_modules\next\src\server\lib\router-server.ts:576:6)
at async Server.requestListener (node_modules\next\src\server\lib\start-server.ts:146:6)
139 | shows: true,
140 | },
> 141 | }).catch(error => console.log(error));
| ^
142 |
143 | return new Response("Success!", { status: 200 })
144 | } catch (error) { {
code: 'ERR_INVALID_ARG_TYPE'
}
⨯ app\actions.ts (146:11) @ deleteHost
⨯ Error: Failed to delete host.
at deleteHost (./app/actions.ts:158:15)
digest: "619090243"
144 | } catch (error) {
145 | console.error("Error deleting host:", error);
> 146 | throw new Error("Failed to delete host.");
| ^
147 | }
148 | }
149 |
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
Here is the relevant section of my new Actions.ts:
export async function deleteHost(hostId: string) {
const session = await auth();

if (!session || !session.user?.id) {
throw new Error("Unauthorized: User must be logged in.");
}

if (!isStaff(session.user.id)) {
throw new Error("Forbidden: User does not have permission.");
}

if (!hostId) {
throw new Error("Host ID is required.");
}

try {
await prisma.host.delete({
where: { id: hostId }
}).catch(error => console.log(error));

return new Response("Success!", { status: 200 })
} catch (error) {
console.error("Error deleting host:", error);
throw new Error("Failed to delete host.");
}
}
export async function deleteHost(hostId: string) {
const session = await auth();

if (!session || !session.user?.id) {
throw new Error("Unauthorized: User must be logged in.");
}

if (!isStaff(session.user.id)) {
throw new Error("Forbidden: User does not have permission.");
}

if (!hostId) {
throw new Error("Host ID is required.");
}

try {
await prisma.host.delete({
where: { id: hostId }
}).catch(error => console.log(error));

return new Response("Success!", { status: 200 })
} catch (error) {
console.error("Error deleting host:", error);
throw new Error("Failed to delete host.");
}
}
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
I have switched over to using a server action implementation
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
Hi. Thanks for the reply
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
Note the object is being created in database, however it doesn't seem to want to return back to the client after request.
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
Relevant API route.ts:
import { NextResponse } from "next/server";
import { auth } from "@/auth";
import prisma from "@/prisma";
import { isStaff } from "@/lib/Staff";

export async function GET() {
try {
const now = new Date();
const shows = await prisma.show.findMany({
where: {
startTime: { gt: now },
},
orderBy: { startTime: "asc" },
include: { host: true },
});

return NextResponse.json(shows);
} catch (error) {
console.error("Error fetching shows:", error);
return NextResponse.error();
}
}

export async function POST(req: Request) {
const session = await auth();

if (!session || !session.user?.id) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

if (!isStaff(session.user.id)) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}

try {
const formData = await req.formData();

const name = formData.get("name");
const hostId = formData.get("hostId");
const startTime = formData.get("startTime");
const endTime = formData.get("endTime");

if (!name || !hostId || !startTime || !endTime) {
return NextResponse.json({ error: "All fields are required." }, { status: 400 });
}

const start = new Date(startTime.toString());
const end = new Date(endTime.toString());

if (isNaN(start.getTime()) || isNaN(end.getTime())) {
return NextResponse.json({ error: "Invalid date format." }, { status: 400 });
}

if (start >= end) {
return NextResponse.json({ error: "Start time must be before end time." }, { status: 400 });
}

const show = await prisma.show.create({
data: {
name: name.toString(),
startTime: start,
endTime: end,
host: {
connect: { id: hostId.toString() },
},
},
include: { host: true },
});

return NextResponse.json(show);
} catch (error) {
console.error("Error creating show:", error);
return NextResponse.json({ error: "Failed to create show." }, { status: 500 });
}
}
import { NextResponse } from "next/server";
import { auth } from "@/auth";
import prisma from "@/prisma";
import { isStaff } from "@/lib/Staff";

export async function GET() {
try {
const now = new Date();
const shows = await prisma.show.findMany({
where: {
startTime: { gt: now },
},
orderBy: { startTime: "asc" },
include: { host: true },
});

return NextResponse.json(shows);
} catch (error) {
console.error("Error fetching shows:", error);
return NextResponse.error();
}
}

export async function POST(req: Request) {
const session = await auth();

if (!session || !session.user?.id) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

if (!isStaff(session.user.id)) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}

try {
const formData = await req.formData();

const name = formData.get("name");
const hostId = formData.get("hostId");
const startTime = formData.get("startTime");
const endTime = formData.get("endTime");

if (!name || !hostId || !startTime || !endTime) {
return NextResponse.json({ error: "All fields are required." }, { status: 400 });
}

const start = new Date(startTime.toString());
const end = new Date(endTime.toString());

if (isNaN(start.getTime()) || isNaN(end.getTime())) {
return NextResponse.json({ error: "Invalid date format." }, { status: 400 });
}

if (start >= end) {
return NextResponse.json({ error: "Start time must be before end time." }, { status: 400 });
}

const show = await prisma.show.create({
data: {
name: name.toString(),
startTime: start,
endTime: end,
host: {
connect: { id: hostId.toString() },
},
},
include: { host: true },
});

return NextResponse.json(show);
} catch (error) {
console.error("Error creating show:", error);
return NextResponse.json({ error: "Failed to create show." }, { status: 500 });
}
}
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
20 replies
PPrisma
Created by яσчαℓтℓя on 11/20/2024 in #help-and-questions
TypeError: The "payload" argument must be of type object. Received null
Getting the exact same thing
20 replies
PPrisma
Created by Zeke on 3/21/2024 in #help-and-questions
Pull Operator not Existing?
Ended up removing my string array and replacing it with an ‘AccountGuild’ model array. This way I can target each one individually.
8 replies
PPrisma
Created by Zeke on 3/21/2024 in #help-and-questions
Pull Operator not Existing?
Hm. Doesn't look like pull even exists. The only fix I can think of is finding the document, grabbing guildIds, then updating guildIds to be the pre-found array filtering out guild_id. But that seems too complex for the task at hand. Surely, a method exists somewhere? Thanks nonetheless.
8 replies
PPrisma
Created by Zeke on 3/21/2024 in #help-and-questions
Pull Operator not Existing?
Why would push not be $push if pull were supposed to be $pull too?
8 replies
PPrisma
Created by Zeke on 3/21/2024 in #help-and-questions
Pull Operator not Existing?
Same error. That doesn't exist.
8 replies
DIAdiscord.js - Imagine an app
Created by Zeke on 3/8/2024 in #djs-questions
Property 'id' does not exist on type 'APIGuild'.
Is there no solution lol?
14 replies
DIAdiscord.js - Imagine an app
Created by Zeke on 3/8/2024 in #djs-questions
Property 'id' does not exist on type 'APIGuild'.
enum GuildAuthStatus {
NotFound = 'Not Found',
Unauthorized = 'Unauthorized',
Authorized = 'Authorized',
}

export async function getGuild(guildId: string) {
const session = await auth();

const botGuildRes = await fetch(`https://discord.com/api/v10/guilds/${guildId}`, {
headers: {
Authorization: 'Bot ' + process.env.DISCORD_BOT_TOKEN,
},
next: { revalidate: 4 }
});

if (!botGuildRes.ok) {
const userGuild = await getUserGuild(guildId, session?.user.access_token)
delGuildDoc(guildId)

if (!userGuild || !userGuild.owner) {
return { status: GuildAuthStatus.Unauthorized, guild: userGuild }
}

return { status: GuildAuthStatus.NotFound, guild: userGuild };
};

const botGuild: APIGuild = await botGuildRes.json();
setupGuildDoc(botGuild);

if (botGuild.owner_id !== session?.user.id) {
return { status: GuildAuthStatus.Unauthorized, guild: botGuild };
};

return { status: GuildAuthStatus.Authorized, guild: botGuild };
};
enum GuildAuthStatus {
NotFound = 'Not Found',
Unauthorized = 'Unauthorized',
Authorized = 'Authorized',
}

export async function getGuild(guildId: string) {
const session = await auth();

const botGuildRes = await fetch(`https://discord.com/api/v10/guilds/${guildId}`, {
headers: {
Authorization: 'Bot ' + process.env.DISCORD_BOT_TOKEN,
},
next: { revalidate: 4 }
});

if (!botGuildRes.ok) {
const userGuild = await getUserGuild(guildId, session?.user.access_token)
delGuildDoc(guildId)

if (!userGuild || !userGuild.owner) {
return { status: GuildAuthStatus.Unauthorized, guild: userGuild }
}

return { status: GuildAuthStatus.NotFound, guild: userGuild };
};

const botGuild: APIGuild = await botGuildRes.json();
setupGuildDoc(botGuild);

if (botGuild.owner_id !== session?.user.id) {
return { status: GuildAuthStatus.Unauthorized, guild: botGuild };
};

return { status: GuildAuthStatus.Authorized, guild: botGuild };
};
14 replies
DIAdiscord.js - Imagine an app
Created by Zeke on 3/8/2024 in #djs-questions
Property 'id' does not exist on type 'APIGuild'.
Or, null, since it might not exist
14 replies
DIAdiscord.js - Imagine an app
Created by Zeke on 3/8/2024 in #djs-questions
Property 'id' does not exist on type 'APIGuild'.
I’m on mobile, but The get guild function fetch request discord api for v10 guild, inline with what discord api types APIGuild should be
14 replies