Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brainbox-backend",
"version": "1.7.3",
"version": "1.7.5",
"description": "Backend for BrainBox",
"author": "lzaycoe (Lazy Code)",
"private": true,
Expand Down
19 changes: 15 additions & 4 deletions src/domains/chats/chats.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,21 @@ export class ChatsGateway implements OnGatewayConnection, OnGatewayDisconnect {
@MessageBody() payload: string,
@ConnectedSocket() client: Socket,
) {
const parsedPayload = JSON.parse(payload);
const { id } = parsedPayload;
const messages = await this.chatsService.getMessages(+id);
client.emit('Messages', messages);
try {
const parsedPayload = JSON.parse(payload);
const conversationId = Number(parsedPayload.id);

if (isNaN(conversationId)) {
console.error('Invalid conversationId:', parsedPayload.id);
return client.emit('error', 'Invalid conversationId');
}

const messages = await this.chatsService.getMessages(conversationId);
client.emit('Messages', messages);
} catch (error) {
console.error('Error in handleGetMessages:', error);
client.emit('error', 'Failed to get messages');
}
}

@SubscribeMessage('updateMessageStatus')
Expand Down
3 changes: 2 additions & 1 deletion src/domains/chats/chats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ChatsService {
}

async getUserConversations(userId: number) {
const conversations = this.prismaService.conversation.findMany({
const conversations = await this.prismaService.conversation.findMany({
where: {
OR: [{ userAId: userId }, { userBId: userId }],
},
Expand All @@ -56,6 +56,7 @@ export class ChatsService {
}

this.logger.log('Conversations found for user');
this.logger.debug('conversations:', conversations);

return conversations;
}
Expand Down
5 changes: 5 additions & 0 deletions src/domains/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import { UsersService } from '@/users/users.service';
export class UsersController {
constructor(private readonly usersService: UsersService) {}

@Get()
async findAll() {
return this.usersService.findAll();
}

@Get('/:valueId')
async findOne(@Param('valueId') valueId: string) {
return this.usersService.findOne(valueId);
Expand Down
17 changes: 17 additions & 0 deletions src/domains/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ export class UsersService {
private readonly clerkClient: ClerkClient,
) {}

async findAll() {
const users = await this.prismaService.user.findMany();

this.logger.debug('Users found:', users);

const detailedUsers = await Promise.all(
users.map(async (user) => {
const clerkUser = await this.clerkClient.users.getUser(user.clerkId);
return { ...user, clerkUser };
}),
);

this.logger.debug('Detailed users:', detailedUsers);

return detailedUsers;
}

async findOne(valueId: string): Promise<any> {
try {
let user;
Expand Down