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.
109 lines
2.2 KiB
109 lines
2.2 KiB
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('/action', 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('/action', async function (request, reply)
|
|
{
|
|
// getting actions
|
|
const action = await actionRepository.create()
|
|
|
|
// send 200 and send set-token
|
|
reply
|
|
.code(200)
|
|
.send({
|
|
'data': action
|
|
})
|
|
})
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @param {object} request
|
|
* @param {object} response
|
|
*
|
|
*/
|
|
fastify.put('/action/: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('/action/:id', async function (request, reply)
|
|
{
|
|
// getting actions
|
|
const action = await actionRepository.findOne({
|
|
'id': request.query.id
|
|
})
|
|
|
|
if (!action) {
|
|
return reply
|
|
.code(404)
|
|
.send()
|
|
}
|
|
|
|
// send 200 and send set-token
|
|
reply
|
|
.code(200)
|
|
.send({
|
|
'success': true
|
|
})
|
|
})
|
|
} |