diff --git a/src/models/generated/schemasPublic.d.ts b/src/models/generated/schemasPublic.d.ts index abf1e69c..77513f1d 100644 --- a/src/models/generated/schemasPublic.d.ts +++ b/src/models/generated/schemasPublic.d.ts @@ -159,9 +159,37 @@ export interface FindTextReuseClustersResponse { */ export interface Newspaper { /** - * The unique identifier of the newspaper + * The unique identifier of the newspaper. */ uid: string; + /** + * The title of the newspaper. + */ + title: string; + /** + * The year of the first available article in the newspaper. + */ + startYear?: number; + /** + * The year of the last available article in the newspaper. + */ + endYear?: number; + /** + * ISO 639-1 codes of languages used in the newspaper. + */ + languageCodes: string[]; + /** + * Total number of articles in the newspaper. + */ + totalArticles: number; + /** + * Total number of issues in the newspaper. + */ + totalIssues: number; + /** + * Total number of pages in the newspaper. + */ + totalPages: number; } diff --git a/src/schema/schemasPublic/Newspaper.json b/src/schema/schemasPublic/Newspaper.json index d48277a1..a23bb631 100644 --- a/src/schema/schemasPublic/Newspaper.json +++ b/src/schema/schemasPublic/Newspaper.json @@ -7,8 +7,44 @@ "properties": { "uid": { "type": "string", - "description": "The unique identifier of the newspaper" + "description": "The unique identifier of the newspaper." + }, + "title": { + "type": "string", + "description": "The title of the newspaper." + }, + "startYear": { + "type": "number", + "description": "The year of the first available article in the newspaper.", + "minimum": 0 + }, + "endYear": { + "type": "number", + "description": "The year of the last available article in the newspaper.", + "minimum": 0 + }, + "languageCodes": { + "type": "array", + "description": "ISO 639-1 codes of languages used in the newspaper.", + "items": { + "type": "string" + } + }, + "totalArticles": { + "type": "number", + "description": "Total number of articles in the newspaper.", + "minimum": 0 + }, + "totalIssues": { + "type": "number", + "description": "Total number of issues in the newspaper.", + "minimum": 0 + }, + "totalPages": { + "type": "number", + "description": "Total number of pages in the newspaper.", + "minimum": 0 } }, - "required": ["uid"] + "required": ["uid", "title", "languageCodes", "totalArticles", "totalIssues", "totalPages"] } diff --git a/src/services/newspapers/newspapers.hooks.js b/src/services/newspapers/newspapers.hooks.js index fbce8764..84db942e 100644 --- a/src/services/newspapers/newspapers.hooks.js +++ b/src/services/newspapers/newspapers.hooks.js @@ -1,6 +1,9 @@ import { authenticateAround as authenticate } from '../../hooks/authenticate' import { rateLimit } from '../../hooks/rateLimiter' import { OrderByChoices } from './newspapers.schema' +import { transformResponseDataItem } from '../../hooks/transformation' +import { inPublicApi } from '../../hooks/redaction' +import { transformNewspaper } from '../../transformers/newspaper' const { queryWithCommonParams, validate, utils } = require('../../hooks/params') const { checkCachedContents, returnCachedContents, saveResultsInCache } = require('../../hooks/redis') @@ -66,7 +69,7 @@ module.exports = { after: { all: [returnCachedContents(), saveResultsInCache()], - find: [], + find: [transformResponseDataItem(transformNewspaper, inPublicApi)], get: [], create: [], update: [], diff --git a/src/transformers/newspaper.ts b/src/transformers/newspaper.ts new file mode 100644 index 00000000..df584956 --- /dev/null +++ b/src/transformers/newspaper.ts @@ -0,0 +1,15 @@ +import { Newspaper as NewspaperInternal } from '../models/generated/schemas' +import { Newspaper as NewspaperPublic } from '../models/generated/schemasPublic' + +export const transformNewspaper = (input: NewspaperInternal): NewspaperPublic => { + return { + uid: input.uid, + title: input.name, + startYear: input.startYear ?? undefined, + endYear: input.endYear ?? undefined, + languageCodes: input.languages, + totalArticles: input.countArticles >= 0 ? input.countArticles : 0, + totalIssues: input.countIssues >= 0 ? input.countIssues : 0, + totalPages: input.countPages >= 0 ? input.countPages : 0, + } +}