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 ], ];