diff --git a/backend/classes/db-helper.js b/backend/classes/db-helper.js index e0fea09..8af10f9 100644 --- a/backend/classes/db-helper.js +++ b/backend/classes/db-helper.js @@ -59,7 +59,9 @@ async function query({ const joinConditions = join.conditions .map((condition, index) => { const conjunction = index === 0 ? "" : condition.type ? condition.type.toUpperCase() : "AND"; - return `${conjunction} ${wrapField(condition.first)} ${condition.operator} ${wrapField(condition.second)}`; + return `${conjunction} ${wrapField(condition.first)} ${condition.operator} ${ + condition.second ? wrapField(condition.second) : `'${condition.value}'` + }`; }) .join(" "); const joinQuery = ` ${join.type.toUpperCase()} JOIN ${join.table} AS ${join.alias} ON ${joinConditions}`; diff --git a/backend/routes/api.js b/backend/routes/api.js index 5de01d4..f958c6a 100644 --- a/backend/routes/api.js +++ b/backend/routes/api.js @@ -1101,8 +1101,8 @@ router.get("/getHistory", async (req, res) => { table: "jf_library_episodes", alias: "e", conditions: [ - { first: "a.EpisodeId", operator: "=", second: "e.EpisodeId", type: "and" }, - { first: "a.SeasonId", operator: "=", second: "e.SeasonId", type: "and" }, + { first: "a.EpisodeId", operator: "=", second: "e.EpisodeId" }, + { first: "a.SeasonId", operator: "=", second: "e.SeasonId" }, ], }, { @@ -1110,7 +1110,7 @@ router.get("/getHistory", async (req, res) => { table: "jf_library_items", alias: "i", conditions: [ - { first: "i.Id", operator: "=", second: "a.NowPlayingItemId", type: "or" }, + { first: "i.Id", operator: "=", second: "a.NowPlayingItemId" }, { first: "e.SeriesId", operator: "=", second: "i.Id", type: "or" }, ], }, @@ -1148,7 +1148,10 @@ router.post("/getLibraryHistory", async (req, res) => { type: "inner", table: "jf_library_items", alias: "i", - conditions: [{ first: "i.Id", operator: "=", second: "a.NowPlayingItemId" }], + conditions: [ + { first: "i.Id", operator: "=", second: "a.NowPlayingItemId" }, + { first: "i.ParentId", operator: "=", value: libraryid }, + ], }, { type: "left", @@ -1160,7 +1163,7 @@ router.post("/getLibraryHistory", async (req, res) => { ], }, ], - where: [{ column: "i.ParentId", operator: "=", value: libraryid }], + order_by: "ActivityDateInserted", sort_order: "desc", pageNumber: page, @@ -1206,13 +1209,13 @@ router.post("/getItemHistory", async (req, res) => { table: "jf_library_items", alias: "i", conditions: [ - { first: "i.Id", operator: "=", second: "a.NowPlayingItemId", type: "or" }, + { first: "i.Id", operator: "=", second: "a.NowPlayingItemId" }, { first: "e.SeriesId", operator: "=", second: "i.Id", type: "or" }, ], }, ], where: [ - { column: "a.EpisodeId", operator: "=", value: itemid, type: "or" }, + { column: "a.EpisodeId", operator: "=", value: itemid }, { column: "a.SeasonId", operator: "=", value: itemid, type: "or" }, { column: "a.NowPlayingItemId", operator: "=", value: itemid, type: "or" }, ], @@ -1222,11 +1225,6 @@ router.post("/getItemHistory", async (req, res) => { pageSize: size, }); - // const groupedResults = rows.map((item) => ({ - // ...item, - // results: [], - // })); - res.send({ current_page: page, pages: result.pages, results: result.results }); } catch (error) { console.log(error); @@ -1265,7 +1263,7 @@ router.post("/getUserHistory", async (req, res) => { table: "jf_library_items", alias: "i", conditions: [ - { first: "i.Id", operator: "=", second: "a.NowPlayingItemId", type: "or" }, + { first: "i.Id", operator: "=", second: "a.NowPlayingItemId" }, { first: "e.SeriesId", operator: "=", second: "i.Id", type: "or" }, ], },