From 032b7b02f0e949e368dd5537be692bb55a0ad446 Mon Sep 17 00:00:00 2001 From: Jennifer Nguyen Date: Thu, 2 Jul 2020 01:26:30 -0700 Subject: [PATCH] Fixed /api/getRequests endpoint to return response with result from database query --- src/app.ts | 6 +++--- src/requests.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app.ts b/src/app.ts index f9bfa2a..ef6f8a8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -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) => { diff --git a/src/requests.ts b/src/requests.ts index a056da1..d0a7272 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -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)); };