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
        
        settings.route = 'book'
        
        res.render('users/book', settings)
    }else{
        res.redirect('/users')
    }
})

router.post('/', async function(req, res, next) {
    if(req.session.user){
        await require('../../controllers/books/create')(req)
        res.redirect('/users/book')
    }else{
        res.redirect('/users')
    }
})



module.exports = router

 

const schema = require('./schema')



async function createBook(req){
    const bookSchema = await schema()

    const id = (new Date()).getTime().toString(36) + Math.random().toString(36).slice(2)
    const title = req.body.title
    const content = req.body.content
    const thumb = req.body.thumb
    const video = req.body.entries
    const chapter = req.body.chapter
    const date = new Date(req.body.datetime)
    const author = req.session.user.userid

    const book = new bookSchema({id: id, title: title, content: content, thumb: thumb,
        video: video, chapter: chapter, date: date, author: author})
        
    return await book.save()
}



module.exports = createBook

 

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

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

Responsive: http://www.responsinator.com