- Created new chat schema in the database. - Implemented chat room model with necessary fields (title, ownerId, roomTypeId, etc.). - Added room type model and rights model for chat functionality. - Developed API endpoints for managing chat rooms, including create, edit, and delete operations. - Integrated chat room management into the admin interface with a dedicated view and dialog for room creation/editing. - Added internationalization support for chat room management UI. - Implemented autocomplete for victim selection in underground activities. - Enhanced the underground view with new activity types and political target selection.
202 lines
6.9 KiB
JavaScript
202 lines
6.9 KiB
JavaScript
import AdminService from '../services/adminService.js';
|
|
import Joi from 'joi';
|
|
|
|
class AdminController {
|
|
// --- Chat Room Admin ---
|
|
constructor() {
|
|
this.getOpenInterests = this.getOpenInterests.bind(this);
|
|
this.changeInterest = this.changeInterest.bind(this);
|
|
this.deleteInterest = this.deleteInterest.bind(this);
|
|
this.changeTranslation = this.changeTranslation.bind(this);
|
|
this.getOpenContacts = this.getOpenContacts.bind(this);
|
|
this.answerContact = this.answerContact.bind(this);
|
|
this.searchUser = this.searchUser.bind(this);
|
|
this.getFalukantUserById = this.getFalukantUserById.bind(this);
|
|
this.changeFalukantUser = this.changeFalukantUser.bind(this);
|
|
this.getRoomTypes = this.getRoomTypes.bind(this);
|
|
this.getGenderRestrictions = this.getGenderRestrictions.bind(this);
|
|
this.getUserRights = this.getUserRights.bind(this);
|
|
this.getRooms = this.getRooms.bind(this);
|
|
this.createRoom = this.createRoom.bind(this);
|
|
this.deleteRoom = this.deleteRoom.bind(this);
|
|
}
|
|
|
|
async getOpenInterests(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const openInterests = await AdminService.getOpenInterests(userId);
|
|
res.status(200).json(openInterests);
|
|
} catch (error) {
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async changeInterest(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const { id: interestId, active, adult: adultOnly } = req.body;
|
|
await AdminService.changeInterest(userId, interestId, active, adultOnly);
|
|
const updatedInterests = await AdminService.getOpenInterests(userId);
|
|
res.status(200).json(updatedInterests);
|
|
} catch (error) {
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async deleteInterest(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const { id: interestId } = req.params;
|
|
await AdminService.deleteInterest(userId, interestId);
|
|
const updatedInterests = await AdminService.getOpenInterests(userId);
|
|
res.status(200).json(updatedInterests);
|
|
} catch (error) {
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async changeTranslation(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const { id: interestId, translations } = req.body;
|
|
await AdminService.changeTranslation(userId, interestId, translations);
|
|
const updatedInterests = await AdminService.getOpenInterests(userId);
|
|
res.status(200).json(updatedInterests);
|
|
} catch (error) {
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async getOpenContacts(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const openContacts = await AdminService.getOpenContacts(userId);
|
|
res.status(200).json(openContacts);
|
|
} catch (error) {
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async answerContact(req, res) {
|
|
try {
|
|
const schema = Joi.object({
|
|
id: Joi.number().integer().required(),
|
|
answer: Joi.string().min(1).required(),
|
|
});
|
|
|
|
const { error, value } = schema.validate(req.body);
|
|
|
|
if (error) {
|
|
return res.status(400).json({ error: error.details[0].message });
|
|
}
|
|
|
|
const { id, answer } = value;
|
|
|
|
await AdminService.answerContact(id, answer);
|
|
res.status(200).json({ status: 'ok' });
|
|
} catch (error) {
|
|
console.error('Error in answerContact:', error);
|
|
res.status(error.status || 500).json({ error: error.message || 'Internal Server Error' });
|
|
}
|
|
}
|
|
|
|
async searchUser(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const { userName, characterName } = req.body;
|
|
const response = await AdminService.getFalukantUser(userId, userName, characterName);
|
|
res.status(200).json(response);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async getFalukantUserById(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const { id: hashedId } = req.params;
|
|
const response = await AdminService.getFalukantUserById(userId, hashedId);
|
|
res.status(200).json(response);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async changeFalukantUser(req, res) {
|
|
try {
|
|
const { userid: userId } = req.headers;
|
|
const data = req.body;
|
|
const { id: falukantUserId, } = req.body;
|
|
const response = await AdminService.changeFalukantUser(userId, falukantUserId, data);
|
|
res.status(200).json(response);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(403).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async getRoomTypes(req, res) {
|
|
try {
|
|
const types = await AdminService.getRoomTypes();
|
|
res.status(200).json(types);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async getGenderRestrictions(req, res) {
|
|
try {
|
|
const restrictions = await AdminService.getGenderRestrictions();
|
|
res.status(200).json(restrictions);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async getUserRights(req, res) {
|
|
try {
|
|
const rights = await AdminService.getUserRights();
|
|
res.status(200).json(rights);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async getRooms(req, res) {
|
|
try {
|
|
const rooms = await AdminService.getRooms();
|
|
res.status(200).json(rooms);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async createRoom(req, res) {
|
|
try {
|
|
const room = await AdminService.createRoom(req.body);
|
|
res.status(201).json(room);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async deleteRoom(req, res) {
|
|
try {
|
|
await AdminService.deleteRoom(req.params.id);
|
|
res.sendStatus(204);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
}
|
|
|
|
export default AdminController;
|