Skip to content

Commit

Permalink
Merge branch 'contribute/EAV-33/buckets-api-http' into contribute/EAV…
Browse files Browse the repository at this point in the history
…-33/buckets-api-http-release51
  • Loading branch information
ianshade committed Dec 20, 2023
2 parents 4f468c6 + 6c2a1bf commit a3cf788
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion meteor/server/api/rest/v1/buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class BucketsServerAPI implements BucketsRestAPI {
_event: string,
bucketId: BucketId
): Promise<ClientAPI.ClientResponse<APIBucketComplete>> {
const bucket = await Buckets.findOneAsync({}, { projection: { _id: 1, name: 1, studioId: 1 } })
const bucket = await Buckets.findOneAsync(bucketId, { projection: { _id: 1, name: 1, studioId: 1 } })
if (!bucket) {
return ClientAPI.responseError(
UserError.from(new Error(`Bucket ${bucketId} not found`), UserErrorMessage.BucketNotFound),
Expand Down
11 changes: 8 additions & 3 deletions meteor/server/api/rest/v1/playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,26 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
externalId: string,
triggerMode?: string | null
): Promise<ClientAPI.ClientResponse<object>> {
const bucketPromise = Buckets.findOneAsync({}, { projection: { _id: 1, name: 1, studioId: 1 } })
const bucketPromise = Buckets.findOneAsync(bucketId, { projection: { _id: 1 } })
const bucketAdlibPromise = BucketAdLibs.findOneAsync({ bucketId, externalId }, { projection: { _id: 1 } })
const bucketAdlibActionPromise = BucketAdLibActions.findOneAsync(
{ bucketId, externalId },
{
projection: { _id: 1 },
}
)
if (!(await bucketPromise)) {
const [bucket, bucketAdlib, bucketAdlibAction] = await Promise.all([
bucketPromise,
bucketAdlibPromise,
bucketAdlibActionPromise,
])
if (!bucket) {
return ClientAPI.responseError(
UserError.from(new Error(`Bucket ${bucketId} not found`), UserErrorMessage.BucketNotFound),
412
)
}
if (!((await bucketAdlibPromise) ?? (await bucketAdlibActionPromise))) {
if (!bucketAdlib && !bucketAdlibAction) {
return ClientAPI.responseError(
UserError.from(
new Error(`No adLib with Id ${externalId}, in bucket ${bucketId}`),
Expand Down
4 changes: 2 additions & 2 deletions packages/job-worker/src/playout/adlibAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export async function handleExecuteAdlibAction(

const initCache = await loadPlayoutModelPreInit(context, lock, playlist, false)

return executeAdlibAction(context, playlist, initCache, data)
return executeAdlibActionAndSaveModel(context, playlist, initCache, data)
})
}

export async function executeAdlibAction(
export async function executeAdlibActionAndSaveModel(
context: JobContext,
playlist: DBRundownPlaylist,
initCache: PlayoutModelPreInit,
Expand Down
5 changes: 3 additions & 2 deletions packages/job-worker/src/playout/bucketAdlibJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { runJobWithPlaylistLock } from './lock'
import { UserError, UserErrorMessage } from '@sofie-automation/corelib/dist/error'
import { BucketId, ShowStyleBaseId, ShowStyleVariantId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { innerStartOrQueueAdLibPiece } from './adlibUtils'
import { executeAdlibAction } from './adlibAction'
import { executeAdlibActionAndSaveModel } from './adlibAction'
import { RundownHoldState } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { createPlayoutModelfromInitModel, loadPlayoutModelPreInit } from './model/implementation/LoadPlayoutModel'

Expand Down Expand Up @@ -55,9 +55,10 @@ export async function handleExecuteBucketAdLibOrAction(
partInstance,
bucketAdLib
)
await playoutModel.saveAllToDatabase()
return {}
} else if (bucketAdLibAction) {
return await executeAdlibAction(context, playlist, initCache, {
return await executeAdlibActionAndSaveModel(context, playlist, initCache, {
actionDocId: bucketAdLibAction._id,
actionId: bucketAdLibAction.actionId,
playlistId: playlist._id,
Expand Down

0 comments on commit a3cf788

Please sign in to comment.