You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.2 KiB

3 years ago
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
*
*/
3 years ago
fastify.get('/task', async function (request, reply)
3 years ago
{
// 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)
3 years ago
{
// getting actions
3 years ago
const action = await actionRepository.create(request.body)
3 years ago
// 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)
3 years ago
{
// 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)
3 years ago
{
// getting actions
3 years ago
const action = await actionRepository.remove(request.params.id)
3 years ago
if (!action) {
return reply
.code(404)
.send()
}
// send 200 and send set-token
reply
.code(200)
.send({
'success': true
})
})
}