Skip to content

Commit bebef58

Browse files
feat: Created the single person lookup without the credits functionality and fixed an issue where some social links weren't always available or empty.
1 parent 5991d28 commit bebef58

File tree

10 files changed

+74
-47
lines changed

10 files changed

+74
-47
lines changed

src/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Module } from '@nestjs/common';
33
import { GraphQLModule } from '@nestjs/graphql';
44

55
import { MovieModule } from './movie/movie.module';
6+
import { PersonModule } from './person/person.module';
67
import { ShowModule } from './show/show.module';
78

89
@Module({
@@ -37,7 +38,8 @@ import { ShowModule } from './show/show.module';
3738
]
3839
}),
3940
ShowModule,
40-
MovieModule
41+
MovieModule,
42+
PersonModule
4143
]
4244
})
4345
export class AppModule {}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* eslint-disable import/extensions */
22
import { HttpModule } from '@nestjs/axios';
33
import { Module } from '@nestjs/common';
4-
import { UtilsModule } from 'src/utils/utils.module';
54

65
import { EntertainmentService } from './entertainment.service';
6+
import { SocialsModule } from '../socials/socials.module';
7+
import { UtilsModule } from '../utils/utils.module';
78

89
@Module({
910
providers: [EntertainmentService],
1011
exports: [EntertainmentService],
11-
imports: [HttpModule, UtilsModule]
12+
imports: [HttpModule, UtilsModule, SocialsModule]
1213
})
1314
export class EntertainmentModule {}

src/entertainment/entertainment.service.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {
1717
TheOpenMovieDatabaseBelongsToCollection,
1818
TheOpenMovieDatabaseSpokenLanguages
1919
} from 'src/movie/movie';
20+
import { SocialsService } from 'src/socials/socials.service';
2021
import { UtilsService } from 'src/utils/utils.service';
2122

