Fixed /api/getRequests endpoint to return response with result from database query

pull/1/head
Jennifer Nguyen 2020-07-02 01:26:30 -07:00
parent 312f1324ca
commit 032b7b02f0
2 changed files with 4 additions and 4 deletions

View File

@ -2,15 +2,15 @@ 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'));
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));
var requestCount = ( request.query.count ? parseInt(request.query.count as string, 10) : 5 );
requests.getRequests(requestCount).then((val: QueryResult) => response.send(val));
});
app.get("/api/getAllRequests", async (request, response) => {

View File

@ -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));
};