1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-09 23:40:06 +00:00

feat(code): added code/trigger API endpoint

This commit is contained in:
Yury
2024-10-29 11:18:04 +03:00
parent aa2a1cbe13
commit ffcf193b87
7 changed files with 194 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
import express from 'express'
import { runCodeValidation } from '../../utils'
import { runCodeValidation, triggerCodeValidation } from '../../utils'
import { CodeController } from '../../controllers/'
const runRouter = express.Router()
@@ -28,4 +28,22 @@ runRouter.post('/execute', async (req, res) => {
}
})
runRouter.post('/trigger', async (req, res) => {
const { error, value: body } = triggerCodeValidation(req.body)
if (error) return res.status(400).send(error.details[0].message)
try {
const response = await controller.triggerCode(req, body)
res.status(200)
res.send(response)
} catch (err: any) {
const statusCode = err.code
delete err.code
res.status(statusCode).send(err)
}
})
export default runRouter