All files / Rindu/utils/spotifyCalls createPlaylist.ts

37.5% Statements 3/8
0% Branches 0/7
0% Functions 0/1
42.85% Lines 3/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  42x 42x   4x                                                
import type { ServerApiContext } from "types/serverContext";
import { handleJsonResponse } from "utils/handleJsonResponse";
import { callSpotifyApi } from "utils/spotifyCalls";
 
export async function createPlaylist(
  user_id: string | undefined,
  options?: {
    name?: string;
    description?: string;
  },
  context?: ServerApiContext
): Promise<SpotifyApi.CreatePlaylistResponse | null> {
  Iif (!user_id) return null;
  const { name, description } = options ?? {};
 
  const res = await callSpotifyApi({
    endpoint: `/users/${user_id}/playlists`,
    method: "POST",
    context,
    body: JSON.stringify({
      name: name ?? "New Playlist",
      description: description ?? "Your playlist created in Rindu",
      public: false,
    }),
  });
 
  return handleJsonResponse<SpotifyApi.CreatePlaylistResponse>(res);
}