Consistency and cleanup

This commit is contained in:
Dessa Simpson 2020-08-02 22:06:28 -07:00
parent 567b2bba27
commit 34a9c0d0d1
4 changed files with 22 additions and 19 deletions

View file

@ -2,12 +2,10 @@ import * as config from "./config";
import * as requests from "./requests";
import * as twitch from "./twitch";
import { URLSearchParams } from "url";
import { QueryResult } from "pg";
import express from "express";
import session from "express-session";
import pgSessionStore from "connect-pg-simple";
import fetch, { Response as FetchResponse } from "node-fetch";
import * as eta from "eta";
import db from "./db";
import errorHandler from "./errors";
@ -26,13 +24,13 @@ app.use(session({
// API
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: QueryResult) => response.send(val))
requests.getRequests(requestCount).then((val: Array<any>) => response.send(val))
.catch((e: any) => errorHandler(request,response,e));
});
app.get("/api/getAllRequests", async (request, response) => {
var requestCount = ( request.query.count ? parseInt(request.query.count as string, 10) : 5 );
requests.getAllRequests(requestCount).then((val: QueryResult) => response.send(val))
requests.getAllRequests(requestCount).then((val: Array<any>) => response.send(val))
.catch((e: any) => errorHandler(request,response,e));
});
@ -92,7 +90,10 @@ app.post("/api/updateRequestScore", async (request, response) => {
}
var url = request.body.url as string;
var scoreDiff = parseInt(request.body.scoreDiff as string, 10);
requests.updateRequestScore(url,scoreDiff).then((val: string) => response.send(val))
requests.updateRequestScore(url,scoreDiff).then((val: [number,string]) => {
response.status(val[0]);
response.send(val[1]);
})
.catch((e: any) => errorHandler(request,response,e));
});
@ -104,7 +105,10 @@ app.post("/api/deleteRequest", async (request, response) => {
return
}
var url = request.body.url as string;
requests.deleteRequest(url).then((val: string) => response.send(val))
requests.deleteRequest(url).then((val: [number,string]) => {
response.status(val[0]);
response.send(val[1]);
})
.catch((e: any) => errorHandler(request,response,e));
});
@ -151,9 +155,9 @@ app.get("/", async (request, response) => {
});
// Logout
app.get ("/logout", async (request, response) => request.session!.destroy((err) => response.redirect(307, '/')));
app.get ("/logout", async (request, response) => request.session!.destroy(() => response.redirect(307, '/')));
const server = app.listen(config.port, () => {
app.listen(config.port, () => {
console.log(`Listening on port ${config.port}`);
});