diff --git a/src/sources/spotify/spotify-api/spotify-api.service.ts b/src/sources/spotify/spotify-api/spotify-api.service.ts index fb2855e..f071678 100644 --- a/src/sources/spotify/spotify-api/spotify-api.service.ts +++ b/src/sources/spotify/spotify-api/spotify-api.service.ts @@ -1,5 +1,6 @@ import { HttpService } from "@nestjs/axios"; import { Injectable } from "@nestjs/common"; +import { firstValueFrom } from "rxjs"; import { SpotifyConnection } from "../spotify-connection.entity"; import { AlbumObject } from "./entities/album-object"; import { ArtistObject } from "./entities/artist-object"; @@ -18,12 +19,15 @@ export class SpotifyApiService { limit: 50, }; - const history = await this.httpService - .get>(`v1/me/player/recently-played`, { - headers: { Authorization: `Bearer ${accessToken}` }, - params: parameters, - }) - .toPromise(); + const history = await firstValueFrom( + this.httpService.get>( + `v1/me/player/recently-played`, + { + headers: { Authorization: `Bearer ${accessToken}` }, + params: parameters, + } + ) + ); return history.data.items; } @@ -32,31 +36,30 @@ export class SpotifyApiService { accessToken: string, spotifyID: string ): Promise { - const artist = await this.httpService - .get(`v1/artists/${spotifyID}`, { + const artist = await firstValueFrom( + this.httpService.get(`v1/artists/${spotifyID}`, { headers: { Authorization: `Bearer ${accessToken}` }, }) - .toPromise(); + ); return artist.data; } async getAlbum(accessToken: string, spotifyID: string): Promise { - const album = await this.httpService - .get(`v1/albums/${spotifyID}`, { + const album = await firstValueFrom( + this.httpService.get(`v1/albums/${spotifyID}`, { headers: { Authorization: `Bearer ${accessToken}` }, }) - .toPromise(); - + ); return album.data; } async getTrack(accessToken: string, spotifyID: string): Promise { - const track = await this.httpService - .get(`v1/tracks/${spotifyID}`, { + const track = await firstValueFrom( + this.httpService.get(`v1/tracks/${spotifyID}`, { headers: { Authorization: `Bearer ${accessToken}` }, }) - .toPromise(); + ); return track.data; } diff --git a/src/sources/spotify/spotify-auth/spotify-auth.service.ts b/src/sources/spotify/spotify-auth/spotify-auth.service.ts index b4f1d7e..393f3d1 100644 --- a/src/sources/spotify/spotify-auth/spotify-auth.service.ts +++ b/src/sources/spotify/spotify-auth/spotify-auth.service.ts @@ -1,6 +1,7 @@ import { HttpService } from "@nestjs/axios"; import { Injectable } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; +import { firstValueFrom } from "rxjs"; import { SpotifyConnection } from "../spotify-connection.entity"; @Injectable() @@ -17,8 +18,8 @@ export class SpotifyAuthService { } async clientCredentialsGrant(): Promise { - const response = await this.httpService - .post<{ access_token: string }>( + const response = await firstValueFrom( + this.httpService.post<{ access_token: string }>( `api/token`, "grant_type=client_credentials", { @@ -28,14 +29,14 @@ export class SpotifyAuthService { }, } ) - .toPromise(); + ); return response.data.access_token; } async refreshAccessToken(connection: SpotifyConnection): Promise { - const response = await this.httpService - .post( + const response = await firstValueFrom( + this.httpService.post( `api/token`, `grant_type=refresh_token&refresh_token=${connection.refreshToken}`, { @@ -45,7 +46,7 @@ export class SpotifyAuthService { }, } ) - .toPromise(); + ); return response.data.access_token; }