<commit_before>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    errorHandler = require('./errors.server.controller'),
    Order = mongoose.model('Order'),
    _ = require('lodash');
var request = require('request');

/**
 * Create a Order
 */
exports.create = function(req, res) {
  var order = new Order(req.body);
  //order.user = req.user;

  order.save(function(err) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      //res.jsonp(order);
      if (order.store) {
        var pushString = "You have Received a New order from MEHER in"+order.addLine1;
        var smsString = "You have Received a New order from MEHER" + "\n";

        order.order.orderitem.forEach( function (value) {
          if (value.quantity) {
            smsString = smsString + value.quantity;
            if (value.unit)
              smsString = smsString + value.unit + " " + value.name + "\n";
            else
              smsString = smsString + " " + value.name + "\n";
          }
          else
            smsString = smsString + '-' + value.name + "\n";
        });
        smsString = smsString + "Phone: " + order.customer.mobile + "\n";
        smsString = smsString + "Address:" + order.customer.addLine1 + "\n" + order.customer.addLine2;
        console.log(smsString);

        var pushMessage = {
          "users": [order.store.deviceId],
          "android": {"collapseKey": "optional", "data": {"message": pushString}},
          "ios": {"badge": 0, "alert": pushString, "sound": "soundName"}
        };

        request({
          url: 'http://api.smscountry.com/SMSCwebservice_bulk.aspx?',
          method: "POST",
          qs: {
            User:"mehertech",
            passwd:"<PASSWORD>",
            mobilenumber: order.store.mobile,
            message: smsString,
            sid:"MEHERA",
            mtype:"N",
            DR:"Y"
          }
        }, function _callback(err, response, SMSbody) {
          console.log(SMSbody);
          request({
            url: "http://getmeher.com:8000/send",
            method: "POST",
            headers: {
              "content-type": "application/json"
            },
            body: JSON.stringify(pushMessage)
          }, function _callback(err, response, Pushbody) {
            var msg = SMSbody + Pushbody
            res.jsonp({message : msg });
          });
        });

      }
      else{
        res.jsonp({message: 'Push not sent to customer'});
      }
    }
  });
};

/**
 * Show the current Order
 */<commit_msg>yes send<commit_after>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    errorHandler = require('./errors.server.controller'),
    Order = mongoose.model('Order'),
    _ = require('lodash');
var request = require('request');

/**
 * Create a Order
 */
exports.create = function(req, res) {
  var order = new Order(req.body);
  //order.user = req.user;

  order.save(function(err) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      //res.jsonp(order);
      if (order.store) {
        var pushString = "You have Received a New order from MEHER in"+order.addLine1;
        var smsString = "You have Received a New order from MEHER" + "\n";

        order.order.orderitem.forEach( function (value) {
          if (value.quantity) {
            smsString = smsString + value.quantity;
            if (value.unit)
              smsString = smsString + value.unit + " " + value.name + "\n";
            else
              smsString = smsString + " " + value.name + "\n";
          }
          else
            smsString = smsString + '-' + value.name + "\n";
        });
        smsString = smsString + "Phone: " + order.customer.mobile + "\n";
        smsString = smsString + "Address:" + order.customer.addLine1 + "\n" + order.customer.addLine2;
        console.log(smsString);

        var pushMessage = {
          "users": [order.store.deviceId],
          "android": {"collapseKey": "optional", "data": {"message": pushString}},
          "ios": {"badge": 0, "alert": pushString, "sound": "soundName"}
        };

        request({
          url: 'http://api.smscountry.com/SMSCwebservice_bulk.aspx?',
          method: "POST",
          qs: {
            User:"mehertech",
            passwd:"<PASSWORD>",
            mobilenumber: order.store.mobile,
            message: smsString,
            sid:"MEHERA",
            mtype:"N",
            DR:"Y"
          }
        }, function _callback(err, response, SMSbody) {
          console.log(SMSbody);
          request({
            url: "http://getmeher.com:8000/send",
            method: "POST",
            headers: {
              "content-type": "application/json"
            },
            body: JSON.stringify(pushMessage)
          }, function _callback(err, response, Pushbody) {
            var msg = SMSbody + Pushbody
            res.jsonp({message : msg });
          });
        });

      }
      else{
        console.log(order.store.deviceId)
        res.jsonp({message: 'Push not sent to customer'});
      }
    }
  });
};

/**
 * Show the current Order
 */
{'fraction_non_alphanumeric': 0.15116942384483742, 'fraction_numerical': 0.004183304810800532, 'mean_word_length': 1.8463203463203464, 'pattern_counts': {'":': 20, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '922435', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1556, 'n_words': 332}