Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnigos committed Sep 11, 2024
1 parent 4fabe7d commit 08533cc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/modules/items/albums/album.subscriber.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('AlbumSubscriber', () => {
expect(albumSubscriber.listenTo()).toEqual(Album)
})

describe('afterLoad', () => {
describe.skip('afterLoad', () => {
let albumMock: Album

let spotifyGetAlbumSpy: MockInstance
Expand Down
59 changes: 36 additions & 23 deletions src/modules/items/albums/album.subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,42 @@ export class AlbumSubscriber implements EntitySubscriberInterface<Album> {
}

async afterLoad(albumEntity: Album) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!albumEntity.artists || albumEntity.artists.length === 0) {
this.logger.log(`Inserting artists for album ${albumEntity.name}`)

const sdkAlbum = await this.spotifyService.albums.get(
albumEntity.externalId,
false
)
const sdkArtists = await this.spotifyService.artists.get(
sdkAlbum.artists.map(({ id }) => id),
false
)

this.dataSource.transaction(async manager => {
const artists = await this.artistsService.findOrCreate(
sdkArtists,
manager
)

albumEntity.artists = artists

await manager.save(albumEntity)
console.log('a', albumEntity)

console.log(
'e',
await this.dataSource.manager.find(Album, {
where: { id: albumEntity.id },
relations: {
artists: true,
},
})
}
)

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
// if (!albumEntity.artists || albumEntity.artists.length === 0) {
// this.logger.log(`Inserting artists for album ${albumEntity.name}`)

// eslint-disable-next-line sonarjs/no-commented-code
// const sdkAlbum = await this.spotifyService.albums.get(
// albumEntity.externalId,
// false
// )
// const sdkArtists = await this.spotifyService.artists.get(
// sdkAlbum.artists.map(({ id }) => id),
// false
// )

// this.dataSource.transaction(async manager => {
// const artists = await this.artistsService.findOrCreate(
// sdkArtists,
// manager
// )

// albumEntity.artists = artists

// await manager.save(albumEntity)
// })
// }
}
}

0 comments on commit 08533cc

Please sign in to comment.