atualiza versão para 0.0.7; adiciona exclusão em cascata de locais de armazenamento e nova rota para verificar impacto

This commit is contained in:
Alexander Sabino
2026-05-09 16:51:34 +01:00
parent 2479154f63
commit 164fe7ecf1
5 changed files with 62 additions and 6 deletions
+13
View File
@@ -470,6 +470,19 @@ async function main() {
}
});
app.get('/api/storage-locations/:id/impact', authMiddleware, async (request, response) => {
try {
const impact = await store.storageLocationImpact(request.params.id);
response.json({
profileCount: impact.profiles.length,
profileNames: impact.profiles.map((p) => p.name),
backupCount: impact.backupCount,
});
} catch (error) {
response.status(500).json({ error: error.message });
}
});
app.delete('/api/storage-locations/:id', authMiddleware, async (request, response) => {
try {
await store.deleteStorageLocation(request.params.id);
+14
View File
@@ -58,6 +58,7 @@ class JsonStore {
backupScope: profileInput.backupScope || 'volumes',
volumeSelections: profileInput.volumeSelections || {},
backupDir: profileInput.backupDir,
storageLocationId: profileInput.storageLocationId || null,
updatedAt: now,
createdAt: profileInput.createdAt || now,
};
@@ -166,8 +167,21 @@ class JsonStore {
return location;
}
async storageLocationImpact(locationId) {
const data = await this.read();
const profiles = data.profiles.filter((p) => p.storageLocationId === locationId);
const profileIds = new Set(profiles.map((p) => p.id));
const backupCount = data.backups.filter((b) => profileIds.has(b.profileId)).length;
return { profiles, backupCount };
}
async deleteStorageLocation(locationId) {
await this.write((data) => {
const profileIds = new Set(
data.profiles.filter((p) => p.storageLocationId === locationId).map((p) => p.id)
);
data.backups = data.backups.filter((b) => !profileIds.has(b.profileId));
data.profiles = data.profiles.filter((p) => !profileIds.has(p.id));
data.storageLocations = data.storageLocations.filter((item) => item.id !== locationId);
return data;
});