Skip to content

Commit

Permalink
feat: message chat notifications done
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlbDR committed Apr 3, 2024
1 parent 91c6229 commit 0c716f8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:
- Added the required column `isReadAt` to the `ChatMessage` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "ChatMessage" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "isRead" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "isReadAt" TIMESTAMP(3) NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ChatMessage" ALTER COLUMN "isReadAt" DROP NOT NULL;
3 changes: 3 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ model ChatMessage {
username String
AdoptionChat AdoptionChat @relation(fields: [adoptionChatSlug], references: [slug], onDelete: Cascade)
adoptionChatSlug String
createdAt DateTime @default(now())
isRead Boolean @default(false)
isReadAt DateTime?
}

enum user_roles {
Expand Down
12 changes: 12 additions & 0 deletions src/presentation/chats/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export class ChatService {
},
});

const chatNotificationExist = await prisma.notification.findFirst({
where: {
link: `/private/chat/${room}`,
isRead: false,
},
});

if (chatNotificationExist) return;

const notification = await prisma.notification.create({
data: {
type: 'new-chat',
Expand Down Expand Up @@ -94,6 +103,9 @@ export class ChatService {
where: {
adoptionChatSlug: chat,
},
orderBy: {
createdAt: 'asc',
},
});

return history;
Expand Down

0 comments on commit 0c716f8

Please sign in to comment.