mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
implement FeaturedEvents
controller
This commit is contained in:
parent
a6adba5f9e
commit
f7a97cce82
@ -37,6 +37,7 @@ export default class Server {
|
||||
controllers.BadgesController,
|
||||
controllers.CommentsController,
|
||||
controllers.SearchController,
|
||||
controllers.FeaturedEventsController,
|
||||
]
|
||||
|
||||
middlewares = middlewares
|
||||
|
@ -0,0 +1,53 @@
|
||||
import { Controller } from "linebridge/dist/server"
|
||||
import { FeaturedEvent } from "../../models"
|
||||
|
||||
import createFeaturedEvent from "./methods/createFeaturedEvent"
|
||||
|
||||
export default class FeaturedEventsController extends Controller {
|
||||
get = {
|
||||
"/featured_event/:id": async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const featuredEvent = await FeaturedEvent.findById(id)
|
||||
|
||||
return res.json(featuredEvent)
|
||||
},
|
||||
"/featured_events": async (req, res) => {
|
||||
const featuredEvents = await FeaturedEvent.find()
|
||||
|
||||
return res.json(featuredEvents)
|
||||
}
|
||||
}
|
||||
|
||||
post = {
|
||||
"/featured_event": {
|
||||
middlewares: ["withAuthentication", "onlyAdmin"],
|
||||
fn: async (req, res) => {
|
||||
const result = await createFeaturedEvent(req.body).catch((err) => {
|
||||
res.status(500).json({
|
||||
error: err.message
|
||||
})
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
if (result) {
|
||||
return res.json(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete = {
|
||||
"/featured_event/:id": {
|
||||
middlewares: ["withAuthentication", "onlyAdmin"],
|
||||
fn: async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const featuredEvent = await FeaturedEvent.findByIdAndDelete(id)
|
||||
|
||||
return res.json(featuredEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
import { FeaturedEvent } from "../../../models"
|
||||
|
||||
export default async (payload) => {
|
||||
const {
|
||||
name,
|
||||
category,
|
||||
description,
|
||||
dates,
|
||||
location,
|
||||
announcement,
|
||||
} = payload
|
||||
|
||||
const featuredEvent = new FeaturedEvent({
|
||||
name,
|
||||
category,
|
||||
description,
|
||||
dates,
|
||||
location,
|
||||
announcement,
|
||||
})
|
||||
|
||||
await featuredEvent.save()
|
||||
|
||||
return featuredEvent
|
||||
}
|
@ -8,4 +8,5 @@ export { default as PostsController } from "./PostsController"
|
||||
export { default as StreamingController } from "./StreamingController"
|
||||
export { default as BadgesController } from "./BadgesController"
|
||||
export { default as CommentsController } from "./CommentsController"
|
||||
export { default as SearchController } from "./SearchController"
|
||||
export { default as SearchController } from "./SearchController"
|
||||
export { default as FeaturedEventsController } from "./FeaturedEventsController"
|
Loading…
x
Reference in New Issue
Block a user