Whenever I try to generate a room without adding a RoomMember, everything goes smoothly. However, the moment I attempt to include a member using the createRoomAction function, an error message pops up:
Error Message:
Invalid
prisma.roomMember.create()
invocation:
{
data: {
emailAddress: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="badbd6d2dfd4ded3c9dbd3defaddd7dbd3d694d9d5d7">[email protected]</a>",
role: "admin",
name: "Said",
userId: "user_2eUSQ4tHpc5dlmeNpqhYu27k3gT",
roomId: "19058849-924f-4805-ba40-3c8513be5ed5",
~~~~~~
? id?: String,
? createdAt?: DateTime,
? updatedAt?: DateTime
}
}
Unknown argument
roomId
. Check available options indicated with ?.
The createRoomAction method appears as follows:
export async function createRoomAction(values: createAndEditRoomType): Promise<RoomType | null> {
const { id: userId, emailAddresses, firstName } = await authenticateAndRedirect();
const emailAddress = emailAddresses[0]?.emailAddress || "";
const AdminName = firstName || "";
try {
const room = await prisma.room.create({
data: {
...values,
clerkId: userId,
emailAddress: emailAddress
}
});
const admin = await prisma.roomMember.create({
data: {
emailAddress: emailAddress,
role: "admin",
name: AdminName,
userId,
roomId: room.id,
}
});
return room;
} catch (error) {
console.error("Error creating admin:", error);
return null;
}
}
This is how my Prisma schema is structured:
model Room {
id String @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
name String
clerkId String
type String
controller String
autoRevealCards Boolean
showAveraging Boolean
emailAddress String
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @updatedAt
roomMember RoomMember[]
}
model RoomMember{
id String @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
name String
emailAddress String
userId String
role Role
roomId String @db.Uuid
room Room @relation(fields: [roomId] , references: [id])
createdAt DateTime @default(dbgenerated("now()"))
updatedAt DateTime @updatedAt
}
I aim for the creator of a room to automatically become a member of that room, with each room having multiple members linked to its ID in the future.
What steps can I take to resolve this issue?