mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Implement routes in /shows
This commit is contained in:
parent
8d7d5f3e7e
commit
7e6592fa2e
@ -1,12 +1,21 @@
|
|||||||
import { sql } from "drizzle-orm";
|
import { and, eq, sql } from "drizzle-orm";
|
||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import { staff } from "~/db/schema/staff";
|
import { staff } from "~/db/schema/staff";
|
||||||
import { KError } from "~/models/error";
|
import { KError } from "~/models/error";
|
||||||
import { Role, Staff } from "~/models/staff";
|
import { Role, Staff } from "~/models/staff";
|
||||||
import { Filter, Page, Sort } from "~/models/utils";
|
import {
|
||||||
|
Page,
|
||||||
|
Sort,
|
||||||
|
createPage,
|
||||||
|
isUuid,
|
||||||
|
keysetPaginate,
|
||||||
|
sortToSql,
|
||||||
|
} from "~/models/utils";
|
||||||
import { desc } from "~/models/utils/descriptions";
|
import { desc } from "~/models/utils/descriptions";
|
||||||
|
|
||||||
|
const staffSort = Sort(["slug", "name", "latinName"], { default: ["slug"] });
|
||||||
|
|
||||||
export const staffH = new Elysia({ tags: ["staff"] })
|
export const staffH = new Elysia({ tags: ["staff"] })
|
||||||
.model({
|
.model({
|
||||||
staff: Staff,
|
staff: Staff,
|
||||||
@ -14,8 +23,19 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
|||||||
})
|
})
|
||||||
.get(
|
.get(
|
||||||
"/staff/:id",
|
"/staff/:id",
|
||||||
async ({ params: { id }, error, set }) => {
|
async ({ params: { id }, error }) => {
|
||||||
throw new Error();
|
const [ret] = await db
|
||||||
|
.select()
|
||||||
|
.from(staff)
|
||||||
|
.where(isUuid(id) ? eq(staff.id, id) : eq(staff.slug, id))
|
||||||
|
.limit(1);
|
||||||
|
if (!ret) {
|
||||||
|
return error(404, {
|
||||||
|
status: 404,
|
||||||
|
message: `No staff found with the id or slug: '${id}'`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
detail: {
|
detail: {
|
||||||
@ -69,14 +89,31 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
|||||||
)
|
)
|
||||||
.get(
|
.get(
|
||||||
"/staff",
|
"/staff",
|
||||||
async ({ query: { limit, after, query }, request: { url } }) => {
|
async ({ query: { limit, after, sort, query }, request: { url } }) => {
|
||||||
throw new Error();
|
const items = await db
|
||||||
|
.select()
|
||||||
|
.from(staff)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
query ? sql`${staff.name} %> ${query}::text` : undefined,
|
||||||
|
keysetPaginate({ table: staff, after, sort }),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.orderBy(
|
||||||
|
...(query
|
||||||
|
? [sql`word_similarity(${query}::text, ${staff.name})`]
|
||||||
|
: sortToSql(sort, staff)),
|
||||||
|
staff.pk,
|
||||||
|
)
|
||||||
|
.limit(limit);
|
||||||
|
return createPage(items, { url, sort, limit });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
detail: {
|
detail: {
|
||||||
description: "Get all staff members known by kyoo.",
|
description: "Get all staff members known by kyoo.",
|
||||||
},
|
},
|
||||||
query: t.Object({
|
query: t.Object({
|
||||||
|
sort: staffSort,
|
||||||
query: t.Optional(t.String({ description: desc.query })),
|
query: t.Optional(t.String({ description: desc.query })),
|
||||||
limit: t.Integer({
|
limit: t.Integer({
|
||||||
minimum: 1,
|
minimum: 1,
|
||||||
|
@ -138,7 +138,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
|
|||||||
if (!ret) {
|
if (!ret) {
|
||||||
return error(404, {
|
return error(404, {
|
||||||
status: 404,
|
status: 404,
|
||||||
message: `No studio with the id or slug: '${id}'`,
|
message: `No studio found with the id or slug: '${id}'`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!ret.language) {
|
if (!ret.language) {
|
||||||
|
@ -3,7 +3,7 @@ import { DbMetadata, ExternalId, Image, Resource } from "./utils";
|
|||||||
|
|
||||||
export const Character = t.Object({
|
export const Character = t.Object({
|
||||||
name: t.String(),
|
name: t.String(),
|
||||||
latinName: t.String(),
|
latinName: t.Nullable(t.String()),
|
||||||
image: t.Nullable(Image),
|
image: t.Nullable(Image),
|
||||||
});
|
});
|
||||||
export type Character = typeof Character.static;
|
export type Character = typeof Character.static;
|
||||||
@ -25,7 +25,7 @@ export const Staff = t.Intersect([
|
|||||||
Resource(),
|
Resource(),
|
||||||
t.Object({
|
t.Object({
|
||||||
name: t.String(),
|
name: t.String(),
|
||||||
latinName: t.String(),
|
latinName: t.Nullable(t.String()),
|
||||||
image: t.Nullable(Image),
|
image: t.Nullable(Image),
|
||||||
externalId: ExternalId(),
|
externalId: ExternalId(),
|
||||||
}),
|
}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user