feat(admin): implement delete functionality for Falukant regions and update UI components

This commit is contained in:
Torsten Schulz (local)
2026-08-14 09:54:09 +02:00
parent 3f80cc40ff
commit e6f6fc984a
7 changed files with 522 additions and 68 deletions

View File

@@ -934,6 +934,45 @@ class AdminService {
return region;
}
async deleteFalukantRegion(userId, regionId) {
if (!(await this.hasUserAccess(userId, 'falukantusers'))) {
throw new Error('noaccess');
}
const region = await RegionData.findByPk(regionId);
if (!region) {
throw new Error('regionNotFound');
}
const [childCount, distanceCount, userCount, characterCount, weatherCount] = await Promise.all([
RegionData.count({ where: { parentId: region.id } }),
RegionDistance.count({
where: {
[Op.or]: [
{ sourceRegionId: region.id },
{ targetRegionId: region.id },
],
},
}),
FalukantUser.count({ where: { mainBranchRegionId: region.id } }),
FalukantCharacter.count({ where: { regionId: region.id } }),
Weather.count({ where: { regionId: region.id } }),
]);
if (childCount > 0) {
throw new Error('regionHasChildren');
}
if (distanceCount > 0) {
throw new Error('regionHasDistances');
}
if (userCount > 0 || characterCount > 0 || weatherCount > 0) {
throw new Error('regionInUse');
}
await region.destroy();
return { success: true };
}
async getRegionDistances(userId) {
if (!(await this.hasUserAccess(userId, 'falukantusers'))) {
throw new Error('noaccess');