So , i am trying to create the community page which is created by the admin , and users can join and chat there but creation of community is successful but the joining is not happening, i am using the prisma and mongodb for that
the model is following
model Community {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
lastmessageAt DateTime @default(now())
name String @unique
description String?
isCommunity Boolean?
messagesIds String? @db.ObjectId
messages Message[]
userIds String[] @db.ObjectId
users User[] @relation(fields: [userIds], references: [id])
}
model Message {
id String @id @default(auto()) @map("_id") @db.ObjectId
content String
createdAt DateTime @default(now())
seenIds String[] @db.ObjectId
seen User[] @relation("Seen", fields: [seenIds], references: [id])
communityId String @db.ObjectId
community Community @relation(fields: [communityId], references: [id], onDelete: Cascade)
senderId String @db.ObjectId
sender User @relation(fields: [senderId], references: [id], onDelete: Cascade)
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String? @unique
name String?
phone String?
hashedPassword String?
role String?
posts Modules[]
userInfo UserInfo?
accounts Account[]
communityIds String[] @db.ObjectId
communities Community[] @relation(fields: [communityIds], references: [id])
seenMessageIds String[] @db.ObjectId
seenMessages Message[] @relation("Seen", fields: [seenMessageIds], references: [id])
messages Message[]
}
this is my schema for that
also creation of communities is successfull but joining is not happening by the user.
{
"communities": [
{
"id": "66841e94362a692ec1d5431b",
"createdAt": "2024-07-02T15:36:52.271Z",
"lastmessageAt": "2024-07-02T15:36:52.271Z",
"name": "web dev comm",
"description": "deepverse the web dev community",
"isCommunity": null,
"messagesIds": null,
"userIds": []
}
]
}
To create the api route to join the users in that community and to leave from that community
the folder structure i am using is app/api/community/[communityId]/join/route.ts
and for leave is app/api/community/[communityId]/leave/route.ts
Arnav Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.