Express.js OO编程

时间:2018-05-06 09:37:32

标签: javascript express

大家好我有问题要实施" class"我的Express App中的关键字。这是我的代码:

/controllers/manajemen_list_venue.js

class Venue{
    constructor(params){
        this.id_venue = params.id_venue;
        this.nama_venue = params.nama_venue;
        this.keterangan = params.keterangan;
    }
}

Venue.prototype.getDataVenue = function(req, res){
    pool.query("SELECT * FROM venue", function(err, rows, fields) {
        if (err) throw err;
        if(rows[0]){
            res.render('manajemen_list_venue/manajemen_list_venue', {
                        person: req.user,
                        venues: rows,
                        message_err: req.flash('message_err'),
                        message_success: req.flash('message_success'),

            }); 
        }
        else{
            req.flash('message_notf', "No venue found.");
            res.render('manajemen_list_venue/manajemen_list_venue', {
                person: req.user,
                message_err: req.flash('message_err'),
                message_success: req.flash('message_success'),
                message_notf: req.flash('message_notf')

            });
        }

    });

}

module.exports = Venue;

/routes/manajemen_list_venue.js

var venue = require('../controllers/manajemen_list_venue');

var venue_1 =  new Venue();

//route level middleware
router.get('/', auth.isLoggedIn, auth.isTuOrSuperAdmin, venue_1.getDataVenue);

它返回错误:

  

C:\用户\用户\桌面\ manajemen事件主\路由\ manajemen_list_venue.js:10   var venue_1 = new Venue();                      ^

     

ReferenceError:未定义Venue       在对象。 (C:\用户\用户\桌面\ manajemen事件主\路由\ manajemen_list_venue.js:10:20)

我的代码出了什么问题?谢谢

0 个答案:

没有答案