Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error with unique album constraint #216

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

Mnigos
Copy link
Member

@Mnigos Mnigos commented Apr 21, 2024

  • implement findOrCreate method with ids in tracksService
    needed in:

findOrCreateAlbumFromExternalId

 if (foundAlbum?.tracks && foundAlbum.tracks.length > 0) {
    const tracks = await this.tracksService.create(
                                            ^^^^^^ => `findOrCreate`
      albumToCreate.tracks.items.map(track => track.id),
      [foundAlbum]
    )
    
    foundAlbum.tracks = tracks
    
    return this.albumsRepository.save(foundAlbum)
  }

findOrCreateAlbumFromExternalId

    for (const foundAlbum of foundAlbums) {
      const albumToCreate = fetchedAlbums.find(
        ({ id }) => id === foundAlbum.externalId
      )

      if (foundAlbum.tracks && foundAlbum.tracks.length > 0 && albumToCreate) {
        await this.tracksService.create(
                                 ^^^^^^ => `findOrCreate`
          albumToCreate.tracks.items.map(track => track.id),
          [foundAlbum]
        )
      }
    }
  • save album with new tracks
      if (foundAlbum.tracks && foundAlbum.tracks.length > 0 && albumToCreate) {
        await this.tracksService.create(
          albumToCreate.tracks.items.map(track => track.id),
          [foundAlbum]
        )
      }
  • filter albums before creating tracks
    by externalId and tracks length

@Mnigos Mnigos self-assigned this Apr 21, 2024
@Mnigos Mnigos requested a review from Iqro-dev April 21, 2024 19:43
@Mnigos Mnigos added the bug Something isn't working label Apr 21, 2024
Copy link

codecov bot commented Apr 21, 2024

Codecov Report

Attention: Patch coverage is 47.61905% with 33 lines in your changes are missing coverage. Please review.

Project coverage is 85.61%. Comparing base (c2c8924) to head (aa24838).

❗ Current head aa24838 differs from pull request most recent head 57d6c41. Consider uploading reports for the commit 57d6c41 to get more accurate results

Files Patch % Lines
src/modules/tracks/tracks.service.ts 23.25% 33 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #216      +/-   ##
==========================================
- Coverage   86.46%   85.61%   -0.85%     
==========================================
  Files          53       53              
  Lines        3014     3066      +52     
  Branches      388      392       +4     
==========================================
+ Hits         2606     2625      +19     
- Misses        408      441      +33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Mnigos Mnigos force-pushed the 213-fix-error-with-unique-constraint-album_unique branch from f92317f to aa24838 Compare April 22, 2024 13:37
@Mnigos Mnigos marked this pull request as ready for review April 22, 2024 13:39
@Mnigos Mnigos force-pushed the 213-fix-error-with-unique-constraint-album_unique branch from aa24838 to 57d6c41 Compare April 22, 2024 13:51
@Mnigos Mnigos merged commit 2d18115 into main Apr 22, 2024
3 checks passed
@Mnigos Mnigos deleted the 213-fix-error-with-unique-constraint-album_unique branch April 22, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants