feat(match3): Erweiterung der Match3-Admin-Funktionalitäten und -Modelle
- Implementierung neuer Endpunkte für die Verwaltung von Match3-Kampagnen, Levels, Objectives und Tile-Typen im Admin-Bereich. - Anpassung der Admin-Services zur Unterstützung von Benutzerberechtigungen und Fehlerbehandlung. - Einführung von neuen Modellen und Assoziationen für Match3-Levels und Tile-Typen in der Datenbank. - Verbesserung der Internationalisierung für Match3-spezifische Texte in Deutsch und Englisch. - Aktualisierung der Frontend-Routen und -Komponenten zur Verwaltung von Match3-Inhalten.
This commit is contained in:
@@ -292,22 +292,34 @@ class AdminService {
|
||||
}
|
||||
|
||||
// --- Chat Room Admin ---
|
||||
async getRoomTypes() {
|
||||
async getRoomTypes(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'chatrooms'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
return await RoomType.findAll();
|
||||
}
|
||||
|
||||
async getGenderRestrictions() {
|
||||
async getGenderRestrictions(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'chatrooms'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
// Find the UserParamType for gender restriction (e.g. description = 'gender')
|
||||
const genderType = await UserParamType.findOne({ where: { description: 'gender' } });
|
||||
if (!genderType) return [];
|
||||
return await UserParamValue.findAll({ where: { userParamTypeId: genderType.id } });
|
||||
}
|
||||
|
||||
async getUserRights() {
|
||||
async getUserRights(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'chatrooms'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
return await ChatRight.findAll();
|
||||
}
|
||||
|
||||
async getRooms() {
|
||||
async getRooms(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'chatrooms'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
// Only return necessary fields to the frontend
|
||||
return await Room.findAll({
|
||||
attributes: [
|
||||
@@ -329,20 +341,301 @@ class AdminService {
|
||||
});
|
||||
}
|
||||
|
||||
async updateRoom(id, data) {
|
||||
async updateRoom(userId, id, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'chatrooms'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const room = await Room.findByPk(id);
|
||||
if (!room) throw new Error('Room not found');
|
||||
await room.update(data);
|
||||
return room;
|
||||
}
|
||||
|
||||
async createRoom(data) {
|
||||
async createRoom(userId, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'chatrooms'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
return await Room.create(data);
|
||||
}
|
||||
|
||||
async deleteRoom(id) {
|
||||
async deleteRoom(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'chatrooms'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
return await Room.destroy({ where: { id } });
|
||||
}
|
||||
|
||||
// --- Match3 Admin Methods ---
|
||||
async getMatch3Campaigns(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Campaign = (await import('../models/match3/campaign.js')).default;
|
||||
return await Match3Campaign.findAll({
|
||||
include: [{
|
||||
model: (await import('../models/match3/level.js')).default,
|
||||
as: 'levels',
|
||||
include: [{
|
||||
model: (await import('../models/match3/objective.js')).default,
|
||||
as: 'objectives',
|
||||
required: false
|
||||
}],
|
||||
required: false
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
async getMatch3Campaign(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Campaign = (await import('../models/match3/campaign.js')).default;
|
||||
return await Match3Campaign.findByPk(id, {
|
||||
include: [{
|
||||
model: (await import('../models/match3/level.js')).default,
|
||||
as: 'levels',
|
||||
include: [{
|
||||
model: (await import('../models/match3/objective.js')).default,
|
||||
as: 'objectives',
|
||||
required: false
|
||||
}],
|
||||
required: false
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
async createMatch3Campaign(userId, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Campaign = (await import('../models/match3/campaign.js')).default;
|
||||
return await Match3Campaign.create(data);
|
||||
}
|
||||
|
||||
async updateMatch3Campaign(userId, id, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Campaign = (await import('../models/match3/campaign.js')).default;
|
||||
const campaign = await Match3Campaign.findByPk(id);
|
||||
if (!campaign) throw new Error('Campaign not found');
|
||||
await campaign.update(data);
|
||||
return campaign;
|
||||
}
|
||||
|
||||
async deleteMatch3Campaign(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Campaign = (await import('../models/match3/campaign.js')).default;
|
||||
return await Match3Campaign.destroy({ where: { id } });
|
||||
}
|
||||
|
||||
async getMatch3Levels(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Level = (await import('../models/match3/level.js')).default;
|
||||
return await Match3Level.findAll({
|
||||
include: [
|
||||
{
|
||||
model: (await import('../models/match3/campaign.js')).default,
|
||||
as: 'campaign',
|
||||
required: false
|
||||
},
|
||||
{
|
||||
model: (await import('../models/match3/objective.js')).default,
|
||||
as: 'objectives',
|
||||
required: false
|
||||
}
|
||||
],
|
||||
order: [['order', 'ASC']]
|
||||
});
|
||||
}
|
||||
|
||||
async getMatch3Level(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Level = (await import('../models/match3/level.js')).default;
|
||||
return await Match3Level.findByPk(id, {
|
||||
include: [
|
||||
{
|
||||
model: (await import('../models/match3/campaign.js')).default,
|
||||
as: 'campaign',
|
||||
required: false
|
||||
},
|
||||
{
|
||||
model: (await import('../models/match3/objective.js')).default,
|
||||
as: 'objectives',
|
||||
required: false
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async createMatch3Level(userId, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Level = (await import('../models/match3/level.js')).default;
|
||||
|
||||
// Wenn keine campaignId gesetzt ist, setze eine Standard-Campaign-ID
|
||||
if (!data.campaignId) {
|
||||
// Versuche eine Standard-Campaign zu finden oder erstelle eine
|
||||
const Match3Campaign = (await import('../models/match3/campaign.js')).default;
|
||||
let defaultCampaign = await Match3Campaign.findOne({ where: { isActive: true } });
|
||||
|
||||
if (!defaultCampaign) {
|
||||
// Erstelle eine Standard-Campaign falls keine existiert
|
||||
defaultCampaign = await Match3Campaign.create({
|
||||
name: 'Standard Campaign',
|
||||
description: 'Standard Campaign für Match3 Levels',
|
||||
isActive: true,
|
||||
order: 1
|
||||
});
|
||||
}
|
||||
|
||||
data.campaignId = defaultCampaign.id;
|
||||
}
|
||||
|
||||
// Validiere, dass campaignId gesetzt ist
|
||||
if (!data.campaignId) {
|
||||
throw new Error('CampaignId ist erforderlich');
|
||||
}
|
||||
|
||||
return await Match3Level.create(data);
|
||||
}
|
||||
|
||||
async updateMatch3Level(userId, id, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Level = (await import('../models/match3/level.js')).default;
|
||||
const level = await Match3Level.findByPk(id);
|
||||
if (!level) throw new Error('Level not found');
|
||||
await level.update(data);
|
||||
return level;
|
||||
}
|
||||
|
||||
async deleteMatch3Level(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Level = (await import('../models/match3/level.js')).default;
|
||||
return await Match3Level.destroy({ where: { id } });
|
||||
}
|
||||
|
||||
// Match3 Objectives
|
||||
async getMatch3Objectives(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Objective = (await import('../models/match3/objective.js')).default;
|
||||
return await Match3Objective.findAll({
|
||||
include: [{
|
||||
model: (await import('../models/match3/level.js')).default,
|
||||
as: 'level',
|
||||
required: false
|
||||
}],
|
||||
order: [['order', 'ASC']]
|
||||
});
|
||||
}
|
||||
|
||||
async getMatch3Objective(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Objective = (await import('../models/match3/objective.js')).default;
|
||||
return await Match3Objective.findByPk(id, {
|
||||
include: [{
|
||||
model: (await import('../models/match3/level.js')).default,
|
||||
as: 'level',
|
||||
required: false
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
async createMatch3Objective(userId, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Objective = (await import('../models/match3/objective.js')).default;
|
||||
|
||||
// Validiere, dass levelId gesetzt ist
|
||||
if (!data.levelId) {
|
||||
throw new Error('LevelId ist erforderlich');
|
||||
}
|
||||
|
||||
// Validiere, dass target eine ganze Zahl ist
|
||||
if (data.target && !Number.isInteger(Number(data.target))) {
|
||||
throw new Error('Target muss eine ganze Zahl sein');
|
||||
}
|
||||
|
||||
return await Match3Objective.create(data);
|
||||
}
|
||||
|
||||
async updateMatch3Objective(userId, id, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Objective = (await import('../models/match3/objective.js')).default;
|
||||
const objective = await Match3Objective.findByPk(id);
|
||||
if (!objective) throw new Error('Objective not found');
|
||||
|
||||
// Validiere, dass target eine ganze Zahl ist
|
||||
if (data.target && !Number.isInteger(Number(data.target))) {
|
||||
throw new Error('Target muss eine ganze Zahl sein');
|
||||
}
|
||||
|
||||
await objective.update(data);
|
||||
return objective;
|
||||
}
|
||||
|
||||
async deleteMatch3Objective(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3Objective = (await import('../models/match3/objective.js')).default;
|
||||
return await Match3Objective.destroy({ where: { id } });
|
||||
}
|
||||
|
||||
async getMatch3TileTypes(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3TileType = (await import('../models/match3/tileType.js')).default;
|
||||
return await Match3TileType.findAll({
|
||||
order: [['name', 'ASC']]
|
||||
});
|
||||
}
|
||||
|
||||
async createMatch3TileType(userId, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3TileType = (await import('../models/match3/tileType.js')).default;
|
||||
return await Match3TileType.create(data);
|
||||
}
|
||||
|
||||
async updateMatch3TileType(userId, id, data) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3TileType = (await import('../models/match3/tileType.js')).default;
|
||||
const tileType = await Match3TileType.findByPk(id);
|
||||
if (!tileType) throw new Error('Tile type not found');
|
||||
await tileType.update(data);
|
||||
return tileType;
|
||||
}
|
||||
|
||||
async deleteMatch3TileType(userId, id) {
|
||||
if (!(await this.hasUserAccess(userId, 'match3'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
const Match3TileType = (await import('../models/match3/tileType.js')).default;
|
||||
return await Match3TileType.destroy({ where: { id } });
|
||||
}
|
||||
}
|
||||
|
||||
export default new AdminService();
|
||||
Reference in New Issue
Block a user