Consistency and cleanup
This commit is contained in:
parent
567b2bba27
commit
34a9c0d0d1
4 changed files with 22 additions and 19 deletions
20
src/app.ts
20
src/app.ts
|
@ -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}`);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue