UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

22 lines (15 loc) 771 B
const pluralize = require('pluralize'), { models: { Selection } } = require('../emporium'), { getStorable, grGreen, resetSelections } = require('../helpers'), { spinner } = require('../refs') module.exports = async ({ Model, resource, id }) => { if (pluralize.isPlural(resource)) resource = pluralize.singular(resource) spinner.text = `selecting ${grGreen(resource)} ${id}` spinner.start() const object = await Model.find(id) if (!object) throw new Error(`unable to find ${grGreen(resource)} ${id}`) const selections = await Selection.get({ resource }) for (const selection of selections) await selection.delete() const selection = await Selection.create({ object, resource }) spinner.succeed(`selected ${grGreen(resource)} ${id}`).stop() }