mirror of
https://github.com/sasjs/server.git
synced 2026-01-07 06:30:06 +00:00
chore: docs finalized for stp and others
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
import express from 'express'
|
||||
import path from 'path'
|
||||
import { ExecutionController } from '../../controllers'
|
||||
import { DriveController } from '../../controllers/drive'
|
||||
import { isFileQuery } from '../../types'
|
||||
import {
|
||||
getFileDriveValidation,
|
||||
getTmpFilesFolderPath,
|
||||
updateFileDriveValidation
|
||||
} from '../../utils'
|
||||
import { getFileDriveValidation, updateFileDriveValidation } from '../../utils'
|
||||
|
||||
const driveRouter = express.Router()
|
||||
|
||||
|
||||
@@ -1,39 +1,26 @@
|
||||
import express from 'express'
|
||||
import { isExecutionQuery, PreProgramVars } from '../../types'
|
||||
import path from 'path'
|
||||
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../../utils'
|
||||
import { ExecutionController, FileUploadController } from '../../controllers'
|
||||
import { executeProgramRawValidation } from '../../utils'
|
||||
import STPController from '../../controllers/stp'
|
||||
import { FileUploadController } from '../../controllers'
|
||||
|
||||
const stpRouter = express.Router()
|
||||
|
||||
const fileUploadController = new FileUploadController()
|
||||
const controller = new STPController()
|
||||
|
||||
stpRouter.get('/execute', async (req, res) => {
|
||||
if (isExecutionQuery(req.query)) {
|
||||
let sasCodePath =
|
||||
path
|
||||
.join(getTmpFilesFolderPath(), req.query._program)
|
||||
.replace(new RegExp('/', 'g'), path.sep) + '.sas'
|
||||
const { error, value: query } = executeProgramRawValidation(req.query)
|
||||
if (error) return res.status(400).send(error.details[0].message)
|
||||
|
||||
await new ExecutionController()
|
||||
.execute(sasCodePath, getPreProgramVariables(req), undefined, undefined, {
|
||||
...req.query
|
||||
})
|
||||
.then((result: {}) => {
|
||||
res.status(200).send(result)
|
||||
})
|
||||
.catch((err: {} | string) => {
|
||||
res.status(400).send({
|
||||
status: 'failure',
|
||||
message: 'Job execution failed.',
|
||||
...(typeof err === 'object' ? err : { details: err })
|
||||
})
|
||||
})
|
||||
} else {
|
||||
res.status(400).send({
|
||||
status: 'failure',
|
||||
message: `Please provide the location of SAS code`
|
||||
})
|
||||
try {
|
||||
const response = await controller.executeReturnRaw(req, query._program)
|
||||
res.send(response)
|
||||
} catch (err: any) {
|
||||
const statusCode = err.code
|
||||
|
||||
delete err.code
|
||||
|
||||
res.status(statusCode).send(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -42,68 +29,27 @@ stpRouter.post(
|
||||
fileUploadController.preuploadMiddleware,
|
||||
fileUploadController.getMulterUploadObject().any(),
|
||||
async (req: any, res: any) => {
|
||||
let _program
|
||||
if (isExecutionQuery(req.query)) {
|
||||
_program = req.query._program
|
||||
} else if (isExecutionQuery(req.body)) {
|
||||
_program = req.body._program
|
||||
}
|
||||
const { error: errQ, value: query } = executeProgramRawValidation(req.query)
|
||||
if (errQ) return res.status(400).send(errQ.details[0].message)
|
||||
|
||||
if (_program) {
|
||||
let sasCodePath =
|
||||
path
|
||||
.join(getTmpFilesFolderPath(), _program)
|
||||
.replace(new RegExp('/', 'g'), path.sep) + '.sas'
|
||||
const { error: errB, value: body } = executeProgramRawValidation(req.body)
|
||||
if (errB) return res.status(400).send(errB.details[0].message)
|
||||
|
||||
let filesNamesMap = null
|
||||
try {
|
||||
const response = await controller.executeReturnJson(
|
||||
req,
|
||||
query,
|
||||
body?._program
|
||||
)
|
||||
res.send(response)
|
||||
} catch (err: any) {
|
||||
const statusCode = err.code
|
||||
|
||||
if (req.files && req.files.length > 0) {
|
||||
filesNamesMap = makeFilesNamesMap(req.files)
|
||||
}
|
||||
delete err.code
|
||||
|
||||
await new ExecutionController()
|
||||
.execute(
|
||||
sasCodePath,
|
||||
getPreProgramVariables(req),
|
||||
undefined,
|
||||
req.sasSession,
|
||||
{ ...req.query, ...req.body },
|
||||
{ filesNamesMap: filesNamesMap },
|
||||
true
|
||||
)
|
||||
.then((result: {}) => {
|
||||
res.status(200).send({
|
||||
status: 'success',
|
||||
...result
|
||||
})
|
||||
})
|
||||
.catch((err: {} | string) => {
|
||||
res.status(400).send({
|
||||
status: 'failure',
|
||||
message: 'Job execution failed.',
|
||||
...(typeof err === 'object' ? err : { details: err })
|
||||
})
|
||||
})
|
||||
} else {
|
||||
res.status(400).send({
|
||||
status: 'failure',
|
||||
message: `Please provide the location of SAS code`
|
||||
})
|
||||
res.status(statusCode).send(err)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const getPreProgramVariables = (req: any): PreProgramVars => {
|
||||
const host = req.get('host')
|
||||
const protocol = req.protocol + '://'
|
||||
const { user, accessToken } = req
|
||||
return {
|
||||
username: user.username,
|
||||
userId: user.userId,
|
||||
displayName: user.displayName,
|
||||
serverUrl: protocol + host,
|
||||
accessToken
|
||||
}
|
||||
}
|
||||
|
||||
export default stpRouter
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import express from 'express'
|
||||
import { isExecutionQuery } from '../../types'
|
||||
import path from 'path'
|
||||
import { getTmpFilesFolderPath, getWebBuildFolderPath } from '../../utils'
|
||||
import { ExecutionController } from '../../controllers'
|
||||
import { getWebBuildFolderPath } from '../../utils'
|
||||
|
||||
const webRouter = express.Router()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user