48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import express from "express";
|
|
import pg from "pg";
|
|
import db from "./db";
|
|
|
|
// getRequests
|
|
const getRequestsQuery = {
|
|
name: "getRequests",
|
|
text: "SELECT * FROM requests_vw LIMIT $1"
|
|
}
|
|
|
|
export async function getRequests(count: number, response: express.Response) {
|
|
var query = Object.assign(getRequestsQuery, { values: [count] });
|
|
db.query(query)
|
|
.then((result: pg.QueryResult) => response.send(result.rows))
|
|
.catch((e: any) => console.error(e.stack));
|
|
};
|
|
|
|
// getAllRequests
|
|
const getAllRequestsQuery = {
|
|
name: "getAllRequests",
|
|
text: "SELECT * FROM requests_all_vw LIMIT $1"
|
|
}
|
|
|
|
export async function getAllRequests(count: number, response: express.Response) {
|
|
var query = Object.assign(getAllRequestsQuery, { values: [count] });
|
|
db.query(query)
|
|
.then((result: pg.QueryResult) => response.send(result.rows))
|
|
.catch((e: any) => console.error(e.stack));
|
|
};
|
|
|
|
// addRequest
|
|
//const checkRequestExistsQuery = {
|
|
// name: "checkRequestExists",
|
|
// text: "SELECT COUNT(*) FROM requests WHERE url = $1"
|
|
//}
|
|
//
|
|
//const addRequestQuery = {
|
|
// name: "addRequest",
|
|
// text: "INSERT INTO requests (url,requester) VALUES ($1,$2)"
|
|
//}
|
|
//
|
|
//export async function addRequest(url: string, response: express.Response) {
|
|
// var query = Object.assign(getAllRequestsQuery, { values: [count] });
|
|
// db.query(query)
|
|
// .then((result: pg.QueryResult) => response.send(result.rows))
|
|
// .catch((e: any) => console.error(e.stack));
|
|
//};
|