Skip to content

Commit

Permalink
fix update playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelillah committed Jul 5, 2022
1 parent f9aaabd commit b945022
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/playlists/playlists.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ export class PlaylistsService {
this.logger.log(`Updating playlist ${id}`);
isValidId(id);
const playlist = await this.isUserTheOwnerOfPlaylist(id, owner);
const response = await this.findPlaylistById(id).then((playlist) =>
const duplicates = await this.findPlaylistById(id).then((playlist) =>
playlist.tracks.filter(
(track) => track._id.toString() !== updatePlaylistDto.trackId,
(track) => track._id.toString() === updatePlaylistDto.trackId,
),
);
if (response.length === 0) {
if (
updatePlaylistDto.action === PlaylistUpdateTaskAction.Add &&
duplicates.length > 0
) {
return {
id: playlist._id.toString(),
msg: 'Track already in playlist',
Expand Down Expand Up @@ -164,7 +167,7 @@ export class PlaylistsService {
(track) => track._id.toString() !== trackToUpdate._id.toString(),
);
default:
throw new BadRequestException('Action not found.');
throw new NotFoundException('Action not found.');
}
}

Expand Down

0 comments on commit b945022

Please sign in to comment.