From feec8d80916eeee48cf65598f8d3838ed7d6f414 Mon Sep 17 00:00:00 2001 From: djdembeck Date: Sat, 19 Aug 2023 15:58:06 -0500 Subject: [PATCH] feat(schema): :sparkles: use `adult` data from audible in form of `isAdult` This data already comes from Audible, might as well include it --- src/config/models/Book.ts | 2 ++ src/config/types.ts | 1 + src/helpers/books/audible/ApiHelper.ts | 1 + tests/datasets/audible/books/api.ts | 1 + tests/datasets/helpers/books.ts | 3 +++ 5 files changed, 8 insertions(+) diff --git a/src/config/models/Book.ts b/src/config/models/Book.ts index 0040f70a..7bf0c727 100644 --- a/src/config/models/Book.ts +++ b/src/config/models/Book.ts @@ -23,6 +23,7 @@ const bookSchema = schema( }) ), image: types.string(), + isAdult: types.boolean({ required: true }), language: types.string({ required: true }), narrators: types.array( types.object({ @@ -55,6 +56,7 @@ const bookSchema = schema( }, { defaults: { + isAdult: false, region: 'us' }, timestamps: true diff --git a/src/config/types.ts b/src/config/types.ts index 84dae5ef..3c8f3194 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -89,6 +89,7 @@ export const ApiBookSchema = z.object({ formatType: z.string(), genres: z.array(ApiGenreSchema).optional(), image: z.string().url().optional(), + isAdult: z.boolean().default(false), language: z.string(), narrators: z.array(ApiNarratorOnBookSchema).optional(), publisherName: z.string(), diff --git a/src/helpers/books/audible/ApiHelper.ts b/src/helpers/books/audible/ApiHelper.ts index 20c6c96a..02c437bc 100644 --- a/src/helpers/books/audible/ApiHelper.ts +++ b/src/helpers/books/audible/ApiHelper.ts @@ -280,6 +280,7 @@ class ApiHelper { genres: [...this.getGenres(), ...this.getTags()] }), image: this.getHighResImage(), + isAdult: this.audibleResponse.is_adult_product, language: this.audibleResponse.language, narrators: this.audibleResponse.narrators?.map((person: ApiNarratorOnBook) => { diff --git a/tests/datasets/audible/books/api.ts b/tests/datasets/audible/books/api.ts index 06556121..257d2968 100644 --- a/tests/datasets/audible/books/api.ts +++ b/tests/datasets/audible/books/api.ts @@ -854,6 +854,7 @@ export const minimalB0036I54I6: ApiBook = { { asin: '18574505011', name: 'Poetry', type: 'tag' } ], image: 'https://m.media-amazon.com/images/I/41dNQts9Z7L.jpg', + isAdult: false, language: 'english', narrators: [], publisherName: 'Stanford Audio', diff --git a/tests/datasets/helpers/books.ts b/tests/datasets/helpers/books.ts index 25560774..b923565d 100644 --- a/tests/datasets/helpers/books.ts +++ b/tests/datasets/helpers/books.ts @@ -20,6 +20,7 @@ const description = 'On the edge of the galaxy, a diplomatic mission to an alien planet takes a turn when the Legionnaires, an elite special fighting force, find themselves ambushed and stranded behind enemy lines. They struggle to survive under siege, waiting on a rescue that might never come....' const formatType = 'unabridged' const image = 'https://m.media-amazon.com/images/I/91spdScZuIL.jpg' +const isAdult = false const language = 'english' const narrators = [ { @@ -370,6 +371,7 @@ export const changedParsedBook: ApiBook = { description, formatType, image, + isAdult, language, narrators, publisherName, @@ -412,6 +414,7 @@ export const parsedBookWithoutGenres: ApiBook = { description, formatType, image, + isAdult, language, narrators, publisherName,