Backend: Implement basic issue API
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
a0de55274d
commit
205c6b5d6b
2
app.js
2
app.js
@ -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) =>{
|
||||
|
10
src/configs/domains.configs.js
Normal file
10
src/configs/domains.configs.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = valid
|
||||
|
||||
const valid = [
|
||||
"owlboard.co.uk",
|
||||
"fjla.uk",
|
||||
"gwr.com",
|
||||
"swrailway.com",
|
||||
"firstrail.com",
|
||||
"networkrail.co.uk"
|
||||
]
|
14
src/controllers/issue.controllers.js
Normal file
14
src/controllers/issue.controllers.js
Normal 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
|
||||
}
|
7
src/routes/issue.routes.js
Normal file
7
src/routes/issue.routes.js
Normal 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;
|
@ -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
|
||||
}
|
Reference in New Issue
Block a user