Skip to content

Commit

Permalink
fix(route): 🐛 nothing could be returned when no genres existed; fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
djdembeck committed Mar 1, 2022
1 parent c2b65ea commit 093e2d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/config/routes/authors/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ async function routes (fastify, options) {
return findInDb
}
// Check state of existing author
if (findInDb.genres) {
// Only update if either genres exist and can be checked
// -or if genres exist on new item but not old
if (findInDb.genres || (!findInDb.genres && parseScraper.genres)) {
// Only update if it's not nuked data
if (parseScraper.genres && parseScraper.genres.length) {
console.log(`Updating asin ${request.params.asin}`)
Expand All @@ -107,6 +109,8 @@ async function routes (fastify, options) {
console.log(`Updating asin ${request.params.asin}`)
await updateAuthor()
}
// No update performed, return original
return findInDb
} else {
// Insert stitched data into DB
newDbItem = await Promise.resolve(
Expand Down
6 changes: 5 additions & 1 deletion src/config/routes/books/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ async function routes (fastify, options) {
return findInDb
}
// Check state of existing book
if (findInDb.genres) {
// Only update if either genres exist and can be checked
// -or if genres exist on new item but not old
if (findInDb.genres || (!findInDb.genres && stitchedData.genres)) {
// Only update if it's not nuked data
if (stitchedData.genres && stitchedData.genres.length) {
console.log(`Updating asin ${request.params.asin}`)
Expand All @@ -139,6 +141,8 @@ async function routes (fastify, options) {
console.log(`Updating asin ${request.params.asin}`)
await updateBook()
}
// No update performed, return original
return findInDb
} else {
// Insert stitched data into DB
newDbItem = await Promise.resolve(Book.insertOne(stitchedData))
Expand Down

0 comments on commit 093e2d7

Please sign in to comment.