2018-06-26 18:35:12 +00:00
|
|
|
export async function all(ctx) {
|
2020-04-06 22:47:58 +00:00
|
|
|
let graphics = ctx.db.get('graphics')
|
|
|
|
let data = ctx.db.get('schedule').forEach(function(s) {
|
|
|
|
s.graphic = graphics.getById(s.graphic_id).value()
|
|
|
|
}).sortBy('sort').value()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
2020-04-06 22:47:58 +00:00
|
|
|
ctx.io.emit('schedule.all', data)
|
2018-06-26 18:35:12 +00:00
|
|
|
total(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function total(ctx) {
|
2020-04-06 22:47:58 +00:00
|
|
|
let data = ctx.db.get('schedule').size()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
2020-04-06 22:47:58 +00:00
|
|
|
ctx.io.emit('schedule.total', { total: data })
|
2018-06-26 18:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function add(ctx, payload) {
|
|
|
|
payload.sort = 1
|
|
|
|
|
2020-04-06 22:47:58 +00:00
|
|
|
let schedule = ctx.db.get('schedule')
|
|
|
|
|
|
|
|
let last = schedule.sortBy('sort').last().value()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
|
|
|
if (last) {
|
2020-04-06 22:47:58 +00:00
|
|
|
payload.sort = last.sort + 1
|
2018-06-26 18:35:12 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 22:47:58 +00:00
|
|
|
await schedule.insert(payload).write()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
|
|
|
await all(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function patch(ctx, payload) {
|
2020-04-06 23:05:03 +00:00
|
|
|
let schedule = ctx.db.get('schedule')
|
2018-06-26 18:35:12 +00:00
|
|
|
|
2020-04-06 23:05:03 +00:00
|
|
|
schedule.forEach(function(item) {
|
|
|
|
schedule.updateById(Number(item.id), { sort: item.sort })
|
|
|
|
})
|
2018-06-26 18:35:12 +00:00
|
|
|
|
2020-04-06 23:05:03 +00:00
|
|
|
await schedule.write()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
|
|
|
await all(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function remove(ctx, payload) {
|
2020-04-06 23:05:03 +00:00
|
|
|
let schedule = ctx.db.get('schedule')
|
|
|
|
let schedItem = schedule.removeById(Number(payload.id)).value()
|
|
|
|
await schedule.write()
|
|
|
|
|
|
|
|
schedItem.deleted_at = new Date().getTime()
|
|
|
|
schedItem.type = 'schedule'
|
2018-06-26 18:35:12 +00:00
|
|
|
|
2020-04-06 23:05:03 +00:00
|
|
|
await ctx.db.get('trash').insert(schedItem).write()
|
2018-06-26 18:35:12 +00:00
|
|
|
|
|
|
|
await all(ctx)
|
|
|
|
}
|