Fixing update song
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Successful in 29s
Music Collection CI Workflow / test (./frontend) (push) Successful in 36s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Successful in 50s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Failing after 1m34s
Music Collection CI Workflow / deploy (push) Has been skipped
Some checks failed
Music Collection CI Workflow / test (./backend) (push) Successful in 29s
Music Collection CI Workflow / test (./frontend) (push) Successful in 36s
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Successful in 50s
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Failing after 1m34s
Music Collection CI Workflow / deploy (push) Has been skipped
This commit is contained in:
parent
e11c22f554
commit
d66d476acb
@ -12,27 +12,23 @@ export class AlbumController {
|
||||
|
||||
@Get()
|
||||
findAll(): Promise<Album[]> {
|
||||
console.log("AlbumController findAll")
|
||||
return this.albumService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOneById(@Param('id') id: number): Promise<Album | null> {
|
||||
console.log("AlbumController findOnyById: ",id);
|
||||
return this.albumService.findOneById(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async create(@Body() createAlbumDto: CreateAlbumDto): Promise<Album | null> {
|
||||
console.log("AlbumController create: ",createAlbumDto);
|
||||
return this.albumService.create(createAlbumDto);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async update(@Param('id') id: number, @Body() updateAlbumDto: UpdateAlbumDto): Promise<Album | null> {
|
||||
console.log("AlbumController update: ",id,updateAlbumDto);
|
||||
return this.albumService.update(id, updateAlbumDto);
|
||||
}
|
||||
|
||||
|
@ -43,23 +43,20 @@ export class AlbumService {
|
||||
}
|
||||
|
||||
async update(id: number, updateAlbumDto: UpdateAlbumDto): Promise<Album | null> {
|
||||
console.log(id, updateAlbumDto);
|
||||
if (id == updateAlbumDto.id) {
|
||||
const albumToUpdate = await this.albumRepository.findOneBy({ id: updateAlbumDto.id });
|
||||
if (!albumToUpdate) {
|
||||
console.log("Didn't find album: ", id);
|
||||
console.error("AlbumService: update: Didn't find album: ", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
albumToUpdate.title = updateAlbumDto.title;
|
||||
albumToUpdate.artist = updateAlbumDto.artist;
|
||||
albumToUpdate.genre = updateAlbumDto.genre;
|
||||
console.log("Saving album:", albumToUpdate);
|
||||
const savedAlbum = await this.albumRepository.save(albumToUpdate);
|
||||
console.log("Saved album: ", savedAlbum);
|
||||
return savedAlbum;
|
||||
} else {
|
||||
console.log("ids don't match", id, updateAlbumDto);
|
||||
console.error("AlbumService: update: IDs do not match", id, updateAlbumDto);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
logger: ['error', 'log', 'warn'],
|
||||
logger: ['error', 'warn'],
|
||||
});
|
||||
app.enableCors({
|
||||
origin: ['https://music.anatid.net'],
|
||||
|
@ -46,8 +46,10 @@ export class SongService {
|
||||
if (id == updateSongDto.id) {
|
||||
const album = await this.albumRepository.findOneBy({id: updateSongDto.albumId});
|
||||
const songToUpdate = await this.songRepository.findOneBy({ id: updateSongDto.id });
|
||||
if (!songToUpdate || !album)
|
||||
if (!songToUpdate || !album) {
|
||||
console.error("SongService: update: Song or Album not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
songToUpdate.id = updateSongDto.id;
|
||||
songToUpdate.title = updateSongDto.title;
|
||||
@ -57,6 +59,7 @@ export class SongService {
|
||||
const song = await this.songRepository.save(songToUpdate);
|
||||
return song;
|
||||
} else {
|
||||
console.error("SongService: update: IDs do not match");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ export async function updateSong(formData: FormData) {
|
||||
const title = formData.get('title');
|
||||
const duration = formData.get('duration');
|
||||
const trackNumber = formData.get('trackNumber');
|
||||
return fetch(`https://api.anatid.net/song/${id}`, {
|
||||
return fetch(`https://api.anatid.net/song/${album-id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
|
Loading…
x
Reference in New Issue
Block a user