mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Add isAvailable
filter for both entries & shows
This commit is contained in:
parent
107e581801
commit
be4b4f016b
@ -72,6 +72,7 @@ export const entryFilters: FilterDef = {
|
||||
runtime: { column: entries.runtime, type: "float" },
|
||||
airDate: { column: entries.airDate, type: "date" },
|
||||
playedDate: { column: entryProgressQ.playedDate, type: "date" },
|
||||
isAvailable: { column: isNotNull(entries.availableSince), type: "bool" },
|
||||
};
|
||||
|
||||
const extraFilters: FilterDef = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { type SQL, and, eq, exists, ne, sql } from "drizzle-orm";
|
||||
import { type SQL, and, eq, exists, gt, ne, sql } from "drizzle-orm";
|
||||
import { db } from "~/db";
|
||||
import {
|
||||
entries,
|
||||
@ -60,7 +60,7 @@ export const showFilters: FilterDef = {
|
||||
runtime: { column: shows.runtime, type: "float" },
|
||||
airDate: { column: shows.startAir, type: "date" },
|
||||
startAir: { column: shows.startAir, type: "date" },
|
||||
endAir: { column: shows.startAir, type: "date" },
|
||||
endAir: { column: shows.endAir, type: "date" },
|
||||
originalLanguage: {
|
||||
column: sql`${shows.original}->'language'`,
|
||||
type: "string",
|
||||
@ -76,6 +76,7 @@ export const showFilters: FilterDef = {
|
||||
values: WatchlistStatus.enum,
|
||||
},
|
||||
score: { column: watchStatusQ.score, type: "int" },
|
||||
isAvailable: { column: sql`(${shows.availableCount} > 0)`, type: "bool" },
|
||||
};
|
||||
export const showSort = Sort(
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ export type FilterDef = {
|
||||
[key: string]:
|
||||
| {
|
||||
column: Column | SQLWrapper;
|
||||
type: "int" | "float" | "date" | "string";
|
||||
type: "int" | "float" | "date" | "string" | "bool";
|
||||
isArray?: boolean;
|
||||
}
|
||||
| {
|
||||
|
@ -29,7 +29,8 @@ export type Value =
|
||||
| { type: "float"; value: number }
|
||||
| { type: "date"; value: string }
|
||||
| { type: "string"; value: string }
|
||||
| { type: "enum"; value: string };
|
||||
| { type: "enum"; value: string }
|
||||
| { type: "bool"; value: boolean };
|
||||
const operators = ["eq", "ne", "gt", "ge", "lt", "le", "has"] as const;
|
||||
export type Operator = (typeof operators)[number];
|
||||
export type Expression =
|
||||
|
@ -48,6 +48,18 @@ export const toDrizzle = (expr: Expression, config: FilterDef): SQL => {
|
||||
// but parser doesn't know if an enum should be a string
|
||||
expr.value = { type: "string", value: expr.value.value };
|
||||
}
|
||||
if (prop.type === "bool" && expr.value.type === "enum") {
|
||||
if (expr.value.value !== "false" && expr.value.value !== "true") {
|
||||
throw new KErrorT(
|
||||
comment`
|
||||
Invalid value for property ${expr.property}.
|
||||
Get ${expr.value.value} but expected true or false.
|
||||
`,
|
||||
{ in: where },
|
||||
);
|
||||
}
|
||||
expr.value = { type: "bool", value: expr.value.value === "true" }
|
||||
}
|
||||
if (prop.type !== expr.value.type) {
|
||||
throw new KErrorT(
|
||||
comment`
|
||||
|
Loading…
x
Reference in New Issue
Block a user