Add functionality for managing user-owned chat rooms: Implement getOwnRooms and deleteOwnRoom methods in ChatController and ChatService, add corresponding API routes in chatRouter, and enhance MultiChatDialog for displaying and deleting owned rooms with localized messages. Update i18n files for new features.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import amqp from 'amqplib/callback_api.js';
|
||||
import User from '../models/community/user.js';
|
||||
import Room from '../models/chat/room.js';
|
||||
|
||||
const RABBITMQ_URL = 'amqp://localhost';
|
||||
const QUEUE = 'oneToOne_messages';
|
||||
@@ -169,6 +171,45 @@ class ChatService {
|
||||
roomTypes: interests.map((i) => ({ id: i.id, name: i.name }))
|
||||
};
|
||||
}
|
||||
|
||||
async getOwnRooms(hashedUserId) {
|
||||
const user = await User.findOne({
|
||||
where: { hashedId: hashedUserId },
|
||||
attributes: ['id']
|
||||
});
|
||||
if (!user) {
|
||||
throw new Error('user_not_found');
|
||||
}
|
||||
|
||||
return Room.findAll({
|
||||
where: { ownerId: user.id },
|
||||
attributes: ['id', 'title', 'isPublic', 'roomTypeId', 'ownerId'],
|
||||
order: [['title', 'ASC']]
|
||||
});
|
||||
}
|
||||
|
||||
async deleteOwnRoom(hashedUserId, roomId) {
|
||||
const user = await User.findOne({
|
||||
where: { hashedId: hashedUserId },
|
||||
attributes: ['id']
|
||||
});
|
||||
if (!user) {
|
||||
throw new Error('user_not_found');
|
||||
}
|
||||
|
||||
const deleted = await Room.destroy({
|
||||
where: {
|
||||
id: roomId,
|
||||
ownerId: user.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!deleted) {
|
||||
throw new Error('room_not_found_or_not_owner');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export default new ChatService();
|
||||
|
||||
Reference in New Issue
Block a user