Peter Boomsma
09/26/2021, 10:30 AMUser
table, each User
can have multiple FollowedBy
records (a many to many relation to other Users).
I want to push a record (a notification) to each of the FollowedBy
users of the current user if a certain action has been done.
model User {
id Int @id @default(autoincrement())
email String @unique
name String
user_name String @unique
password String
movies Movie[]
notifications Notification[]
followedBy User[] @relation("UserFollows", references: [id])
following User[] @relation("UserFollows", references: [id])
}
model Notification {
id Int @id @default(autoincrement())
link String?
movie_id Int?
message String
icon String?
thumbnail String?
user User @relation(fields: [userId], references: [id])
userId Int
watched Boolean
}
So I need a create function on the notification:
createNotification: async (_, args, {req, res}) => {
const notification = await prisma.notification.create({
});
return notification;
},
What would be the best way to go through the list of FollowedBy
users for the current user? (current user id is available on the req req.userId
Ryan
09/27/2021, 7:20 AM