Migrated read APIs to Nitro
This commit is contained in:
1 parent
eb4e9f0700
commit
ee5809a489
26 files changed
+558
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { getRouterParam } from "h3"
|
||||
import { Track } from "../../models/track"
|
||||
import { requireAuthenticatedUser } from "../../utils/auth"
|
||||
import { parseMongoId, validationResponse } from "../../utils/api-validation"
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAuthenticatedUser(event)
|
||||
|
||||
const parsedId = parseMongoId(getRouterParam(event, "id"))
|
||||
if ("error" in parsedId) return validationResponse(event, parsedId.error)
|
||||
|
||||
return Track.findOne({ _id: parsedId.value })
|
||||
.populate({
|
||||
path: "album",
|
||||
select: "-artists",
|
||||
populate: { path: "genre" },
|
||||
})
|
||||
.populate("artists")
|
||||
.exec()
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { getRouterParam } from "h3"
|
||||
import { Track } from "../../../models/track"
|
||||
import { requireAuthenticatedUser } from "../../../utils/auth"
|
||||
import { parseMongoId, validationResponse } from "../../../utils/api-validation"
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAuthenticatedUser(event)
|
||||
|
||||
const parsedId = parseMongoId(getRouterParam(event, "id"))
|
||||
if ("error" in parsedId) return validationResponse(event, parsedId.error)
|
||||
|
||||
const track = await Track.findOne({ _id: parsedId.value }).select("lyrics").exec()
|
||||
if (!track) return {}
|
||||
|
||||
return track.lyrics
|
||||
})
|
||||
Reference in new issue
Block a user