diff --git a/src/task/imdbTask.ts b/src/task/imdbTask.ts index 22222d3..4ed0c87 100644 --- a/src/task/imdbTask.ts +++ b/src/task/imdbTask.ts @@ -5,7 +5,6 @@ import Movie from "../models/movie"; export async function updateImdbInfo() { let movieInfos = await getNewImdbInfos(); - removeEmptyInfos(movieInfos); logResult(movieInfos); return updateYahooMovies(movieInfos); } @@ -33,13 +32,6 @@ function filterNeedCrawlMovie({ englishTitle, releaseDate, imdbLastCrawlTime }: return shouldCrawl; } -function removeEmptyInfos(movieInfos: Movie[]){ - movieInfos.forEach(info=>{ - !info.imdbID && delete info.imdbID; - !info.imdbRating && delete info.imdbRating; - }) -} - function logResult(movieInfos: Movie[]) { const foundMovies = movieInfos.filter(movie => movie.imdbID); const notfoundMovieIds = movieInfos.filter(movie => !movie.imdbID).map(movie => movie.yahooId); @@ -48,5 +40,8 @@ function logResult(movieInfos: Movie[]) { } function updateYahooMovies(movieInfos: Movie[]) { - return movieInfos.map(imdbInfo => db.updateDocument({ yahooId: imdbInfo.yahooId }, imdbInfo, "yahooMovies")) + return movieInfos.map(({ yahooId, imdbID, imdbRating, imdbLastCrawlTime }) => { + const newInfo = imdbID ? { imdbID, imdbRating, imdbLastCrawlTime } : { imdbLastCrawlTime } + return db.updateDocument({ yahooId }, newInfo, "yahooMovies") + }) } \ No newline at end of file diff --git a/src/test/imdbTask.test.ts b/src/test/imdbTask.test.ts index a6c2787..aeea90f 100644 --- a/src/test/imdbTask.test.ts +++ b/src/test/imdbTask.test.ts @@ -44,7 +44,7 @@ describe('imdbTask', () => { await updateImdbInfo(); sandbox.assert.calledWith(stubUpdateDocument, { yahooId: yahooMovie.yahooId }, - { yahooId: yahooMovie.yahooId, imdbLastCrawlTime: moment().format('YYYY-MM-DDTHH') }); + { imdbLastCrawlTime: moment().format('YYYY-MM-DDTHH') }); }); }); }); \ No newline at end of file