|
1 | 1 | /* tslint:disable:no-use-before-declare */ |
2 | | -import { Meteor } from 'meteor/meteor' |
3 | | -import * as _ from 'underscore' |
4 | | -import { StudioRouteBehavior } from '@sofie-automation/corelib/dist/dataModel/Studio' |
5 | 2 | import { PackageInfo } from '../../coreSystem' |
6 | 3 | import { StudioContentAccess } from '../../security/studio' |
7 | 4 | import { shouldUpdateStudioBaselineInner } from '@sofie-automation/corelib/dist/studio/baseline' |
8 | | -import { logger } from '../../logging' |
9 | | -import { Blueprints, RundownPlaylists, Studios, Timeline } from '../../collections' |
| 5 | +import { Blueprints, RundownPlaylists, Timeline } from '../../collections' |
| 6 | +import { StudioJobs } from '@sofie-automation/corelib/dist/worker/studio' |
| 7 | +import { QueueStudioJob } from '../../worker/worker' |
10 | 8 |
|
11 | 9 | export namespace ServerPlayoutAPI { |
12 | 10 | export async function shouldUpdateStudioBaseline(access: StudioContentAccess): Promise<string | false> { |
@@ -38,32 +36,12 @@ export namespace ServerPlayoutAPI { |
38 | 36 | export async function switchRouteSet( |
39 | 37 | access: StudioContentAccess, |
40 | 38 | routeSetId: string, |
41 | | - state: boolean |
| 39 | + state: boolean | 'toggle' |
42 | 40 | ): Promise<void> { |
43 | | - logger.debug(`switchRouteSet "${access.studioId}" "${routeSetId}"=${state}`) |
44 | | - |
45 | | - const studio = access.studio |
46 | | - |
47 | | - if (studio.routeSets[routeSetId] === undefined) |
48 | | - throw new Meteor.Error(404, `RouteSet "${routeSetId}" not found!`) |
49 | | - const routeSet = studio.routeSets[routeSetId] |
50 | | - if (routeSet.behavior === StudioRouteBehavior.ACTIVATE_ONLY && state === false) |
51 | | - throw new Meteor.Error(400, `RouteSet "${routeSetId}" is ACTIVATE_ONLY`) |
52 | | - |
53 | | - const modification: Record<string, any> = {} |
54 | | - modification[`routeSets.${routeSetId}.active`] = state |
55 | | - |
56 | | - if (studio.routeSets[routeSetId].exclusivityGroup && state === true) { |
57 | | - _.each(studio.routeSets, (otherRouteSet, otherRouteSetId) => { |
58 | | - if (otherRouteSetId === routeSetId) return |
59 | | - if (otherRouteSet.exclusivityGroup === routeSet.exclusivityGroup) { |
60 | | - modification[`routeSets.${otherRouteSetId}.active`] = false |
61 | | - } |
62 | | - }) |
63 | | - } |
64 | | - |
65 | | - await Studios.updateAsync(studio._id, { |
66 | | - $set: modification, |
| 41 | + const queuedJob = await QueueStudioJob(StudioJobs.SwitchRouteSet, access.studioId, { |
| 42 | + routeSetId, |
| 43 | + state, |
67 | 44 | }) |
| 45 | + await queuedJob.complete |
68 | 46 | } |
69 | 47 | } |
0 commit comments