Skip to content
Snippets Groups Projects
Commit d99bf981 authored by Louis's avatar Louis :fire:
Browse files

Add feedback endpoint

parent 0f505beb
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@
"moment": "^2.24.0",
"moment-range": "^4.0.2",
"multer": "^1.4.2",
"node-fetch": "^2.6.0",
"oauth2-server": "^3.0.1",
"pg": "^7.12.1",
"scrypt-kdf": "^2.0.1",
......
const fetch = require('node-fetch')
const SLACK_WEBHOOK = process.env.SLACK_WEBHOOK
function createSlackPayload({ name, email, message = '' }) {
return {
"blocks": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Incoming message from an app user!"
}
},
{
"type": "section",
"text": {
"type": "plain_text",
text: message,
emoji: true,
}
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": (new Date()).toDateString(),
},
name && {
"type": "plain_text",
"text": `From: ${ name }`
},
email && {
"type": "plain_text",
"text": `Email: ${ email }`
}
].filter(Boolean)
}
]
}
}
exports.send = async ctx => {
const { message } = ctx.request.body
const payload = { message }
const user = await ctx.services.authService.getUser()
if (user) {
payload.name = user.name
payload.email = user.email
}
const slackObject = createSlackPayload(payload)
const response = await fetch(SLACK_WEBHOOK, {
method: 'POST',
body: JSON.stringify(slackObject),
headers: {
'Content-Type': 'application/json',
},
}).catch(e => e)
if (response instanceof Error) {
console.error(response)
ctx.status = 500
ctx.body = {
message: 'Something went wrong'
}
} else {
ctx.status = response.status
ctx.body = { message: 'Something Happened'}
}
}
......@@ -22,36 +22,41 @@ web.post('/auth/authorize', AuthServer.authorize)
web.post('/auth/token', AuthServer.token)
// --- API ROUTES
const api = new Router({ prefix: '/api' })
api.use(require('./middleware/api/errors'))
api.use(includes)
api.post('/metrics', controller('api/content', 'postMetric'))
api.get('/metrics', controller('api/content', 'getWithin'))
function mount(api) {
api.use(require('./middleware/api/errors'))
api.use(includes)
api.post('/metrics', controller('api/content', 'postMetric'))
api.get('/metrics', controller('api/content', 'getWithin'))
api.get('/images', controller('api/storage', 'getFiles'))
api.post('/images', upload.single('featured_image'), controller('api/storage', 'saveFile'))
api.post('/images/:imageId/feature', controller('api/storage', 'featureImage'))
api.get('/images', controller('api/storage', 'getFiles'))
api.post('/images', upload.single('featured_image'), controller('api/storage', 'saveFile'))
api.post('/images/:imageId/feature', controller('api/storage', 'featureImage'))
/** @deprecated */
api.post('/feature', upload.single('featured_image'), controller('api/storage', 'saveFile'))
/** @deprecated */
api.post('/feature', upload.single('featured_image'), controller('api/storage', 'saveFile'))
api.get('/feed', controller('api/storage', 'feed'))
api.post('/feed/:fileId/like',controller('api/storage', 'like'))
api.post('/feed/:fileId/unlike', controller('api/storage', 'unlike'))
api.get('/feed', controller('api/storage', 'feed'))
api.post('/feed/:fileId/like',controller('api/storage', 'like'))
api.post('/feed/:fileId/unlike', controller('api/storage', 'unlike'))
api.post('/register', controller('api/auth', 'register'))
api.post('/login', controller('api/auth', 'login'))
api.post('/register', controller('api/auth', 'register'))
api.post('/login', controller('api/auth', 'login'))
api.get('/self', controller('api/user', 'self'))
api.put('/self/:property', controller('api/user', 'updateOne'))
api.get('/self', controller('api/user', 'self'))
api.put('/self/:property', controller('api/user', 'updateOne'))
const apiApi = new Router({ prefix: '/api' })
apiApi.use(api.routes())
apiApi.use(api.allowedMethods())
api.post('/feedback', controller('api/feedback', 'send'))
}
const apiRouter = new Router({ prefix: '/api' })
const apiLegacy = new Router({ prefix: '/api/api' })
mount(apiRouter)
mount(apiLegacy)
module.exports = {
api,
web,
apiApi,
apiRouter,
apiLegacy,
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment