var express = require('express')
var router = express.Router()
var settings = require('../../settings')



router.get('/', async function(req, res, next) {
    settings.dLogo = 'ទំព័រ​អ្នក​ប្រើប្រាស់'
  
    if(req.session.user){
        const today = new Date()
        const date = today.toLocaleDateString('fr-CA')
        const time = today.toLocaleTimeString('it-IT')
        settings.datetime = date + 'T' +  time

        const count = await require('../../controllers/users/count')()
        settings.message = `ចំនួន​អ្នក​ប្រើប្រាស់​​សរុបៈ ${count}`
        const read = await require('../../controllers/users/read')

        settings.items = await read(settings.dItemLimit)
        
        settings.route = 'user'
        
        res.render('users/user', settings)
    }else{
        res.redirect('/users')
    }
})




module.exports = router

 

const schema = require('./schema')



async function getUser(amount=10, id=false, page=0, userid=null){
    const userSchema = await schema()

    if(userid){
        var querry = {author: userid}
    }else{
        var querry = {}
    }

    if(id){
        return await userSchema.findOne({userid: id})
    }else if(page){
        return await userSchema.find(querry).skip(amount * page).sort({date: -1, _id: -1}).limit(amount)
    }else{
        return await userSchema.find(querry).sort({date: -1, _id: -1}).limit(amount)
    }
}



module.exports = getUser

 

GitHub: https://github.com/Sokhavuth/tv

Vercel: https://tv-neon.vercel.app

Responsive: http://www.responsinator.com