Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / cmContact / cmContact.rpc.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x4b3f=['message','catch','CmContact','findAll','options','raw','where','attributes','map','include','GetCmContact','create','keys','body','cf_','update','table','cm_contacts','set','id\x20=\x20?','sequelize','CreateCmContact','lodash','util','moment','bluebird','randomstring','ioredis','squel','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','redis','defaults','localhost','register','request','then','info','CmContact,\x20%s,\x20%s','debug','CmContact,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error'];(function(_0x13e741,_0x5d3c24){var _0x3f8bb3=function(_0x4440a0){while(--_0x4440a0){_0x13e741['push'](_0x13e741['shift']());}};_0x3f8bb3(++_0x5d3c24);}(_0x4b3f,0x1bd));var _0xf4b3=function(_0x4bd766,_0x4e5259){_0x4bd766=_0x4bd766-0x0;var _0xce3d01=_0x4b3f[_0x4bd766];return _0xce3d01;};'use strict';var _=require(_0xf4b3('0x0'));var util=require(_0xf4b3('0x1'));var moment=require(_0xf4b3('0x2'));var BPromise=require(_0xf4b3('0x3'));var rs=require(_0xf4b3('0x4'));var fs=require('fs');var Redis=require(_0xf4b3('0x5'));var squel=require(_0xf4b3('0x6'));var db=require(_0xf4b3('0x7'))['db'];var utils=require('../../config/utils');var logger=require(_0xf4b3('0x8'))(_0xf4b3('0x9'));var config=require(_0xf4b3('0xa'));var jayson=require(_0xf4b3('0xb'));var client=jayson['client']['http']({'port':0x232a});config[_0xf4b3('0xc')]=_[_0xf4b3('0xd')](config[_0xf4b3('0xc')],{'host':_0xf4b3('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf4b3('0xc')]));require('./cmContact.socket')[_0xf4b3('0xf')](socket);function respondWithRpcPromise(_0x170780,_0x5167ed,_0x28255e){return new BPromise(function(_0x56e5b0,_0x1e8442){return client[_0xf4b3('0x10')](_0x170780,_0x28255e)[_0xf4b3('0x11')](function(_0x2d203e){logger[_0xf4b3('0x12')](_0xf4b3('0x13'),_0x5167ed,'request\x20sent');logger[_0xf4b3('0x14')](_0xf4b3('0x15'),_0x5167ed,_0xf4b3('0x16'),JSON[_0xf4b3('0x17')](_0x2d203e));if(_0x2d203e[_0xf4b3('0x18')]){if(_0x2d203e[_0xf4b3('0x18')]['code']===0x1f4){logger[_0xf4b3('0x18')](_0xf4b3('0x13'),_0x5167ed,_0x2d203e[_0xf4b3('0x18')][_0xf4b3('0x19')]);return _0x1e8442(_0x2d203e[_0xf4b3('0x18')][_0xf4b3('0x19')]);}logger[_0xf4b3('0x18')](_0xf4b3('0x13'),_0x5167ed,_0x2d203e[_0xf4b3('0x18')][_0xf4b3('0x19')]);return _0x56e5b0(_0x2d203e[_0xf4b3('0x18')][_0xf4b3('0x19')]);}else{logger[_0xf4b3('0x12')]('CmContact,\x20%s,\x20%s',_0x5167ed,_0xf4b3('0x16'));_0x56e5b0(_0x2d203e['result'][_0xf4b3('0x19')]);}})[_0xf4b3('0x1a')](function(_0xdc3ce3){logger['error'](_0xf4b3('0x13'),_0x5167ed,_0xdc3ce3);_0x1e8442(_0xdc3ce3);});});}exports['GetCmContact']=function(_0x32ba1c){var _0x3b4a8d=this;return new Promise(function(_0x2f564a,_0x1514ef){return db[_0xf4b3('0x1b')][_0xf4b3('0x1c')]({'raw':_0x32ba1c['options']?_0x32ba1c[_0xf4b3('0x1d')][_0xf4b3('0x1e')]===undefined?!![]:![]:!![],'where':_0x32ba1c[_0xf4b3('0x1d')]?_0x32ba1c[_0xf4b3('0x1d')][_0xf4b3('0x1f')]||null:null,'attributes':_0x32ba1c[_0xf4b3('0x1d')]?_0x32ba1c[_0xf4b3('0x1d')][_0xf4b3('0x20')]||null:null,'limit':_0x32ba1c['options']?_0x32ba1c['options']['limit']||null:null,'include':_0x32ba1c['options']?_0x32ba1c['options']['include']?_[_0xf4b3('0x21')](_0x32ba1c[_0xf4b3('0x1d')][_0xf4b3('0x22')],function(_0x5a876d){return{'model':db[_0x5a876d['model']],'as':_0x5a876d['as'],'attributes':_0x5a876d[_0xf4b3('0x20')],'include':_0x5a876d[_0xf4b3('0x22')]?_[_0xf4b3('0x21')](_0x5a876d[_0xf4b3('0x22')],function(_0x7f2c23){return{'model':db[_0x7f2c23['model']],'as':_0x7f2c23['as'],'attributes':_0x7f2c23[_0xf4b3('0x20')],'include':_0x7f2c23[_0xf4b3('0x22')]?_[_0xf4b3('0x21')](_0x7f2c23[_0xf4b3('0x22')],function(_0x21f938){return{'model':db[_0x21f938['model']],'as':_0x21f938['as'],'attributes':_0x21f938[_0xf4b3('0x20')]};}):[]};}):[]};}):[]:[]})[_0xf4b3('0x11')](function(_0x33faf9){logger['info']('GetCmContact',_0x32ba1c);logger[_0xf4b3('0x14')](_0xf4b3('0x23'),_0x32ba1c,JSON['stringify'](_0x33faf9));_0x2f564a(_0x33faf9);})[_0xf4b3('0x1a')](function(_0x525548){logger[_0xf4b3('0x18')](_0xf4b3('0x23'),_0x525548[_0xf4b3('0x19')],_0x32ba1c);_0x1514ef(_0x3b4a8d[_0xf4b3('0x18')](0x1f4,_0x525548[_0xf4b3('0x19')]));});});};exports['CreateCmContact']=function(_0xa1c0bf){var _0x96c3ca=this;return new Promise(function(_0xb033c9,_0x4cf7bb){return db[_0xf4b3('0x1b')][_0xf4b3('0x24')](_0xa1c0bf['body'],{'raw':_0xa1c0bf[_0xf4b3('0x1d')]?_0xa1c0bf[_0xf4b3('0x1d')][_0xf4b3('0x1e')]===undefined?!![]:![]:!![]})[_0xf4b3('0x11')](function(_0x2b7671){var _0x5ad88c;for(var _0x531870=0x0;_0x531870<Object[_0xf4b3('0x25')](_0xa1c0bf[_0xf4b3('0x26')])['length'];_0x531870++){var _0x10877=Object[_0xf4b3('0x25')](_0xa1c0bf[_0xf4b3('0x26')])[_0x531870];if(_0x10877['startsWith'](_0xf4b3('0x27'))){_0x5ad88c=squel[_0xf4b3('0x28')]()[_0xf4b3('0x29')](_0xf4b3('0x2a'))[_0xf4b3('0x2b')](_0x10877,_0xa1c0bf['body'][_0x10877])[_0xf4b3('0x1f')](_0xf4b3('0x2c'),_0x2b7671['id'])['toString']();break;}}if(!_0x5ad88c)return _0x2b7671;return db[_0xf4b3('0x2d')]['query'](_0x5ad88c)['then'](function(){return _0x2b7671;});})[_0xf4b3('0x11')](function(_0x5c85cf){logger[_0xf4b3('0x12')](_0xf4b3('0x2e'),_0xa1c0bf);logger[_0xf4b3('0x14')](_0xf4b3('0x2e'),_0xa1c0bf,JSON[_0xf4b3('0x17')](_0x5c85cf));_0xb033c9(_0x5c85cf);})[_0xf4b3('0x1a')](function(_0x56788c){logger['error']('CreateCmContact',_0x56788c[_0xf4b3('0x19')],_0xa1c0bf);_0x4cf7bb(_0x96c3ca['error'](0x1f4,_0x56788c['message']));});});};