node-paytmpg 6.4.6 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +132 -182
- package/app/views/layouts/index.hbs +7 -7
- package/app/views/result.hbs +1 -1
- package/dist/app/controllers/adapters/open_money.js +400 -0
- package/dist/app/controllers/adapters/paytm.js +34 -0
- package/{app → dist/app}/controllers/adapters/payu.js +208 -239
- package/dist/app/controllers/checksum/PaytmChecksum.js +118 -0
- package/dist/app/controllers/checksum/checksum.js +158 -0
- package/dist/app/controllers/checksum/crypt.js +117 -0
- package/dist/app/controllers/checksum/server.js +130 -0
- package/dist/app/controllers/payment.controller.js +985 -0
- package/dist/app/controllers/static/loadingsvg.js +54 -0
- package/dist/app/controllers/user.controller.js +53 -0
- package/dist/app/models/index.js +2 -0
- package/dist/app/routes/payment_route.js +46 -0
- package/dist/app/utils/buildConfig.js +210 -0
- package/dist/app/utils/utils.js +20 -0
- package/dist/app/views/home.hbs +22 -0
- package/dist/app/views/init.hbs +98 -0
- package/dist/app/views/layouts/index.hbs +53 -0
- package/dist/app/views/result.hbs +33 -0
- package/dist/index.js +119 -0
- package/dist/package.json +67 -0
- package/dist/public/css/style.css +455 -0
- package/dist/public/js/index.js +283 -0
- package/dist/public/layer_checkout.js +38 -0
- package/dist/public/pay.png +0 -0
- package/dist/public/start.png +0 -0
- package/dist/public/start2.png +0 -0
- package/dist/public/stat.png +0 -0
- package/dist/public/test.html +24 -0
- package/dist/public/test.html~ +24 -0
- package/package.json +29 -6
- package/public/test.html~ +24 -0
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.github/workflows/nodejs.yml +0 -24
- package/.github/workflows/npm-publish.yml +0 -23
- package/Dockerfile +0 -9
- package/app/controllers/adapters/open_money.js +0 -515
- package/app/controllers/checksum/PaytmChecksum.js +0 -94
- package/app/controllers/checksum/checksum.js +0 -154
- package/app/controllers/checksum/crypt.js +0 -98
- package/app/controllers/checksum/server.js +0 -132
- package/app/controllers/np_user.controller.js +0 -89
- package/app/controllers/payment_controller.js +0 -1204
- package/app/models/np_multidbplugin.js +0 -111
- package/app/models/np_transaction.model.js +0 -16
- package/app/models/np_user.model.js +0 -12
- package/app/routes/payment_route.js +0 -73
- package/app.yaml +0 -18
- package/example.js +0 -34
- package/index.js +0 -86
- package/lib/config/buildConfig.js +0 -113
- package/lib/config/defaults.js +0 -37
- package/lib/config/validator.js +0 -103
- package/lib/services/database.service.js +0 -153
- package/lib/utils/id-generator.js +0 -30
- package/lib/utils/sanitizer.js +0 -25
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var crypt = require('./crypt');
|
|
4
|
-
var util = require('util');
|
|
5
|
-
var crypto = require('crypto');
|
|
6
|
-
const PaytmChecksum = require('./PaytmChecksum.js');
|
|
7
|
-
|
|
8
|
-
//mandatory flag: when it set, only mandatory parameters are added to checksum
|
|
9
|
-
|
|
10
|
-
function paramsToString(params, mandatoryflag) {
|
|
11
|
-
var data = '';
|
|
12
|
-
var tempKeys = Object.keys(params);
|
|
13
|
-
tempKeys.sort();
|
|
14
|
-
tempKeys.forEach(function (key) {
|
|
15
|
-
if (!params[key]) {
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
var n = params[key].includes("REFUND");
|
|
20
|
-
var m = params[key].includes("|");
|
|
21
|
-
if (n == true) {
|
|
22
|
-
params[key] = "";
|
|
23
|
-
}
|
|
24
|
-
if (m == true) {
|
|
25
|
-
params[key] = "";
|
|
26
|
-
}
|
|
27
|
-
} catch (e) {
|
|
28
|
-
params[key] = "";
|
|
29
|
-
console.log(e)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (key !== 'CHECKSUMHASH') {
|
|
34
|
-
if (params[key] === 'null') params[key] = '';
|
|
35
|
-
if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
|
|
36
|
-
data += (params[key] + '|');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function genchecksum(params, key, cb) {
|
|
45
|
-
let checksumPromise = PaytmChecksum.generateSignature(params, key).then(checksum => {
|
|
46
|
-
cb(undefined, checksum)
|
|
47
|
-
})
|
|
48
|
-
return checksumPromise;
|
|
49
|
-
var data = paramsToString(params);
|
|
50
|
-
crypt.gen_salt(4, function (err, salt) {
|
|
51
|
-
var sha256 = crypto.createHash('sha256').update(data + salt).digest('hex');
|
|
52
|
-
var check_sum = sha256 + salt;
|
|
53
|
-
var encrypted = crypt.encrypt(check_sum, key);
|
|
54
|
-
cb(undefined, encrypted);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function genchecksumbystring(params, key, cb) {
|
|
58
|
-
|
|
59
|
-
crypt.gen_salt(4, function (err, salt) {
|
|
60
|
-
var sha256 = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
|
|
61
|
-
var check_sum = sha256 + salt;
|
|
62
|
-
var encrypted = crypt.encrypt(check_sum, key);
|
|
63
|
-
|
|
64
|
-
var CHECKSUMHASH = encodeURIComponent(encrypted);
|
|
65
|
-
CHECKSUMHASH = encrypted;
|
|
66
|
-
cb(undefined, CHECKSUMHASH);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function verifychecksum(params, key, checksumhash) {
|
|
71
|
-
return PaytmChecksum.verifySignature(params, key, checksumhash)
|
|
72
|
-
var data = paramsToString(params, false);
|
|
73
|
-
|
|
74
|
-
//TODO: after PG fix on thier side remove below two lines
|
|
75
|
-
if (typeof checksumhash !== "undefined") {
|
|
76
|
-
checksumhash = checksumhash.replace('\n', '');
|
|
77
|
-
checksumhash = checksumhash.replace('\r', '');
|
|
78
|
-
var temp = decodeURIComponent(checksumhash);
|
|
79
|
-
var checksum = crypt.decrypt(temp, key);
|
|
80
|
-
var salt = checksum.substr(checksum.length - 4);
|
|
81
|
-
var sha256 = checksum.substr(0, checksum.length - 4);
|
|
82
|
-
var hash = crypto.createHash('sha256').update(data + salt).digest('hex');
|
|
83
|
-
if (hash === sha256) {
|
|
84
|
-
return true;
|
|
85
|
-
} else {
|
|
86
|
-
util.log("checksum is wrong");
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
util.log("checksum not found");
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function verifychecksumbystring(params, key, checksumhash) {
|
|
96
|
-
|
|
97
|
-
var checksum = crypt.decrypt(checksumhash, key);
|
|
98
|
-
var salt = checksum.substr(checksum.length - 4);
|
|
99
|
-
var sha256 = checksum.substr(0, checksum.length - 4);
|
|
100
|
-
var hash = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
|
|
101
|
-
if (hash === sha256) {
|
|
102
|
-
return true;
|
|
103
|
-
} else {
|
|
104
|
-
util.log("checksum is wrong");
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function genchecksumforrefund(params, key, cb) {
|
|
110
|
-
var data = paramsToStringrefund(params);
|
|
111
|
-
crypt.gen_salt(4, function (err, salt) {
|
|
112
|
-
var sha256 = crypto.createHash('sha256').update(data + salt).digest('hex');
|
|
113
|
-
var check_sum = sha256 + salt;
|
|
114
|
-
var encrypted = crypt.encrypt(check_sum, key);
|
|
115
|
-
params.CHECKSUM = encodeURIComponent(encrypted);
|
|
116
|
-
cb(undefined, params);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function paramsToStringrefund(params, mandatoryflag) {
|
|
121
|
-
var data = '';
|
|
122
|
-
var tempKeys = Object.keys(params);
|
|
123
|
-
tempKeys.sort();
|
|
124
|
-
tempKeys.forEach(function (key) {
|
|
125
|
-
var m = params[key].includes("|");
|
|
126
|
-
if (m == true) {
|
|
127
|
-
params[key] = "";
|
|
128
|
-
}
|
|
129
|
-
if (key !== 'CHECKSUMHASH') {
|
|
130
|
-
if (params[key] === 'null') params[key] = '';
|
|
131
|
-
if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
|
|
132
|
-
data += (params[key] + '|');
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return data;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function checkRazorSignature(razorpayOrderId, razorpayPaymentId, secret, razorpay_signature) {
|
|
140
|
-
const hmac = crypto.createHmac('sha256', secret);
|
|
141
|
-
|
|
142
|
-
hmac.update(razorpayOrderId + "|" + razorpayPaymentId);
|
|
143
|
-
let generatedSignature = hmac.digest('hex');
|
|
144
|
-
|
|
145
|
-
let isSignatureValid = generatedSignature == razorpay_signature;
|
|
146
|
-
return isSignatureValid
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
module.exports.genchecksum = genchecksum;
|
|
150
|
-
module.exports.verifychecksum = verifychecksum;
|
|
151
|
-
module.exports.verifychecksumbystring = verifychecksumbystring;
|
|
152
|
-
module.exports.genchecksumbystring = genchecksumbystring;
|
|
153
|
-
module.exports.genchecksumforrefund = genchecksumforrefund;
|
|
154
|
-
module.exports.checkRazorSignature = checkRazorSignature;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var crypto = require('crypto');
|
|
4
|
-
var util = require('util');
|
|
5
|
-
|
|
6
|
-
var crypt = {
|
|
7
|
-
iv: '@@@@&&&&####$$$$',
|
|
8
|
-
|
|
9
|
-
encrypt: function (data,custom_key) {
|
|
10
|
-
var iv = this.iv;
|
|
11
|
-
var key = custom_key;
|
|
12
|
-
var algo = '256';
|
|
13
|
-
switch (key.length) {
|
|
14
|
-
case 16:
|
|
15
|
-
algo = '128';
|
|
16
|
-
break;
|
|
17
|
-
case 24:
|
|
18
|
-
algo = '192';
|
|
19
|
-
break;
|
|
20
|
-
case 32:
|
|
21
|
-
algo = '256';
|
|
22
|
-
break;
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
var cipher = crypto.createCipheriv('AES-' + algo + '-CBC', key, iv);
|
|
26
|
-
//var cipher = crypto.createCipher('aes256',key);
|
|
27
|
-
var encrypted = cipher.update(data, 'binary', 'base64');
|
|
28
|
-
encrypted += cipher.final('base64');
|
|
29
|
-
return encrypted;
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
decrypt: function (data,custom_key) {
|
|
33
|
-
var iv = this.iv;
|
|
34
|
-
var key = custom_key;
|
|
35
|
-
var algo = '256';
|
|
36
|
-
switch (key.length) {
|
|
37
|
-
case 16:
|
|
38
|
-
algo = '128';
|
|
39
|
-
break;
|
|
40
|
-
case 24:
|
|
41
|
-
algo = '192';
|
|
42
|
-
break;
|
|
43
|
-
case 32:
|
|
44
|
-
algo = '256';
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
var decipher = crypto.createDecipheriv('AES-' + algo + '-CBC', key, iv);
|
|
48
|
-
var decrypted = decipher.update(data, 'base64', 'binary');
|
|
49
|
-
try {
|
|
50
|
-
decrypted += decipher.final('binary');
|
|
51
|
-
} catch (e) {
|
|
52
|
-
util.log(util.inspect(e));
|
|
53
|
-
}
|
|
54
|
-
return decrypted;
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
gen_salt: function (length, cb) {
|
|
58
|
-
crypto.randomBytes((length * 3.0) / 4.0, function (err, buf) {
|
|
59
|
-
var salt;
|
|
60
|
-
if (!err) {
|
|
61
|
-
salt = buf.toString("base64");
|
|
62
|
-
}
|
|
63
|
-
//salt=Math.floor(Math.random()*8999)+1000;
|
|
64
|
-
cb(err, salt);
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
/* one way md5 hash with salt */
|
|
69
|
-
md5sum: function (salt, data) {
|
|
70
|
-
return crypto.createHash('md5').update(salt + data).digest('hex');
|
|
71
|
-
},
|
|
72
|
-
sha256sum: function (salt, data) {
|
|
73
|
-
return crypto.createHash('sha256').update(data + salt).digest('hex');
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
module.exports = crypt;
|
|
78
|
-
|
|
79
|
-
(function () {
|
|
80
|
-
var i;
|
|
81
|
-
|
|
82
|
-
function logsalt(err, salt) {
|
|
83
|
-
if (!err) {
|
|
84
|
-
console.log('salt is ' + salt);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (require.main === module) {
|
|
89
|
-
var enc = crypt.encrypt('One97');
|
|
90
|
-
console.log('encrypted - ' + enc);
|
|
91
|
-
console.log('decrypted - ' + crypt.decrypt(enc));
|
|
92
|
-
|
|
93
|
-
for (i = 0; i < 5; i++) {
|
|
94
|
-
crypt.gen_salt(4, logsalt);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}());
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
const http = require('http');
|
|
2
|
-
const https = require('https');
|
|
3
|
-
const qs = require('querystring');
|
|
4
|
-
const port = 8080;
|
|
5
|
-
const checksum_lib = require('./checksum.js');
|
|
6
|
-
|
|
7
|
-
var PaytmConfig = {
|
|
8
|
-
mid: "XXXXXXXXXXXXXXXXXXXX",
|
|
9
|
-
key: "XXXXXXXXXXXXXXXX",
|
|
10
|
-
website: "XXXXXXXXXX"
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
http.createServer(function (req, res) {
|
|
15
|
-
|
|
16
|
-
switch(req.url){
|
|
17
|
-
case "/":
|
|
18
|
-
var params = {};
|
|
19
|
-
params['MID'] = PaytmConfig.mid;
|
|
20
|
-
params['WEBSITE'] = PaytmConfig.website;
|
|
21
|
-
params['CHANNEL_ID'] = 'WEB';
|
|
22
|
-
params['INDUSTRY_TYPE_ID'] = 'Retail';
|
|
23
|
-
params['ORDER_ID'] = 'TEST_' + new Date().getTime();
|
|
24
|
-
params['CUST_ID'] = 'Customer001';
|
|
25
|
-
params['TXN_AMOUNT'] = '1.00';
|
|
26
|
-
params['CALLBACK_URL'] = 'http://localhost:'+port+'/callback';
|
|
27
|
-
params['EMAIL'] = 'abc@mailinator.com';
|
|
28
|
-
params['MOBILE_NO'] = '7777777777';
|
|
29
|
-
|
|
30
|
-
checksum_lib.genchecksum(params, PaytmConfig.key, function (err, checksum) {
|
|
31
|
-
|
|
32
|
-
var txn_url = "https://securegw-stage.paytm.in/theia/processTransaction"; // for staging
|
|
33
|
-
// var txn_url = "https://securegw.paytm.in/theia/processTransaction"; // for production
|
|
34
|
-
|
|
35
|
-
var form_fields = "";
|
|
36
|
-
for(var x in params){
|
|
37
|
-
form_fields += "<input type='hidden' name='"+x+"' value='"+params[x]+"' >";
|
|
38
|
-
}
|
|
39
|
-
form_fields += "<input type='hidden' name='CHECKSUMHASH' value='"+checksum+"' >";
|
|
40
|
-
|
|
41
|
-
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
42
|
-
res.write('<html><head><title>Merchant Checkout Page</title></head><body><center><h1>Please do not refresh this page...</h1></center><form method="post" action="'+txn_url+'" name="f1">'+form_fields+'</form><script type="text/javascript">document.f1.submit();</script></body></html>');
|
|
43
|
-
res.end();
|
|
44
|
-
});
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
case "/callback":
|
|
48
|
-
|
|
49
|
-
var body = '';
|
|
50
|
-
|
|
51
|
-
req.on('data', function (data) {
|
|
52
|
-
body += data;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
req.on('end', function () {
|
|
56
|
-
var html = "";
|
|
57
|
-
var post_data = qs.parse(body);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// received params in callback
|
|
61
|
-
console.log('Callback Response: ', post_data, "\n");
|
|
62
|
-
html += "<b>Callback Response</b><br>";
|
|
63
|
-
for(var x in post_data){
|
|
64
|
-
html += x + " => " + post_data[x] + "<br/>";
|
|
65
|
-
}
|
|
66
|
-
html += "<br/><br/>";
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// verify the checksum
|
|
70
|
-
var checksumhash = post_data.CHECKSUMHASH;
|
|
71
|
-
// delete post_data.CHECKSUMHASH;
|
|
72
|
-
var result = checksum_lib.verifychecksum(post_data, PaytmConfig.key, checksumhash);
|
|
73
|
-
console.log("Checksum Result => ", result, "\n");
|
|
74
|
-
html += "<b>Checksum Result</b> => " + (result? "True" : "False");
|
|
75
|
-
html += "<br/><br/>";
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Send Server-to-Server request to verify Order Status
|
|
80
|
-
var params = {"MID": PaytmConfig.mid, "ORDERID": post_data.ORDERID};
|
|
81
|
-
|
|
82
|
-
checksum_lib.genchecksum(params, PaytmConfig.key, function (err, checksum) {
|
|
83
|
-
|
|
84
|
-
params.CHECKSUMHASH = checksum;
|
|
85
|
-
post_data = 'JsonData='+JSON.stringify(params);
|
|
86
|
-
|
|
87
|
-
var options = {
|
|
88
|
-
hostname: 'securegw-stage.paytm.in', // for staging
|
|
89
|
-
// hostname: 'securegw.paytm.in', // for production
|
|
90
|
-
port: 443,
|
|
91
|
-
path: '/merchant-status/getTxnStatus',
|
|
92
|
-
method: 'POST',
|
|
93
|
-
headers: {
|
|
94
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
95
|
-
'Content-Length': post_data.length
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Set up the request
|
|
101
|
-
var response = "";
|
|
102
|
-
var post_req = https.request(options, function(post_res) {
|
|
103
|
-
post_res.on('data', function (chunk) {
|
|
104
|
-
response += chunk;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
post_res.on('end', function(){
|
|
108
|
-
console.log('S2S Response: ', response, "\n");
|
|
109
|
-
|
|
110
|
-
var _result = JSON.parse(response);
|
|
111
|
-
html += "<b>Status Check Response</b><br>";
|
|
112
|
-
for(var x in _result){
|
|
113
|
-
html += x + " => " + _result[x] + "<br/>";
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
117
|
-
res.write(html);
|
|
118
|
-
res.end();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// post the data
|
|
123
|
-
post_req.write(post_data);
|
|
124
|
-
post_req.end();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}).listen(port);
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
var User;
|
|
2
|
-
var Transaction = require('../models/np_transaction.model.js');
|
|
3
|
-
var IDLEN = 10;
|
|
4
|
-
function makeid(length) {
|
|
5
|
-
var text = "";
|
|
6
|
-
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
7
|
-
|
|
8
|
-
for (var i = 0; i < length; i++)
|
|
9
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
10
|
-
|
|
11
|
-
return text;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = function (app, callbacks) {
|
|
15
|
-
var module = {};
|
|
16
|
-
var config = (app.get('np_config'))
|
|
17
|
-
|
|
18
|
-
let usingMultiDbOrm = false;
|
|
19
|
-
if (config.db_url) {
|
|
20
|
-
User = require('../models/np_user.model.js');
|
|
21
|
-
usingMultiDbOrm = false;
|
|
22
|
-
} else if (app.multidborm) {
|
|
23
|
-
const sample = {
|
|
24
|
-
"id": "user_aB3dE9xY1Z",
|
|
25
|
-
"name": "tset",
|
|
26
|
-
"email": "testgmailcom",
|
|
27
|
-
"phone": "12345678",
|
|
28
|
-
"createdAt": "stringlarge",
|
|
29
|
-
"updatedAt": "stringlarge",
|
|
30
|
-
"returnUrl": "stringlarge"
|
|
31
|
-
}
|
|
32
|
-
User = require('../models/np_multidbplugin.js')('npusers', app.multidborm, sample);
|
|
33
|
-
User.db = app.multidborm;
|
|
34
|
-
User.modelname = 'npusers'
|
|
35
|
-
User.idFieldName = 'id'
|
|
36
|
-
app.NPUser = User;
|
|
37
|
-
usingMultiDbOrm = true;
|
|
38
|
-
}
|
|
39
|
-
module.create = (userData, cb) => {
|
|
40
|
-
|
|
41
|
-
User.findOne({ email: userData.email }, function (err, user) {
|
|
42
|
-
if (user) {
|
|
43
|
-
|
|
44
|
-
// console.log("User Update : ",userData.name );
|
|
45
|
-
var myquery = { email: userData.email };
|
|
46
|
-
|
|
47
|
-
var objForUpdate = user;
|
|
48
|
-
|
|
49
|
-
if (userData.email && userData.email.indexOf("@") !== -1) objForUpdate.email = userData.email;
|
|
50
|
-
if (userData.phone && userData.phone.length > 2) objForUpdate.phone = userData.phone;
|
|
51
|
-
if (userData.name && userData.name.length > 2) objForUpdate.name = userData.name;
|
|
52
|
-
delete objForUpdate._id;
|
|
53
|
-
var newvalues = { $set: objForUpdate };
|
|
54
|
-
//console.log("User Old : ",userData.name);
|
|
55
|
-
User.updateOne(myquery, newvalues, function (err, saveRes) {
|
|
56
|
-
if (err) cb({
|
|
57
|
-
message: err.message || "Some error occurred while updating users."
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// console.log("Sendiing callback")
|
|
61
|
-
cb(user);
|
|
62
|
-
// console.log("sent callback")
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} else {
|
|
67
|
-
|
|
68
|
-
// console.log("User New : ",userData.name);
|
|
69
|
-
|
|
70
|
-
userData.id = "user_" + makeid(IDLEN);
|
|
71
|
-
var userTask = new User(userData);
|
|
72
|
-
userTask.save()
|
|
73
|
-
.then(user => {
|
|
74
|
-
// console.log("Sendiing callback")
|
|
75
|
-
cb(user);
|
|
76
|
-
// console.log("sent callback")
|
|
77
|
-
|
|
78
|
-
}).catch(err => {
|
|
79
|
-
return cb(err);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}, usingMultiDbOrm ? User : undefined);
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
return module;
|
|
88
|
-
|
|
89
|
-
}
|