mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
implement featuredWallpaper
endpoints
This commit is contained in:
parent
e39225b338
commit
27333be7ac
@ -1,8 +1,28 @@
|
||||
import { Controller } from "linebridge/dist/server"
|
||||
import { Schematized } from "../../lib"
|
||||
|
||||
import { FeaturedWallpaper } from "../../models"
|
||||
|
||||
export default class PublicController extends Controller {
|
||||
static refName = "PublicController"
|
||||
|
||||
get = {
|
||||
"/featured_wallpapers": {
|
||||
fn: async (req, res) => {
|
||||
const featuredWallpapers = await FeaturedWallpaper.find({})
|
||||
.sort({ date: -1 })
|
||||
.limit(10)
|
||||
.catch(err => {
|
||||
return res.status(500).json({
|
||||
error: err.message
|
||||
}).end()
|
||||
})
|
||||
|
||||
return res.json(featuredWallpapers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post = {
|
||||
"/only_managers_test": {
|
||||
middlewares: ["withAuthentication", "permissions"],
|
||||
@ -12,6 +32,21 @@ export default class PublicController extends Controller {
|
||||
assertedPermissions: req.assertedPermissions
|
||||
})
|
||||
},
|
||||
},
|
||||
"/new_featured_wallpaper": {
|
||||
middlewares: ["withAuthentication", "onlyAdmin"],
|
||||
fn: Schematized({
|
||||
select: ["url", "date"],
|
||||
required: ["url"],
|
||||
}, async (req, res) => {
|
||||
const newFeaturedWallpaper = new FeaturedWallpaper(req.selection)
|
||||
|
||||
await newFeaturedWallpaper.save().catch((err) => {
|
||||
return res.status(400).json({ message: err.message })
|
||||
})
|
||||
|
||||
return res.json(newFeaturedWallpaper)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user