-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathplaylist.js
More file actions
36 lines (32 loc) · 1011 Bytes
/
playlist.js
File metadata and controls
36 lines (32 loc) · 1011 Bytes
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
30
31
32
33
34
35
36
const spotify = require('../helpers/spotify');
const serverErrorResponse = require('../responses/serverErrorResponse');
const clientErrorResponse = require('../responses/clientErrorResponse');
const successResponse = require('../responses/successResponse');
module.exports = {
/**
* Retrieve a single playlist
*/
getPlaylistByID: async (req, res) => {
try {
const { id } = req.params;
const playlist = await spotify.findPlaylist(id);
if (!playlist) {
return clientErrorResponse(res, 404, 'Playlist not found');
}
return successResponse(res, 200, 'Playlist retrieved', playlist);
} catch (err) {
return serverErrorResponse(res, err);
}
},
/**
* Retrieve all playlists
*/
getAllPlaylists: async (req, res) => {
try {
const playlists = await spotify.findAllPlaylists();
return successResponse(res, 200, 'Playlists retrieved', playlists);
} catch (err) {
return serverErrorResponse(res, err);
}
},
};