feat(api): update existing artists in MusicLibrary

This commit is contained in:
Julian Tölle 2021-11-21 15:53:27 +01:00
parent a0c28e2324
commit a0ffe108e1
11 changed files with 176 additions and 1 deletions

View file

@ -12,6 +12,7 @@ import { FindAlbumDto } from "./dto/find-album.dto";
import { FindArtistDto } from "./dto/find-artist.dto";
import { FindGenreDto } from "./dto/find-genre.dto";
import { FindTrackDto } from "./dto/find-track.dto";
import { UpdateArtistDto } from "./dto/update-artist.dto";
import { Genre } from "./genre.entity";
import { GenreRepository } from "./genre.repository";
import { Track } from "./track.entity";
@ -32,6 +33,17 @@ export class MusicLibraryService {
});
}
async getArtistWithOldestUpdate(): Promise<Artist | undefined> {
const [oldestArtist] = await this.artistRepository.find({
take: 1,
order: {
updatedAt: "ASC",
},
});
return oldestArtist;
}
async createArtist(data: CreateArtistDto): Promise<Artist> {
const artist = this.artistRepository.create();
@ -57,6 +69,17 @@ export class MusicLibraryService {
return artist;
}
async updateArtist({
artist,
updatedFields,
}: UpdateArtistDto): Promise<Artist> {
artist.name = updatedFields.name;
artist.genres = updatedFields.genres;
artist.updatedAt = new Date();
return this.artistRepository.save(artist);
}
async findAlbum(query: FindAlbumDto): Promise<Album | undefined> {
return this.albumRepository.findOne({
where: { spotify: { id: query.spotify.id } },