UNPKG

@wmfs/tymly-cardscript-plugin

Version:

Plugin which handles interactions to do with Cardscript

40 lines (32 loc) 1.02 kB
class WatchBoard { init (resourceConfig, env) { this.watchedBoards = env.bootedServices.storage.models.tymly_watchedBoards } async run (event, context) { const { stateMachineName, boardKeys, title, description, category, categoryLabel } = event let feedName = [stateMachineName] if (boardKeys) Object.keys(boardKeys).sort().map(k => feedName.push(boardKeys[k])) feedName = feedName.join('|') const launches = [{ stateMachineName, input: { boardKeys } }] const startedWatching = new Date().toISOString() try { const doc = await this.watchedBoards.upsert( { userId: context.userId, feedName, title, description, startedWatching, launches, category, categoryLabel }, {} ) context.sendTaskSuccess({ subscriptionId: doc.idProperties.id, feedName, startedWatching }) } catch (err) { context.sendTaskFailure(err) } } } module.exports = WatchBoard