Kyoo/src/app/misc/items-utils.ts
2021-08-06 12:08:21 +02:00

34 lines
1.0 KiB
TypeScript

import { ItemType, LibraryItem } from "../models/resources/library-item";
import { Show, ShowRole } from "../models/resources/show";
import { Collection } from "../models/resources/collection";
import { People } from "../models/resources/people";
export class ItemsUtils
{
static getLink(item: LibraryItem | Show | ShowRole | Collection): string
{
if ("type" in item && item.type === ItemType.Collection)
return "/collection/" + item.slug;
else
return "/show/" + item.slug;
}
static getDate(item: LibraryItem | Show | ShowRole | Collection | People): string
{
if ("role" in item && item.role)
{
if ("type" in item && item.type)
return `as ${item.role} (${item.type})`;
return `as ${item.role}`;
}
if ("type" in item && item.type && typeof item.type === "string")
return item.type;
if (!("startAir" in item))
return "";
if (item.endAir && item.startAir?.getFullYear() !== item.endAir.getFullYear())
return `${item.startAir.getFullYear()} - ${item.endAir.getFullYear()}`;
return item.startAir?.getFullYear().toString();
}
}