routes/review.js


 

module.exports = function(app,app_secure,uuid){
    var nodemailer = require('nodemailer');
    app.get('/admin/getcomment', function(req, res) {
        var db = req.db;
        var vObj = {'reviewed':'N'};
        db.collection('comment').find(vObj,{}).toArray(function (err, items) {
            res.json(items);
        });
    });


    app.put('/admin/comment/edit/:id', function(req, res) {
        var db = req.db;
        var newVen = req.body;
        var reviewed = newVen.reviewed;
        var emailId = newVen.userEmail;
        db.collection('comment').update({'_id':newVen._id},newVen,{'safe':true },function(err, result){
            if(err === null){
                var vObj = {'reviewed':'N'};
                db.collection('comment').find(vObj,{}).toArray(function (err, items) {
                    res.json(items);
                 });
            }else{
                res.send({ msg: err });
            }
        });

        var mailOpts, smtpTrans;
        //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
        smtpTrans = nodemailer.createTransport('SMTP', {
            service: 'Gmail',
            auth: {
              user: "spotdekho@gmail.com",
              pass: "asfasfasdfasfd" 
            }
        });
        //Mail options
        mailOpts = {
            from: 'spotdekho@gmail.com',
            to: emailId,
            subject: 'SpotDekho -- your comment has been published in the website',
            text: "Thank you for your valuable comments in SpotDekho.\nWe have posted your feedback/ review/ comment in the website. Please check it out. \n\n\n\nFeel free to contact us at admin@spotdekho.com or through our CONTACT-US web page, available at :- https://www.spotdekho.com/contactus \n\nRegards,\nSpotDekho Team"
        };
        smtpTrans.sendMail(mailOpts, function (error, response) {
        if (error) {
          console.log ("Error while sending email during comment approval");
        }
        else {
          console.log ("Email sent to person who has posted the comment");
        }
        smtpTrans.close();
        });

    });



    app.delete('/admin/comment/delete/:id', function(req, res) {
        var db = req.db;
        var reviewToDelete = req.params.id;
        db.collection('comment').removeById(reviewToDelete, function(err, result) {
            res.send((result === 1) ? { msg: '' } : { msg:'error: ' + err });
        });
    });


}

 

Leave a Reply

Your email address will not be published. Required fields are marked *