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,24 @@
|
||||
import { getQuery, getRouterParam } from "h3"
|
||||
import { Album } from "../../../models/album"
|
||||
import { requireAuthenticatedUser } from "../../../utils/auth"
|
||||
import { parseMongoId, parseNumber, 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 query = getQuery(event)
|
||||
const limit = parseNumber(query.limit, 9, 1)
|
||||
if ("error" in limit) return validationResponse(event, limit.error)
|
||||
const skip = parseNumber(query.skip, 0, 0)
|
||||
if ("error" in skip) return validationResponse(event, skip.error)
|
||||
|
||||
return Album.find({ artists: parsedId.value })
|
||||
.limit(limit.value || 9)
|
||||
.skip(skip.value || 0)
|
||||
.populate("genre")
|
||||
.populate("artists")
|
||||
.exec()
|
||||
})
|
||||
Reference in new issue
Block a user