As usual, before doing anything on admin user page, a route to user page needs to be defined and added to the entry point as below:

 

// route/admin.js
import express from 'express'
const adminRoute = express.Router()

import jobRoute from './admin/job.js'
adminRoute.use('/job',jobRoute)

import categoryRoute from './admin/category.js'
adminRoute.use('/category',categoryRoute)

import uploadRoute from './admin/upload.js'
adminRoute.use('/upload',uploadRoute)

import userRoute from './admin/user.js'
adminRoute.use('/user',userRoute)

export default adminRoute

 

// route/admin/user.js
import express from 'express'
const userRoute = express.Router()
import user from '../../controller/admin/user.js'

userRoute.get('/',async (req,res)=>{
    if(req.session.user){
        user.getItem(req,res)
    }else{
        res.redirect('/login')
    }
})

export default userRoute

 

// controller/admin/user.js
import config from '../../config.js'

class User{
    constructor(){
        (async ()=>{
            this.config = await config()
        })()
    }

    async getItem(req,res){
        this.config.pageTitle = 'ទំព័រអ្នក​ប្រើប្រាស់'
        this.config.route = '/admin/user'
        this.config.type = 'user'


        res.render('base',{data:this.config})
    }
}

export default await new User()

 

GitHub: https://github.com/Sokhavuth/khmerweb-job

Heroku: https://khmerweb-job.herokuapp.com