diff --git a/backend/src/album/album.controller.ts b/backend/src/album/album.controller.ts index 2eb97c1..110d1bc 100644 --- a/backend/src/album/album.controller.ts +++ b/backend/src/album/album.controller.ts @@ -26,7 +26,7 @@ export class AlbumController { @Put() async update(@Param('id') id: number, @Body() updateAlbumDto: UpdateAlbumDto): Promise { - return this.albumService.update(updateAlbumDto); + return this.albumService.update(id, updateAlbumDto); } @Delete(':id') diff --git a/backend/src/album/album.entity.ts b/backend/src/album/album.entity.ts index a6a214d..6e2be92 100644 --- a/backend/src/album/album.entity.ts +++ b/backend/src/album/album.entity.ts @@ -15,6 +15,6 @@ export class Album { @Column() genre: string - @OneToMany(() => Song, (song) => song.album, { eager: true }) + @OneToMany(() => Song, (song) => song.album, { eager: true, onDelete: 'CASCADE' }) songs: Song[] } diff --git a/backend/src/song/song.controller.ts b/backend/src/song/song.controller.ts index ff5a56e..df0ff9f 100644 --- a/backend/src/song/song.controller.ts +++ b/backend/src/song/song.controller.ts @@ -25,8 +25,8 @@ export class SongController { } @Put() - async update(@Body() updateSongDto: UpdateSongDto): Promise { - return this.songService.update(updateSongDto); + async update(@Param('id') id: number, @Body() updateSongDto: UpdateSongDto): Promise { + return this.songService.update(id, updateSongDto); } @Delete(':id') diff --git a/backend/src/song/song.service.ts b/backend/src/song/song.service.ts index c70731c..58809c1 100644 --- a/backend/src/song/song.service.ts +++ b/backend/src/song/song.service.ts @@ -30,15 +30,19 @@ export class SongService { } async update(updateSongDto: UpdateSongDto): Promise { - const song = this.songRepository.findOneBy({ id: updateSongDto.id }); - if (!song) - return "Song not found"; + if (id === updateSongDto.id) { + const song = this.songRepository.findOneBy({ id: updateSongDto.id }); + if (!song) + return "Song not found"; - await this.songRepository.update({ id: updateSongDto.id }, { - title: updateSongDto.title, - duration: updateSongDto.duration - }); - return "Song updated successfully"; + await this.songRepository.update({ id: updateSongDto.id }, { + title: updateSongDto.title, + duration: updateSongDto.duration + }); + return "Song updated successfully"; + } else { + return "Song ID does not match posted data" + } } async remove(id: number): Promise {