|
|
|
import DOMPurify from 'isomorphic-dompurify'
|
|
|
|
import ActionRepository from './../../repositories/actionRepository.js'
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Björn Hase, me@herr-hase.wtf
|
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
|
|
* @link https://gitea.node001.net/HerrHase/super-hog
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default async function(fastify, opts)
|
|
|
|
{
|
|
|
|
const actionRepository = new ActionRepository()
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {object} request
|
|
|
|
* @param {object} response
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
fastify.get('/task', async function (request, reply)
|
|
|
|
{
|
|
|
|
// getting actions
|
|
|
|
const actions = await actionRepository.find({ 'selector': {
|
|
|
|
'type': 'action'
|
|
|
|
}})
|
|
|
|
|
|
|
|
// send 200 and send set-token
|
|
|
|
reply
|
|
|
|
.code(200)
|
|
|
|
.send({
|
|
|
|
'data': actions
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {object} request
|
|
|
|
* @param {object} response
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
fastify.post('/task', async function (request, reply)
|
|
|
|
{
|
|
|
|
// getting actions
|
|
|
|
const action = await actionRepository.create(request.body)
|
|
|
|
|
|
|
|
// send 200 and send set-token
|
|
|
|
reply
|
|
|
|
.code(200)
|
|
|
|
.send({
|
|
|
|
'data': action
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {object} request
|
|
|
|
* @param {object} response
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
fastify.put('/task/:id', async function (request, reply)
|
|
|
|
{
|
|
|
|
// getting actions
|
|
|
|
const action = await actionRepository.update({
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
// send 200 and send set-token
|
|
|
|
reply
|
|
|
|
.code(200)
|
|
|
|
.send({
|
|
|
|
'data': action
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete single action
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {object} request
|
|
|
|
* @param {object} response
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
fastify.delete('/task/:id', async function (request, reply)
|
|
|
|
{
|
|
|
|
// getting actions
|
|
|
|
const action = await actionRepository.remove(request.params.id)
|
|
|
|
|
|
|
|
if (!action) {
|
|
|
|
return reply
|
|
|
|
.code(404)
|
|
|
|
.send()
|
|
|
|
}
|
|
|
|
|
|
|
|
// send 200 and send set-token
|
|
|
|
reply
|
|
|
|
.code(200)
|
|
|
|
.send({
|
|
|
|
'success': true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|