Fixed /api/getRequests endpoint to return response with result from database query
parent
312f1324ca
commit
032b7b02f0
|
@ -2,6 +2,7 @@ import * as config from "./config";
|
|||
import * as requests from "./requests";
|
||||
import express from "express";
|
||||
import db from "./db";
|
||||
import { QueryResult } from "pg";
|
||||
|
||||
const app = express();
|
||||
app.use(express.static('public'));
|
||||
|
@ -9,8 +10,7 @@ app.use(express.json());
|
|||
|
||||
app.get("/api/getRequests", async (request, response) => {
|
||||
var requestCount = ( request.query.count ? parseInt(request.query.count as string, 10) : 5 );
|
||||
requests.getRequests(requestCount).then((val: any) => console.log(val));
|
||||
response.send(requests.getRequests(requestCount));
|
||||
requests.getRequests(requestCount).then((val: QueryResult) => response.send(val));
|
||||
});
|
||||
|
||||
app.get("/api/getAllRequests", async (request, response) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ const getRequestsQuery = {
|
|||
|
||||
export async function getRequests(count: number) {
|
||||
var query = Object.assign(getRequestsQuery, { values: [count] });
|
||||
db.query(query)
|
||||
return db.query(query)
|
||||
.then((result: pg.QueryResult) => result.rows)
|
||||
.catch((e: any) => console.error(e.stack));
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue