1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-09 07:20:05 +00:00

feat(stp): added trigger endpoint

This commit is contained in:
Yury
2024-10-29 16:27:53 +03:00
parent e9519cb3c6
commit b0723f1444
4 changed files with 191 additions and 3 deletions

View File

@@ -1,5 +1,8 @@
import express from 'express'
import { executeProgramRawValidation } from '../../utils'
import {
executeProgramRawValidation,
triggerProgramValidation
} from '../../utils'
import { STPController } from '../../controllers/'
import { FileUploadController } from '../../controllers/internal'
@@ -69,4 +72,27 @@ stpRouter.post(
}
)
stpRouter.post('/trigger', async (req, res) => {
const { error, value: body } = triggerProgramValidation(req.body)
if (error) return res.status(400).send(error.details[0].message)
try {
const response = await controller.triggerProgram(
req,
body,
req.query?._program as string
)
res.status(200)
res.send(response)
} catch (err: any) {
const statusCode = err.code
delete err.code
res.status(statusCode).send(err)
}
})
export default stpRouter