// routes/admin.js
import express from 'express'
const adminRouter = express.Router()
import postRouter from './admin/post.js'
adminRouter.use('/post',postRouter)
import categoryRouter from './admin/category.js'
adminRouter.use('/category',categoryRouter)
import uploadRouter from './admin/upload.js'
adminRouter.use('/upload',uploadRouter)
import userRouter from './admin/user.js'
adminRouter.use('/user',userRouter)
export default adminRouter
//routes/admin/user.js
import express from 'express'
const userRouter = express.Router()
import user from '../../controllers/admin/user.js'
userRouter.get('/',async (req,res)=>{
if(req.session.user){
user.getItem(req,res)
}else{
res.redirect('/login')
}
})
export default userRouter
// controllers/admin/user.js
import config from "../../config.js"
class User{
async getItem(req,res){
this.config = await config()
this.config.pageTitle = 'ទំព័រអ្នកប្រើប្រាស់'
this.config.user = req.session.user
if((this.config.user.role === 'Admin')||(this.config.user.role === 'Editor')){
this.config.route = '/admin/user'
this.config.type = 'user'
}else if(this.config.user.role === 'Author'){
}
res.render('base',{data:this.config})
}
}
export default new User()