UNPKG

1.66 kBJavaScriptView Raw
1var Promise = require('promise');
2var winston = require('./winston');
3
4var Contact = function(config, single, plural){
5 var request = require('./c21request.js')(config)
6
7 return {
8
9
10 create: function(firstname, lastname, email, current_user){
11 var create = {}
12 create["firstname"] = firstname;
13 create["lastname"] = lastname;
14 create["email"] = email;
15 create["current_user"] = current_user;
16
17 winston.debug("chat21-node-sdk contact.create", create);
18
19
20 var admintoken = "";
21 if (config.admintoken) {
22 admintoken = "?token=" + encodeURIComponent(config.admintoken);
23 }
24
25
26 return new Promise(function(resolve, reject){
27 request.post('/' + plural+ admintoken, create).then(function(data){
28 winston.debug("chat21-node-sdk contact.created", data);
29 resolve(data)
30 }).catch(function(err){
31 reject(err)
32 })
33 })
34 },
35
36 update: function(firstname, lastname, current_user){
37 var update = {}
38
39
40 update["firstname"] = firstname;
41 update["lastname"] = lastname;
42 update["current_user"] = current_user;
43
44 winston.debug("chat21-node-sdk contact.update", update);
45
46
47 var admintoken = "";
48 if (config.admintoken) {
49 admintoken = "?token=" + encodeURIComponent(config.admintoken);
50 }
51
52
53 return new Promise(function(resolve, reject){
54 request.put('/' + plural+'/me'+ admintoken, update).then(function(data){
55 winston.debug("chat21-node-sdk contact.updated", data);
56 resolve(data)
57 }).catch(function(err){
58 reject(err)
59 })
60 })
61 }
62
63 }
64}
65
66module.exports = Contact