Init
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
const asyncHandler = require("express-async-handler");
|
||||
const Site = require("../models/siteModels");
|
||||
const { _sr } = require("../plugins/resServer")
|
||||
|
||||
|
||||
/**
|
||||
*@desc Get all site
|
||||
*@route GET /api/sites/
|
||||
*@access Public
|
||||
*/
|
||||
const getSite = asyncHandler(async (req, res) => {
|
||||
const profile = await Site.findOne({ profile: "main" });
|
||||
res.status(200).json(profile);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
*@desc Update a site
|
||||
*@route PUT /api/sites/
|
||||
*@access private
|
||||
*/
|
||||
const updateSite = [
|
||||
asyncHandler(async (req, res) => {
|
||||
const site = await Site.findOneAndUpdate(
|
||||
{ profile: "main" },
|
||||
req.body,
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
if (!site) {
|
||||
res.status(404);
|
||||
throw new Error(_sr.fa.not_found.item_id);
|
||||
}
|
||||
res.status(200).json(site);
|
||||
})
|
||||
]
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
baseRoute: "/sites",
|
||||
items: [
|
||||
{
|
||||
off: false,
|
||||
route: "/",
|
||||
method: "get",
|
||||
middleware: ['validateAdminToken', 'hasPermission'],
|
||||
permission: "SITE",
|
||||
use: getSite
|
||||
},
|
||||
{
|
||||
off: false,
|
||||
route: "/id/:id",
|
||||
method: "put",
|
||||
middleware: ['validateAdminToken', 'hasPermission'],
|
||||
permission: "SITE",
|
||||
use: updateSite
|
||||
},
|
||||
]
|
||||
};
|
||||
Reference in New Issue
Block a user