From 4442468119a8b70aa9488d20abffa4bf03709bf1 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Mon, 10 May 2021 18:12:31 +0000 Subject: [PATCH] Add utility function to convert movie tickets to movies --- services/request/src/utils.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 services/request/src/utils.ts diff --git a/services/request/src/utils.ts b/services/request/src/utils.ts new file mode 100644 index 0000000..6cbdd2a --- /dev/null +++ b/services/request/src/utils.ts @@ -0,0 +1,23 @@ +import { IMovie } from "@autoplex-api/request"; +import { MovieTicket } from "@autoplex/database"; +import { PlexIpc } from "services"; +import Application from "./Application"; + +/** + * Convert a MovieTicket entity to a serialized IMovie object + */ +export async function convertTicketsToMovies(tickets: MovieTicket[]) { + let plex = Application.instance().service("Plex"); + let plexLinks = await plex.movieLinks(tickets.map(ticket => ticket.tmdbId)); + return tickets.map((ticket) => { + backdropPath : ticket.info?.backdropPath ?? null, + originalLanguage: ticket.info?.originalLanguage ?? null, + originalTitle : ticket.info?.originalTitle ?? null, + overview : ticket.info?.overview ?? null, + posterPath : ticket.info?.posterPath ?? null, + releaseDate : ticket.info?.releaseDate ?? null, + title : ticket.title, + plexLink : plexLinks[ticket.tmdbId], + tmdbId : ticket.tmdbId + }); +}