mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-03 19:17:16 -05:00 
			
		
		
		
	Cleanup default watchlist sort
This commit is contained in:
		
							parent
							
								
									880a85ff8d
								
							
						
					
					
						commit
						df7d109c34
					
				@ -1,6 +1,12 @@
 | 
				
			|||||||
import { type SQL, and, eq, isNotNull, isNull, sql } from "drizzle-orm";
 | 
					import { and, eq, isNotNull, isNull, sql } from "drizzle-orm";
 | 
				
			||||||
import Elysia, { t } from "elysia";
 | 
					import Elysia, { t } from "elysia";
 | 
				
			||||||
import { auth, getUserInfo } from "~/auth";
 | 
					import { auth, getUserInfo } from "~/auth";
 | 
				
			||||||
 | 
					import {
 | 
				
			||||||
 | 
						getShows,
 | 
				
			||||||
 | 
						showFilters,
 | 
				
			||||||
 | 
						showSort,
 | 
				
			||||||
 | 
						watchStatusQ,
 | 
				
			||||||
 | 
					} from "~/controllers/shows/logic";
 | 
				
			||||||
import { db } from "~/db";
 | 
					import { db } from "~/db";
 | 
				
			||||||
import { profiles, shows } from "~/db/schema";
 | 
					import { profiles, shows } from "~/db/schema";
 | 
				
			||||||
import { watchlist } from "~/db/schema/watchlist";
 | 
					import { watchlist } from "~/db/schema/watchlist";
 | 
				
			||||||
@ -19,7 +25,6 @@ import {
 | 
				
			|||||||
} from "~/models/utils";
 | 
					} from "~/models/utils";
 | 
				
			||||||
import { desc } from "~/models/utils/descriptions";
 | 
					import { desc } from "~/models/utils/descriptions";
 | 
				
			||||||
import { MovieWatchStatus, SerieWatchStatus } from "~/models/watchlist";
 | 
					import { MovieWatchStatus, SerieWatchStatus } from "~/models/watchlist";
 | 
				
			||||||
import { getShows, showFilters, showSort, watchStatusQ } from "./shows/logic";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function setWatchStatus({
 | 
					async function setWatchStatus({
 | 
				
			||||||
	show,
 | 
						show,
 | 
				
			||||||
@ -72,7 +77,7 @@ async function setWatchStatus({
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
		.returning({
 | 
							.returning({
 | 
				
			||||||
			...getColumns(watchlist),
 | 
								...getColumns(watchlist),
 | 
				
			||||||
			percent: sql`${watchlist.seenCount}`.as("percent"),
 | 
								percent: sql<number>`${watchlist.seenCount}`.as("percent"),
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -82,7 +87,10 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
 | 
				
			|||||||
	.guard(
 | 
						.guard(
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			query: t.Object({
 | 
								query: t.Object({
 | 
				
			||||||
				sort: showSort,
 | 
									sort: {
 | 
				
			||||||
 | 
										...showSort,
 | 
				
			||||||
 | 
										default: ["watchStatus", ...showSort.default],
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
				filter: t.Optional(Filter({ def: showFilters })),
 | 
									filter: t.Optional(Filter({ def: showFilters })),
 | 
				
			||||||
				query: t.Optional(t.String({ description: desc.query })),
 | 
									query: t.Optional(t.String({ description: desc.query })),
 | 
				
			||||||
				limit: t.Integer({
 | 
									limit: t.Integer({
 | 
				
			||||||
@ -233,7 +241,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
 | 
				
			|||||||
			}),
 | 
								}),
 | 
				
			||||||
			body: SerieWatchStatus,
 | 
								body: SerieWatchStatus,
 | 
				
			||||||
			response: {
 | 
								response: {
 | 
				
			||||||
				200: t.Union([SerieWatchStatus, DbMetadata]),
 | 
									200: t.Intersect([SerieWatchStatus, DbMetadata]),
 | 
				
			||||||
				404: KError,
 | 
									404: KError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			permissions: ["core.read"],
 | 
								permissions: ["core.read"],
 | 
				
			||||||
@ -280,7 +288,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
 | 
				
			|||||||
			}),
 | 
								}),
 | 
				
			||||||
			body: t.Omit(MovieWatchStatus, ["percent"]),
 | 
								body: t.Omit(MovieWatchStatus, ["percent"]),
 | 
				
			||||||
			response: {
 | 
								response: {
 | 
				
			||||||
				200: t.Union([MovieWatchStatus, DbMetadata]),
 | 
									200: t.Intersect([MovieWatchStatus, DbMetadata]),
 | 
				
			||||||
				404: KError,
 | 
									404: KError,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			permissions: ["core.read"],
 | 
								permissions: ["core.read"],
 | 
				
			||||||
 | 
				
			|||||||
@ -67,6 +67,21 @@ describe("Set & get watch status", () => {
 | 
				
			|||||||
		});
 | 
							});
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						it("Can filter watchlist", async () => {
 | 
				
			||||||
 | 
							let [resp, body] = await getWatchlist("me", {
 | 
				
			||||||
 | 
								filter: "watchStatus eq rewatching",
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							expectStatus(resp, body).toBe(200);
 | 
				
			||||||
 | 
							expect(body.items).toBeArrayOfSize(1);
 | 
				
			||||||
 | 
							expect(body.items[0].slug).toBe(bubble.slug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[resp, body] = await getWatchlist("me", {
 | 
				
			||||||
 | 
								filter: "watchStatus eq completed",
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							expectStatus(resp, body).toBe(200);
 | 
				
			||||||
 | 
							expect(body.items).toBeArrayOfSize(0);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	it("Return watchstatus in /shows", async () => {
 | 
						it("Return watchstatus in /shows", async () => {
 | 
				
			||||||
		const [resp, body] = await getShows({});
 | 
							const [resp, body] = await getShows({});
 | 
				
			||||||
		expectStatus(resp, body).toBe(200);
 | 
							expectStatus(resp, body).toBe(200);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user