feat(admin): implement delete functionality for Falukant regions and update UI components
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user