Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Parse.Cloud.afterSave("Feedback", (request) => {
- const grade = request.object.get("grade").toString() ;
- const message = request.object.get("message");
- // request.log.info("TEST_LOG_GRADE: "+ grade + "TEST_LOG_MESSAGE: " + message);
- const userObj = request.object.get("user");
- const user = JSON.parse(JSON.stringify(userObj))
- const userID = user["objectId"];
- request.log.info("TEST_LOG: "+userID);
- return getUser(userID).then(function(user){
- if(user){
- sendEmailOnFeedback(user.get("email"), grade, message)
- } else {
- console.log("User with objectId: " + userID + " was not found");
- }
- }, function(error){
- console.error("Got an error " + error.code + " : " + error.message);
- });
- });
- function getUser(userId) {
- var promise = new Parse.Promise();
- var query = new Parse.Query(Parse.User);
- query.equalTo("objectId",userId);
- query.first().then(function(result){
- if(result){
- // If result was defined, the object with this objectID was found
- promise.resolve(result);
- } else {
- console.log("User ID: " + userId + " was not found");
- promise.resolve(null);
- }
- }, function(error){
- console.error("Error searching for User with id: " + userId + " Error: " + error);
- promise.error(error);
- });
- return promise;
- }
- function sendEmailOnFeedback(useremail, grade, message) {
- //// https://nodemailer.com/about/
- const nodemailer = require("nodemailer");
- //// create reusable transporter object using the default SMTP transport
- const mailTransport = nodemailer.createTransport({
- service: 'gmail',
- auth: {
- user: "wadertest123@gmail.com",
- pass: "anoda123456"
- }
- });
- //// setup email data with unicode symbols
- const mailOptions = {
- from: '"Wader App" <wader@example.com>', // sender address
- to: "test@anoda.io, lamcevs0@gmail.com", // list of receivers
- subject: "New user feedback", // Subject line
- text: "Hello world?", // plain text body
- //html: '<b> ${useremail} </b> <br> <b> ${message} </b> <br>' // html body
- };
- // send mail with defined transport object
- return mailTransport.sendMail(mailOptions);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement