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 * as requests from "./requests";
import express from "express"; import express from "express";
import db from "./db"; import db from "./db";
import { QueryResult } from "pg";
const app = express(); const app = express();
app.use(express.static('public')); app.use(express.static('public'));
app.use(express.json()); app.use(express.json());
app.get("/api/getRequests", async (request, response) => { app.get("/api/getRequests", async (request, response) => {
var requestCount = ( request.query.count ? parseInt(request.query.count as string, 10) : 5 ); var requestCount = ( request.query.count ? parseInt(request.query.count as string, 10) : 5 );
requests.getRequests(requestCount).then((val: any) => console.log(val)); requests.getRequests(requestCount).then((val: QueryResult) => response.send(val));
response.send(requests.getRequests(requestCount));
}); });
app.get("/api/getAllRequests", async (request, response) => { app.get("/api/getAllRequests", async (request, response) => {

View File

@ -10,7 +10,7 @@ const getRequestsQuery = {
export async function getRequests(count: number) { export async function getRequests(count: number) {
var query = Object.assign(getRequestsQuery, { values: [count] }); var query = Object.assign(getRequestsQuery, { values: [count] });
db.query(query) return db.query(query)
.then((result: pg.QueryResult) => result.rows) .then((result: pg.QueryResult) => result.rows)
.catch((e: any) => console.error(e.stack)); .catch((e: any) => console.error(e.stack));
}; };