fix: complete display and channel group management
This commit is contained in:
@@ -91,11 +91,20 @@ export function registerPlaybackRoutes(
|
||||
const groupId = requireUuidParam(context, "groupId");
|
||||
const store = createSignageStore(context.services.database);
|
||||
const groups = await store.listChannelGroups();
|
||||
const group = groups.find((candidate) => candidate.group.id === groupId);
|
||||
if (!group) {
|
||||
throw new SignageError("SIGNAGE_NOT_FOUND");
|
||||
}
|
||||
if (groups.length <= 1) {
|
||||
// An installation always has somewhere for a viewer to land.
|
||||
throw new SignageError("SIGNAGE_CONFLICT", { reason: "last-group" });
|
||||
}
|
||||
await store.deleteChannelGroup(groupId);
|
||||
const fallbackGroup = groups.find((candidate) => candidate.group.id !== groupId);
|
||||
const fallbackChannel = fallbackGroup?.channels.find((channel) => channel.isDefault);
|
||||
if (!fallbackChannel) {
|
||||
throw new SignageError("SIGNAGE_CONFLICT", { reason: "no-fallback-channel" });
|
||||
}
|
||||
await store.deleteChannelGroup(groupId, fallbackChannel.id);
|
||||
return new Response(null, { status: 204 });
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user