fix: complete display and channel group management
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
playbackStates,
|
||||
selections,
|
||||
selectionVariants,
|
||||
viewers,
|
||||
} from "../../schema/tables.js";
|
||||
import {
|
||||
type NewStoredSelection,
|
||||
@@ -176,8 +177,21 @@ export function createPlaybackStore(database: ModuleDatabase): SignagePlaybackSt
|
||||
});
|
||||
},
|
||||
|
||||
async deleteChannelGroup(groupId: string): Promise<void> {
|
||||
await database.delete(channelGroups).where(eq(channelGroups.id, groupId));
|
||||
async deleteChannelGroup(groupId: string, fallbackChannelId: string): Promise<void> {
|
||||
await database.transaction(async (transaction) => {
|
||||
const removedChannels = await transaction
|
||||
.select({ id: channels.id })
|
||||
.from(channels)
|
||||
.where(eq(channels.groupId, groupId));
|
||||
const removedChannelIds = removedChannels.map((channel) => channel.id);
|
||||
if (removedChannelIds.length > 0) {
|
||||
await transaction
|
||||
.update(viewers)
|
||||
.set({ channelId: fallbackChannelId, updatedAt: new Date() })
|
||||
.where(inArray(viewers.channelId, removedChannelIds));
|
||||
}
|
||||
await transaction.delete(channelGroups).where(eq(channelGroups.id, groupId));
|
||||
});
|
||||
},
|
||||
|
||||
async findChannelGroup(groupId: string): Promise<StoredChannelGroupDetail | undefined> {
|
||||
|
||||
Reference in New Issue
Block a user