Skip to content

Commit

Permalink
feat: add CompanyType
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Aug 4, 2020
2 parents 1241e5e + 84fe8b0 commit 10ecfa6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/Tmdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
MovieType,
MovieVideoType,
PersonType,
CompanyType,
} from './types';

type QueryType = {
Expand Down Expand Up @@ -158,6 +159,14 @@ class Tmdb {
return person;
}

async getCompany (companyId: number): Promise<CompanyType> {
const company = await this.get('company/' + companyId, {
language: this.language,
});

return company;
}

async findId (resourceType: 'movie' | 'person', externalSource: 'imdb', externalId: string): Promise<number> {
if (resourceType !== 'movie' && resourceType !== 'person') {
throw new Unimplemented();
Expand Down
9 changes: 5 additions & 4 deletions src/bin/generate-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
} from 'lodash';

const typeMap = {
CompanyType: (data) => {
return data.paths['/company/{company_id}'].get.responses['200'].schema.properties;
},
ImagePathType: (data) => {
return data.definitions['image-path'].type;
},
Expand Down Expand Up @@ -121,9 +124,7 @@ const getPropertyFlowType = (property: Object) => {
};

const run = async () => {
const oas = await got('https://api.stoplight.io/v1/versions/9WaNJfGpnnQ76opqe/export/oas.json', {
json: true,
});
const oas = await got('https://api.stoplight.io/v1/versions/9WaNJfGpnnQ76opqe/export/oas.json').json();

for (const typeName of typeNames) {
const resourceResolver = typeMap[typeName];
Expand All @@ -132,7 +133,7 @@ const run = async () => {
throw new Error('Unexpected state.');
}

const typeDefinition = resourceResolver(oas.body);
const typeDefinition = resourceResolver(oas);

if (!typeDefinition) {
throw new Error('Unexpected state.');
Expand Down
11 changes: 11 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,14 @@ export type PersonType = {|
+popularity: number,
+profilePath: ImagePathType,
|};

export type CompanyType = {|
+description: string,
+headquarters: string,
+homepage: string,
+id: number,
+logoPath: string,
+name: string,
+originCountry: string,
+parentCompany: null | CompanyType,
|};

0 comments on commit 10ecfa6

Please sign in to comment.