-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from COS301-SE-2023/api_chat_feature_dev
Api chat feature dev
- Loading branch information
Showing
26 changed files
with
220 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
libs/api/event/data-access/src/interfaces/chat-message.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
export interface IChatMessage { | ||
text: string | undefined | null, | ||
timestamp: Date | undefined | null, | ||
user: { | ||
id: string | undefined | null, | ||
fullname: string | undefined | null, | ||
profilePic: string | undefined | null, | ||
role: string | undefined | null, | ||
}, | ||
}; | ||
|
||
export class ChatMessage { | ||
text: string | undefined | null; | ||
timestamp: Date | undefined | null; | ||
user: { | ||
id: string | undefined | null; | ||
fullname: string | undefined | null; | ||
profilePic: string | undefined | null; | ||
role: string | undefined | null; | ||
} | undefined | null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './position.interface'; | ||
export * from './position.interface'; | ||
export * from './chat-message.interface'; |
24 changes: 24 additions & 0 deletions
24
libs/api/event/feature/src/commands/add-event-chat-message.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AddChatMessageCommand } from '@event-participation-trends/api/event/util'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { EventRepository } from '@event-participation-trends/api/event/data-access'; | ||
import { Types } from 'mongoose'; | ||
|
||
@CommandHandler(AddChatMessageCommand) | ||
export class AddChatMessageHandler implements ICommandHandler<AddChatMessageCommand, void> { | ||
constructor( | ||
private readonly eventRepository: EventRepository, | ||
|
||
) {} | ||
|
||
async execute(command: AddChatMessageCommand) { | ||
console.log(`${AddChatMessageHandler.name}`); | ||
|
||
const request = command.request; | ||
|
||
if(request.messagePacket) | ||
this.eventRepository.createChatMessage( | ||
<Types.ObjectId> <unknown> request.eventId, | ||
request.messagePacket | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
libs/api/event/feature/src/queries/get-event-chat-messages.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { EventRepository } from '@event-participation-trends/api/event/data-access'; | ||
import { ChatMessage, GetEventChatMessagesQuery, IGetEventChatMessagesResponse } from '@event-participation-trends/api/event/util'; | ||
import { QueryHandler, IQueryHandler } from '@nestjs/cqrs'; | ||
import { Types } from 'mongoose'; | ||
|
||
@QueryHandler(GetEventChatMessagesQuery) | ||
export class GetEventChatMessagesHandler implements IQueryHandler<GetEventChatMessagesQuery, IGetEventChatMessagesResponse> { | ||
constructor( | ||
private readonly eventRepository: EventRepository, | ||
) {} | ||
|
||
async execute(query: GetEventChatMessagesQuery) { | ||
console.log(`${GetEventChatMessagesHandler.name}`); | ||
const request = query.request; | ||
const eventIdObj = <Types.ObjectId> <unknown> request.eventId; | ||
|
||
const chats = new Array<ChatMessage>(); | ||
const chatDocs = await this.eventRepository.getEventChatMessages(eventIdObj); | ||
chatDocs[0]?.eventChats?.forEach(doc=>{ | ||
chats.push({ | ||
text: doc.text, | ||
timestamp: doc.timestamp, | ||
user: doc.user, | ||
}) | ||
}) | ||
|
||
return {messages :<ChatMessage[]><unknown> chats}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
libs/api/event/util/src/commands/add-event-chat-message.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IAddChatMessageRequest} from '../requests'; | ||
|
||
export class AddChatMessageCommand { | ||
constructor(public readonly request: IAddChatMessageRequest) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
libs/api/event/util/src/interfaces/chat-message.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
export interface IChatMessage { | ||
text: string | undefined | null, | ||
timestamp: Date | undefined | null, | ||
user: { | ||
id: string | undefined | null, | ||
fullname: string | undefined | null, | ||
profilePic: string | undefined | null, | ||
role: string | undefined | null, | ||
}, | ||
}; | ||
|
||
export class ChatMessage { | ||
text: string | undefined | null; | ||
timestamp: Date | undefined | null; | ||
user: { | ||
id: string | undefined | null; | ||
fullname: string | undefined | null; | ||
profilePic: string | undefined | null; | ||
role: string | undefined | null; | ||
} | undefined | null; | ||
}; |
Oops, something went wrong.