filo_caspar/api/graphic/routes.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-04-14 04:01:51 +00:00
import Graphic from './model'
2017-12-03 11:34:43 +00:00
export async function all(ctx) {
2016-04-14 04:01:51 +00:00
let data = await Graphic.getAll()
2017-12-03 11:34:43 +00:00
ctx.io.emit('graphic.all', data.toJSON())
2016-04-14 04:01:51 +00:00
}
2017-12-03 11:34:43 +00:00
export async function single(ctx, data) {
2016-04-14 04:01:51 +00:00
if (!data || !data.id) {
ctx.log.warn('called graphic get single but no id specified')
return
}
let graphic = await Graphic.getSingle(data.id)
2017-12-03 11:34:43 +00:00
ctx.io.emit('graphic.single', graphic.toJSON())
2016-04-14 04:01:51 +00:00
}
export async function create(ctx, data) {
data.settings = {}
data.is_deleted = false
if (data.engine === 'countdown') {
data.settings.html = `<span id="${data.name}-countdown-timer">countdown appears here</span>`
data.settings.main = 'text'
}
await Graphic.create(data)
2017-12-03 11:34:43 +00:00
await all(ctx)
2016-04-14 04:01:51 +00:00
}
export async function remove(ctx, data) {
if (!data || !data.id) {
ctx.log.warn('called graphic get single but no id specified')
return
}
let graphic = await Graphic.getSingle(data.id)
graphic.set({ is_deleted: true })
await graphic.save()
2017-12-03 11:34:43 +00:00
await all(ctx)
2016-04-14 04:01:51 +00:00
}
export async function update(ctx, data) {
if (!data || !data.id) {
ctx.log.warn('called graphic update but no id specified')
return
}
let graphic = await Graphic.getSingle(data.id)
graphic.set(data)
await graphic.save()
2017-12-03 11:34:43 +00:00
await single(ctx, data)
2016-04-14 04:01:51 +00:00
}