You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
962 B
30 lines
962 B
import * as api from '../../client/src/api/api'; |
|
import { EndpointError, EndpointHandler, handleErrorsInEndpoint } from './types'; |
|
import Knex from 'knex'; |
|
import { doQuery } from '../db/Query'; |
|
|
|
export const Query: EndpointHandler = async (req: any, res: any, knex: Knex) => { |
|
if (!api.checkQueryRequest(req.body)) { |
|
const e: EndpointError = { |
|
name: "EndpointError", |
|
message: 'Invalid Query request: ' + JSON.stringify(req.body), |
|
httpStatus: 400 |
|
}; |
|
throw e; |
|
} |
|
const reqObject: api.QueryRequest = req.body; |
|
const { id: userId } = req.user; |
|
|
|
console.log("User ", userId, ": Query ", reqObject); |
|
|
|
try { |
|
let r = doQuery(userId, reqObject, knex); |
|
res.status(200).send(r); |
|
} catch (e) { |
|
handleErrorsInEndpoint(e); |
|
} |
|
} |
|
|
|
export const queryEndpoints: [ string, string, boolean, EndpointHandler ][] = [ |
|
[ api.QueryEndpoint, 'post', true, Query ], |
|
]; |