From deaed41f08573f22ca40d7ac53f4b49af766048c Mon Sep 17 00:00:00 2001 From: CapoMK25 Date: Fri, 30 Jan 2026 11:28:43 +0200 Subject: [PATCH 1/4] Fixed tests to accomodate this feature --- src/__tests__/chat/chatService/addReaction.test.ts | 9 +++++++-- src/__tests__/chat/data/builder/ReactionDtoBuilder.ts | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/__tests__/chat/chatService/addReaction.test.ts b/src/__tests__/chat/chatService/addReaction.test.ts index dfc18f0b9..d227fd72f 100644 --- a/src/__tests__/chat/chatService/addReaction.test.ts +++ b/src/__tests__/chat/chatService/addReaction.test.ts @@ -7,6 +7,7 @@ describe('ChatService.addReaction() test suite', () => { let chatService: ChatService; const chatMessageBuilder = ChatBuilderFactory.getBuilder('ChatMessage'); const chatModel = ChatModule.getChatModel(); + const mockSenderId = '60f7c2d9a2d3c7b7e56d01df'; const senderId = new ObjectId(); const reactPlayerName = 'ReactMan420'; @@ -27,11 +28,12 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '👍', + mockSenderId ); expect(err).toBeNull(); expect(updated.reactions).toEqual([ - { playerName: reactPlayerName, emoji: '👍' }, + { playerName: reactPlayerName, emoji: '👍', sender_id: mockSenderId }, ]); }); @@ -42,11 +44,12 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '😂', + mockSenderId ); expect(err).toBeNull(); expect(updated.reactions).toEqual([ - { playerName: reactPlayerName, emoji: '😂' }, + { playerName: reactPlayerName, emoji: '😂', sender_id: mockSenderId }, ]); }); @@ -57,6 +60,7 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '', + mockSenderId ); expect(err).toBeNull(); @@ -69,6 +73,7 @@ describe('ChatService.addReaction() test suite', () => { fakeId, 'NoPlayer', '🔥', + mockSenderId ); expect(updated).toBeNull(); diff --git a/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts b/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts index a3fb92007..b1c9e656e 100644 --- a/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts +++ b/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts @@ -5,6 +5,7 @@ export default class ReactionDtoBuilder implements IDataBuilder { private readonly base: ReactionDto = { playerName: 'TestPlayer420', emoji: '👍', + sender_id: '60f7c2d9a2d3c7b7e56d01df' }; build(): ReactionDto { From 889dfeaaa8910689309a7f88d6bfb7db57546563 Mon Sep 17 00:00:00 2001 From: CapoMK25 Date: Fri, 30 Jan 2026 11:30:22 +0200 Subject: [PATCH 2/4] Linter changes... --- src/__tests__/chat/chatService/addReaction.test.ts | 8 ++++---- src/__tests__/chat/data/builder/ReactionDtoBuilder.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/__tests__/chat/chatService/addReaction.test.ts b/src/__tests__/chat/chatService/addReaction.test.ts index d227fd72f..c9ce919f5 100644 --- a/src/__tests__/chat/chatService/addReaction.test.ts +++ b/src/__tests__/chat/chatService/addReaction.test.ts @@ -28,7 +28,7 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '👍', - mockSenderId + mockSenderId, ); expect(err).toBeNull(); @@ -44,7 +44,7 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '😂', - mockSenderId + mockSenderId, ); expect(err).toBeNull(); @@ -60,7 +60,7 @@ describe('ChatService.addReaction() test suite', () => { chat._id.toString(), reactPlayerName, '', - mockSenderId + mockSenderId, ); expect(err).toBeNull(); @@ -73,7 +73,7 @@ describe('ChatService.addReaction() test suite', () => { fakeId, 'NoPlayer', '🔥', - mockSenderId + mockSenderId, ); expect(updated).toBeNull(); diff --git a/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts b/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts index b1c9e656e..d35b3f0fa 100644 --- a/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts +++ b/src/__tests__/chat/data/builder/ReactionDtoBuilder.ts @@ -5,7 +5,7 @@ export default class ReactionDtoBuilder implements IDataBuilder { private readonly base: ReactionDto = { playerName: 'TestPlayer420', emoji: '👍', - sender_id: '60f7c2d9a2d3c7b7e56d01df' + sender_id: '60f7c2d9a2d3c7b7e56d01df', }; build(): ReactionDto { From f231a7519f705fb804975020d3f8994d2fef7fb3 Mon Sep 17 00:00:00 2001 From: CapoMK25 Date: Fri, 30 Jan 2026 11:31:33 +0200 Subject: [PATCH 3/4] Feature for sender id implemented --- src/chat/dto/reaction.dto.ts | 7 +++++ src/chat/schema/reaction.schema.ts | 3 +++ src/chat/service/baseChat.service.ts | 1 + src/chat/service/chat.service.ts | 40 ++++------------------------ 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/chat/dto/reaction.dto.ts b/src/chat/dto/reaction.dto.ts index 26e7b234a..3ca58b450 100644 --- a/src/chat/dto/reaction.dto.ts +++ b/src/chat/dto/reaction.dto.ts @@ -17,4 +17,11 @@ export class ReactionDto { */ @Expose() emoji: string; + + /** + * Player id of the user + * @example "123456789" + */ + @Expose() + sender_id: string; } diff --git a/src/chat/schema/reaction.schema.ts b/src/chat/schema/reaction.schema.ts index 1e7cc5387..fa2e1edf4 100644 --- a/src/chat/schema/reaction.schema.ts +++ b/src/chat/schema/reaction.schema.ts @@ -6,4 +6,7 @@ export class Reaction { @Prop({ type: String, required: true }) emoji: string; + + @Prop({ type: String, required: true }) + sender_id: string; } diff --git a/src/chat/service/baseChat.service.ts b/src/chat/service/baseChat.service.ts index 339359103..987196113 100644 --- a/src/chat/service/baseChat.service.ts +++ b/src/chat/service/baseChat.service.ts @@ -113,6 +113,7 @@ export abstract class BaseChatService { reaction.message_id, client.user.name, reaction.emoji, + client.user.playerId, ); if (error) { diff --git a/src/chat/service/chat.service.ts b/src/chat/service/chat.service.ts index 74a7d47d2..14d9f1370 100644 --- a/src/chat/service/chat.service.ts +++ b/src/chat/service/chat.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; -import {} from '../../common/base/decorator/AddBasicService.decorator'; import { ChatMessage } from '../schema/chatMessage.schema'; import { Model } from 'mongoose'; import BasicService from '../../common/service/basicService/BasicService'; @@ -16,6 +15,7 @@ import { SEReason } from '../../common/service/basicService/SEReason'; @Injectable() export class ChatService { + private readonly basicService: BasicService; public constructor( @InjectModel(ChatMessage.name) public readonly model: Model, @@ -23,14 +23,6 @@ export class ChatService { this.basicService = new BasicService(model); } - private readonly basicService: BasicService; - - /** - * Creates a message in database. - * - * @param message - Message data to create. - * @returns Created message. - */ async createChatMessage(message: CreateChatMessageDto) { return this.basicService.createOne( message, @@ -38,17 +30,19 @@ export class ChatService { } /** - * Adds an reaction to chat message. + * Adds a reaction to chat message. * * @param messageId - ID of the message reaction is to. * @param playerName - Name of the player who reacted. * @param emoji - String representation of the emoji. + * @param sender_id - Unique ID of the player reacting. * @returns Message with added reaction. */ async addReaction( messageId: string, playerName: string, emoji: string, + sender_id: string, ): Promise> { const [message, error] = await this.basicService.readOneById(messageId); @@ -59,7 +53,7 @@ export class ChatService { (r) => r.playerName !== playerName, ); - if (emoji) message.reactions.push({ playerName, emoji }); + if (emoji) message.reactions.push({ playerName, emoji, sender_id }); const [, updateError] = await this.basicService.updateOneById( message._id, @@ -71,12 +65,6 @@ export class ChatService { return [message, null]; } - /** - * Retrieves messages from database. - * - * @param options - Database query options. - * @returns An array of chat messages. - */ async getMessages( options?: TIServiceReadManyOptions, ): Promise> { @@ -87,15 +75,6 @@ export class ChatService { return await this.basicService.readMany(opts); } - /** - * Updates a ChatMessage by its _id in DB. The _id field is read-only and must be found from the parameter - * - * @param chat - The data needs to be updated of the ChatMessage. - * @returns _true_ if ChatMessage was updated successfully, _false_ if nothing was updated for the ChatMessage, - * or a ServiceError: - * - NOT_FOUND if the ChatMessage was not found - * - REQUIRED if _id is not provided - */ async updateOneById( chat: Partial, ): Promise<[boolean | null, ServiceError[] | null]> { @@ -122,15 +101,6 @@ export class ChatService { return [isSuccess, errors]; } - /** - * Deletes the chatmessage. - * - * @param chatId - The ID of the chatmessage to delete. - * @returns _true_ if ChatMessage was deleted successfully, _false_ if nothing was deleted - * or a ServiceError: - * - NOT_FOUND if the ChatMessage was not found - * - REQUIRED if _id is not provided - */ async deleteChatMessageById(chatId: string): Promise> { return await this.basicService.deleteOneById(chatId); } From e3d66fe0c7b8918e9e1c989e42c1a23358099ae4 Mon Sep 17 00:00:00 2001 From: CapoMK25 Date: Tue, 3 Feb 2026 09:09:31 +0200 Subject: [PATCH 4/4] Readded documentation that went missing for some reason --- src/chat/service/chat.service.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/chat/service/chat.service.ts b/src/chat/service/chat.service.ts index 14d9f1370..80b832bc9 100644 --- a/src/chat/service/chat.service.ts +++ b/src/chat/service/chat.service.ts @@ -23,6 +23,12 @@ export class ChatService { this.basicService = new BasicService(model); } + /** + * Creates a message in the database. + * + * @param message - Message data to create. + * @returns Created message. + */ async createChatMessage(message: CreateChatMessageDto) { return this.basicService.createOne( message, @@ -30,7 +36,7 @@ export class ChatService { } /** - * Adds a reaction to chat message. + * Adds a reaction to the chat message. * * @param messageId - ID of the message reaction is to. * @param playerName - Name of the player who reacted. @@ -65,6 +71,12 @@ export class ChatService { return [message, null]; } + /** + * Retrieves messages from the database. + * + * @param options - Database query options. + * @returns An array of chat messages. + */ async getMessages( options?: TIServiceReadManyOptions, ): Promise> { @@ -75,6 +87,15 @@ export class ChatService { return await this.basicService.readMany(opts); } + /** + * Updates a ChatMessage by its _id in the DB. The _id field is read-only and must be found from the parameter + * + * @param chat - The data needs to be updated of the ChatMessage. + * @returns _true_ if ChatMessage was updated successfully, _false_ if nothing was updated for the ChatMessage, + * or a ServiceError: + * - NOT_FOUND if the ChatMessage was not found + * - REQUIRED if _id is not provided + */ async updateOneById( chat: Partial, ): Promise<[boolean | null, ServiceError[] | null]> { @@ -101,6 +122,15 @@ export class ChatService { return [isSuccess, errors]; } + /** + * Deletes the chatmessage. + * + * @param chatId - The ID of the chatmessage to delete. + * @returns _true_ if ChatMessage was deleted successfully, _false_ if nothing was deleted + * or a ServiceError: + * - NOT_FOUND if the ChatMessage was not found + * - REQUIRED if _id is not provided + */ async deleteChatMessageById(chatId: string): Promise> { return await this.basicService.deleteOneById(chatId); }