mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
implement get /playlist/:id
endpoint
This commit is contained in:
parent
f4f4726231
commit
50fd9c7d38
@ -2,13 +2,26 @@ import { Controller } from "linebridge/dist/server"
|
|||||||
import { Schematized } from "../../lib"
|
import { Schematized } from "../../lib"
|
||||||
|
|
||||||
import publishPlaylist from "./methods/publishPlaylist"
|
import publishPlaylist from "./methods/publishPlaylist"
|
||||||
|
import getPlaylist from "./methods/getPlaylist"
|
||||||
|
|
||||||
export default class PlaylistsController extends Controller {
|
export default class PlaylistsController extends Controller {
|
||||||
//static useMiddlewares = ["withAuthentication"]
|
//static useMiddlewares = ["withAuthentication"]
|
||||||
|
|
||||||
get = {
|
get = {
|
||||||
"/playlist/:id": async (req, res) => {
|
"/playlist/:id": async (req, res) => {
|
||||||
|
const result = await getPlaylist({
|
||||||
|
_id: req.params.id
|
||||||
|
}).catch((err) => {
|
||||||
|
res.status(500).json({
|
||||||
|
error: err.message
|
||||||
|
})
|
||||||
|
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return res.json(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +31,7 @@ export default class PlaylistsController extends Controller {
|
|||||||
fn: Schematized({
|
fn: Schematized({
|
||||||
required: ["title", "list"],
|
required: ["title", "list"],
|
||||||
select: ["title", "description", "thumbnail", "list"],
|
select: ["title", "description", "thumbnail", "list"],
|
||||||
},async (req, res) => {
|
}, async (req, res) => {
|
||||||
if (typeof req.body.list === "undefined") {
|
if (typeof req.body.list === "undefined") {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error: "list is required"
|
error: "list is required"
|
||||||
@ -43,7 +56,6 @@ export default class PlaylistsController extends Controller {
|
|||||||
return res.json(result)
|
return res.json(result)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
import { User, Playlist } from "../../../models"
|
||||||
|
|
||||||
|
export default async (payload) => {
|
||||||
|
const { _id } = payload
|
||||||
|
|
||||||
|
if (!_id) {
|
||||||
|
throw new Error("Missing _id")
|
||||||
|
}
|
||||||
|
|
||||||
|
let playlist = await Playlist.findById(_id).catch((err) => false)
|
||||||
|
|
||||||
|
if (!playlist) {
|
||||||
|
throw new Error("Playlist not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
playlist = playlist.toObject()
|
||||||
|
|
||||||
|
const user = await User.findById(playlist.user_id).catch((err) => false)
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
throw new Error("User not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
playlist.user = {
|
||||||
|
username: user.username,
|
||||||
|
avatar: user.avatar,
|
||||||
|
}
|
||||||
|
|
||||||
|
return playlist
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user