Prevent assert error when checking request status, returns success 200
This commit is contained in:
@@ -33,7 +33,8 @@ class RequestRepository {
|
|||||||
// downloaded: "(select status from requests where id is request.id and type is request.type limit 1)",
|
// downloaded: "(select status from requests where id is request.id and type is request.type limit 1)",
|
||||||
// deluge: '(select status from deluge_torrent where id is request.id and type is request.type limit 1)',
|
// deluge: '(select status from deluge_torrent where id is request.id and type is request.type limit 1)',
|
||||||
// fetchAllFilterStatus: 'select * from request where '
|
// fetchAllFilterStatus: 'select * from request where '
|
||||||
// readWithoutUserData: "select id, title, year, type, status, date from requests where id is ? and type is ?",
|
readWithoutUserData:
|
||||||
|
"select id, title, year, type, status, date from requests where id is ? and type is ?",
|
||||||
read: "select id, title, year, type, status, requested_by, ip, date, user_agent from requests where id is ? and type is ?"
|
read: "select id, title, year, type, status, requested_by, ip, date, user_agent from requests where id is ? and type is ?"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,8 @@ class RequestRepository {
|
|||||||
return this.database
|
return this.database
|
||||||
.get(this.queries.readWithoutUserData, [id, type])
|
.get(this.queries.readWithoutUserData, [id, type])
|
||||||
.then(row => {
|
.then(row => {
|
||||||
assert(row, "Could not find request item with that id and type");
|
if (!row) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
title: row.title,
|
title: row.title,
|
||||||
@@ -122,10 +124,7 @@ class RequestRepository {
|
|||||||
return this.database
|
return this.database
|
||||||
.all(fetchQuery, fetchParams)
|
.all(fetchQuery, fetchParams)
|
||||||
.then(async rows => {
|
.then(async rows => {
|
||||||
const sqliteResponse = await this.database.get(
|
const sqliteResponse = await this.database.get(fetchTotalResults);
|
||||||
fetchTotalResults,
|
|
||||||
filter || null
|
|
||||||
);
|
|
||||||
const { totalRequests } = sqliteResponse;
|
const { totalRequests } = sqliteResponse;
|
||||||
const totalPages = Math.ceil(totalRequests / 26);
|
const totalPages = Math.ceil(totalRequests / 26);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,19 @@ function fetchAllRequests(req, res) {
|
|||||||
|
|
||||||
request
|
request
|
||||||
.getRequestByIdAndType(id, type)
|
.getRequestByIdAndType(id, type)
|
||||||
.then(result => res.send(result))
|
.then(result => {
|
||||||
|
if (!result) {
|
||||||
|
return res.send({
|
||||||
|
success: false,
|
||||||
|
message: `Item ${type} with id ${id} has not been requested`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.send({
|
||||||
|
success: true,
|
||||||
|
result
|
||||||
|
});
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
return res.status(error?.statusCode || 500).send({
|
return res.status(error?.statusCode || 500).send({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const chaiHttp = require("chai-http");
|
|||||||
|
|
||||||
const server = require("../../src/webserver/server");
|
const server = require("../../src/webserver/server");
|
||||||
const resetDatabase = require("../helpers/resetDatabase");
|
const resetDatabase = require("../helpers/resetDatabase");
|
||||||
// const assert = require("assert");
|
|
||||||
chai.use(chaiHttp);
|
chai.use(chaiHttp);
|
||||||
|
|
||||||
describe("As a user I want a forbidden error if the token is malformed", () => {
|
describe("As a user I want a forbidden error if the token is malformed", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user