Backend: Implement basic issue API

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-30 23:47:14 +00:00
parent a0de55274d
commit 205c6b5d6b
5 changed files with 49 additions and 7 deletions

2
app.js
View File

@ -15,6 +15,7 @@ const listRtr = require('./src/routes/list.routes'); // /list endpoints
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
const findRtr = require('./src/routes/find.routes'); // /find endpoints
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
const initDb = require('./src/utils/dbinit.utils'); // DB Init Utility
// Set Server Configurations
@ -53,6 +54,7 @@ app.use('/api/v1/list', listRtr);
app.use('/api/v1/ldb', ldbRtr);
app.use('/api/v1/kube', kubeRtr);
app.use('/api/v1/find', findRtr);
app.use('./api/v1/issue', issueRtr);
// Start Express
app.listen(srvPort, srvListen, (error) =>{

View File

@ -0,0 +1,10 @@
module.exports = valid
const valid = [
"owlboard.co.uk",
"fjla.uk",
"gwr.com",
"swrailway.com",
"firstrail.com",
"networkrail.co.uk"
]

View File

@ -0,0 +1,14 @@
const issue = require('../services/issue.services');
async function post(req, res, next){
try {
res.json(await issue.processor(req.body))
} catch (err) {
console.error(`Controller Error`, err.message);
next(err);
}
}
module.exports = {
post
}

View File

@ -0,0 +1,7 @@
const express = require('express');
const router = express.Router();
const issueController = require('../controllers/issue.controllers');
router.post('/issue', issueController.post);
module.exports = router;

View File

@ -1,19 +1,28 @@
const axios = require('axios')
const clean = require('../utils/sanitizer.utils')
async function processor(data) {
let out = {}
out.title = await cleanData(data.title)
out.body = await cleanData(data.body)
sendToGitea(out);
}
async function cleanData(data) {
return clean.cleanApiEndpointTxt(data)
}
async function sendToGitea(body) {
let key = process.env.OWL_GIT_ISSUEBOT
let url = process.env.OWL_GIT_APIENDPOINT
let options = {
let opts = {
headers: {
Authorization: key
},
data: body,
withCredantials: true
}
}
await axios.post(url, options)
await axios.post(url, body, opts)
}
module.exports = {
sendToGitea
processor
}