feat(api): fetch listens from spotify

This commit is contained in:
Julian Tölle 2020-02-02 19:21:58 +01:00
parent f253a66f86
commit f2065d3f1f
54 changed files with 1180 additions and 256 deletions

View file

@ -2,6 +2,7 @@ import { Injectable, NotFoundException } from "@nestjs/common";
import { CreateOrUpdateDto } from "./dto/create-or-update.dto";
import { User } from "./user.entity";
import { UserRepository } from "./user.repository";
import { SpotifyConnection } from "src/sources/spotify/spotify-connection.entity";
@Injectable()
export class UsersService {
@ -17,6 +18,10 @@ export class UsersService {
return user;
}
async findAll(): Promise<User[]> {
return this.userRepository.find();
}
async createOrUpdate(data: CreateOrUpdateDto): Promise<User> {
let user = await this.userRepository.findOne({
where: { spotify: { id: data.spotify.id } }
@ -39,4 +44,12 @@ export class UsersService {
return user;
}
async updateSpotifyConnection(
user: User,
spotify: SpotifyConnection
): Promise<void> {
user.spotify = spotify;
await this.userRepository.save(user);
}
}