2223
import {
2324
ICreditsQueryResponse,
24-
IExternalIdsQueryResponse,
2525
IKeywordsQueryResponse,
2626
IReviewQuery,
2727
IVdoesQueryResponse
@@ -37,7 +37,8 @@ interface IEntertainmentCommonArguments {
3737
export class EntertainmentService {
3838
constructor(
3939
private readonly httpService: HttpService,
40-
private readonly utilService: UtilsService
40+
private readonly utilService: UtilsService,
41+
private readonly socialsService: SocialsService
4142
) {}
4243

4344
async getReview({
@@ -198,26 +199,10 @@ export class EntertainmentService {
198199
entertainmentType,
199200
entertainmentId
200201
}: IEntertainmentCommonArguments): Promise<Social> {
201-
const { data } = await firstValueFrom(
202-
this.httpService.get<IExternalIdsQueryResponse>(
203-
`https://api.themoviedb.org/3/${entertainmentType.toLowerCase()}/${entertainmentId}/external_ids?language=en-U`,
204-
{
205-
headers: {
206-
Accept: 'application/json',
207-
Authorization:
208-
// eslint-disable-next-line max-len
209-
'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI1NDMwNWQxNmE1ZThkN2E3ZWMwZmM2NTk5MzZiY2EzMCIsInN1YiI6IjViMzE0MjQ1OTI1MTQxM2M5MTAwNTIwNCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.iqdLKFCSgeWG3SYso7Rqj297FORviPf9hDdn2kKygTA'
210-
}
211-
}
212-
)
213-
);
214-
215-
return {
216-
facebook: `https://www.facebook.com/${data.facebook_id}`,
217-
homepage: ``,
218-
instagram: `https://www.instagram.com/${data.facebook_id}`.toLowerCase(),
219-
twitter: `https://www.twitter.com/${data.twitter_id}`
220-
};
202+
return this.socialsService.getSocials({
203+
resourceId: entertainmentId,
204+
resourceType: entertainmentType
205+
});
221206
}
222207

223208
getCollection = (

src/entertainment/entertainment.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ export interface IKeywordsQueryResponse {
5454
keywords: Keyword[];
5555
}
5656

57-
export interface IExternalIdsQueryResponse {
58-
id: number;
59-
imdb_id: string;
60-
wikidata_id: string;
61-
facebook_id: string;
62-
instagram_id: string;
63-
twitter_id: string;
64-
}
65-
6657
export interface IVideosQueryResult {
6758
iso_639_1: string;
6859
iso_3166_1: string;

src/graphql.schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface IQuery {
9999
__typename?: 'IQuery';
100100
movie(id: number): Nullable<Movie> | Promise<Nullable<Movie>>;
101101
show(id: number): Nullable<Show> | Promise<Nullable<Show>>;
102+
person(id: number): Nullable<Person> | Promise<Nullable<Person>>;
102103
}
103104

104105
export interface CurrentSeason {
@@ -223,6 +224,7 @@ export interface Social {
223224
instagram?: Nullable<string>;
224225
twitter?: Nullable<string>;
225226
homepage?: Nullable<string>;
227+
tiktok?: Nullable<string>;
226228
}
227229

228230
export interface Video {

src/models/Query.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
type Query {
22
movie(id: Int!): Movie
33
show(id: Int!): Show
4+
person(id: Int!): Person
45
}

src/models/entertainment/Social.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ type Social {
33
instagram: String
44
twitter: String
55
homepage: String
6+
tiktok: String
67
}

src/person/person.resolver.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
import { Resolver } from '@nestjs/graphql';
1+
import { Args, Parent, Query, ResolveField, Resolver } from '@nestjs/graphql';
22

3-
@Resolver()
4-
export class PersonResolver {}
3+
import { PersonService } from './person.service';
4+
import { Person } from '../graphql.schema';
5+
6+
// import { Person } from '../graphql.schema';
7+
8+
@Resolver('Person')
9+
export class PersonResolver {
10+
constructor(private readonly personService: PersonService) {}
11+
12+
@Query()
13+
async person(@Args('id') personId: number) {
14+
return this.personService.getPerson(personId);
15+
}
16+
17+
@ResolveField()
18+
async social(@Parent() person: Person) {
19+
// Get the external social url (The homepage isn't set here as it's already apart of the original Movie query)
20+
const socials = await this.personService.getSocials(person.id ?? 0);
21+
22+
return {
23+
...socials,
24+
25+
// Since the homepage is apart of the original query append it to the homepage property
26+
homepage: person.homepage
27+
};
28+
}
29+
}

src/person/person.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
33
import { firstValueFrom } from 'rxjs';
44

55
import { TheOpenMovieDatabasePerson, TheOpenMovieDatabasePersonGender } from './person';
6-
import { Person, Social } from '../graphql.schema';
76
import { SocialsService } from '../socials/socials.service';
87
import { UtilsService } from '../utils/utils.service';
98

@@ -61,7 +60,7 @@ export class PersonService {
6160
}
6261
}
6362

64-
async getPerson(personId: number): Promise<Person> {
63+
async getPerson(personId: number) {
6564
const { data } = await firstValueFrom(
6665
this.httpService.get<TheOpenMovieDatabasePerson>(
6766
`https://api.themoviedb.org/3/person/${personId}?language=en-U`,
@@ -90,7 +89,7 @@ export class PersonService {
9089
};
9190
}
9291

93-
async getSocials(personId: number): Promise<Social> {
92+
async getSocials(personId: number) {
9493
return this.socialService.getSocials({
9594
resourceId: personId,
9695
resourceType: 'PERSON'

src/socials/socials.service.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export class SocialsService {
1616
resourceType: ENTERTAINMENT_TYPES | 'PERSON';
1717
resourceId: number;
1818
}): Promise<Social> {
19-
console.log('getting socials..');
20-
2119
const { data } = await firstValueFrom(
2220
this.httpService.get<IExternalIdsQueryResponse>(
2321
`https://api.themoviedb.org/3/${resourceType.toLowerCase()}/${resourceId}/external_ids?language=en-U`,
@@ -32,12 +30,34 @@ export class SocialsService {
3230
)
3331
);
3432

33+
console.log('social', data);
34+
35+
let facebook = null;
36+
let instagram = null;
37+
let twitter = null;
38+
let tiktok = null;
39+
40+
if (data.facebook_id) {
41+
facebook = `https://www.facebook.com/${data.facebook_id}`;
42+
}
43+
44+
if (data.instagram_id) {
45+
instagram = `https://www.instagram.com/${data.instagram_id}`.toLowerCase();
46+
}
47+
48+
if (data.twitter_id) {
49+
twitter = `https://www.twitter.com/${data.twitter_id}`;
50+
}
51+
52+
if (data.tiktok_id) {
53+
tiktok = `https://www.tiktok.com/@${data.tiktok_id}/`;
54+
}
55+
3556
return {
36-
facebook: `https://www.facebook.com/${data.facebook_id}`,
37-
homepage: ``,
38-
instagram: `https://www.instagram.com/${data.instagram_id}`.toLowerCase(),
39-
twitter: `https://www.twitter.com/${data.twitter_id}`
40-
// tiktok: `https://www.tiktok.com/@${data.tiktok_id}/`
57+
facebook,
58+
instagram,
59+
twitter,
60+
tiktok
4161
};
4262
}
4363
}

0 commit comments

Comments
 (0)