diff --git a/main.wasp b/main.wasp index f476a1d..f63183d 100644 --- a/main.wasp +++ b/main.wasp @@ -91,6 +91,7 @@ entity User {=psl externalAuthAssociations SocialLogin[] chats Chat[] + conversations Conversation[] psl=} // relatedObject RelatedObject[] - add in line 86 entity SocialLogin {=psl @@ -130,6 +131,8 @@ entity Conversation {=psl updatedAt DateTime @updatedAt chat Chat? @relation(fields: [chatId], references: [id]) chatId Int? + user User? @relation(fields: [userId], references: [id]) + userId Int? psl=} diff --git a/migrations/20231116051633_add_user_id_to_conversation_model/migration.sql b/migrations/20231116051633_add_user_id_to_conversation_model/migration.sql new file mode 100644 index 0000000..79804a1 --- /dev/null +++ b/migrations/20231116051633_add_user_id_to_conversation_model/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "Conversation" ADD COLUMN "userId" INTEGER; + +-- AddForeignKey +ALTER TABLE "Conversation" ADD CONSTRAINT "Conversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/src/server/actions.ts b/src/server/actions.ts index 50a8b9a..bc38b86 100644 --- a/src/server/actions.ts +++ b/src/server/actions.ts @@ -180,6 +180,7 @@ export const createChat: CreateChat = async (_args, context) }, ], chat: { connect: { id: chat.id } }, + user: { connect: { id: context.user.id } }, }, }); } diff --git a/src/server/queries.ts b/src/server/queries.ts index be7bce8..4aa674c 100644 --- a/src/server/queries.ts +++ b/src/server/queries.ts @@ -45,7 +45,7 @@ export const getConversations: GetConversations