-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (33 loc) · 981 Bytes
/
index.js
File metadata and controls
38 lines (33 loc) · 981 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
37
38
const {
createPlaylist,
deletePlaylist,
getPlaylistInfo,
validateBody,
} = require('./utils');
exports.deezer = async (req, res) => {
if (req.method === 'GET') {
// Get playlist information
const response = await getPlaylistInfo(req.query.link);
return res.status(200).json(response);
}
if (req.method === 'POST') {
// Create a playlist
const result = validateBody(req.body);
if (!result.isValid) {
return res.status(400).json({ errors: result.errors });
}
const tracks = req.body.tracks;
const playlistInfo = {
name: req.body.name,
description: req.body.description,
};
const response = await createPlaylist(tracks, playlistInfo);
return res.status(201).json(response);
}
if (req.method === 'DELETE') {
// Delete playlist
await deletePlaylist(req.query.link);
return res.status(200).json({ message: 'Done' });
}
return res.status(400).json({ message: 'Invalid method' });
};