Built motion from commit (unavailable).|2.5.21
[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 _0xf564=['CreateCmContact','create','keys','length','body','startsWith','cf_','update','table','cm_contacts','where','id\x20=\x20?','toString','sequelize','query','lodash','util','moment','randomstring','ioredis','squel','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','http','redis','defaults','localhost','./cmContact.socket','register','request','then','info','debug','CmContact,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','CmContact,\x20%s,\x20%s','message','result','GetCmContact','CmContact','findAll','options','raw','attributes','include','map','model','catch'];(function(_0x378891,_0x4e3e16){var _0xfbfda2=function(_0x3b7681){while(--_0x3b7681){_0x378891['push'](_0x378891['shift']());}};_0xfbfda2(++_0x4e3e16);}(_0xf564,0x14d));var _0x4f56=function(_0x56608c,_0x29eb74){_0x56608c=_0x56608c-0x0;var _0x3c7fb0=_0xf564[_0x56608c];return _0x3c7fb0;};'use strict';var _=require(_0x4f56('0x0'));var util=require(_0x4f56('0x1'));var moment=require(_0x4f56('0x2'));var BPromise=require('bluebird');var rs=require(_0x4f56('0x3'));var fs=require('fs');var Redis=require(_0x4f56('0x4'));var squel=require(_0x4f56('0x5'));var db=require(_0x4f56('0x6'))['db'];var utils=require(_0x4f56('0x7'));var logger=require(_0x4f56('0x8'))('rpc');var config=require(_0x4f56('0x9'));var jayson=require(_0x4f56('0xa'));var client=jayson['client'][_0x4f56('0xb')]({'port':0x232a});config[_0x4f56('0xc')]=_[_0x4f56('0xd')](config['redis'],{'host':_0x4f56('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4f56('0xc')]));require(_0x4f56('0xf'))[_0x4f56('0x10')](socket);function respondWithRpcPromise(_0x193468,_0x2ad047,_0x2e57a4){return new BPromise(function(_0x663ec7,_0x4d8c3a){return client[_0x4f56('0x11')](_0x193468,_0x2e57a4)[_0x4f56('0x12')](function(_0x11885c){logger[_0x4f56('0x13')]('CmContact,\x20%s,\x20%s',_0x2ad047,'request\x20sent');logger[_0x4f56('0x14')](_0x4f56('0x15'),_0x2ad047,_0x4f56('0x16'),JSON[_0x4f56('0x17')](_0x11885c));if(_0x11885c[_0x4f56('0x18')]){if(_0x11885c['error']['code']===0x1f4){logger[_0x4f56('0x18')](_0x4f56('0x19'),_0x2ad047,_0x11885c[_0x4f56('0x18')][_0x4f56('0x1a')]);return _0x4d8c3a(_0x11885c[_0x4f56('0x18')][_0x4f56('0x1a')]);}logger[_0x4f56('0x18')]('CmContact,\x20%s,\x20%s',_0x2ad047,_0x11885c[_0x4f56('0x18')][_0x4f56('0x1a')]);return _0x663ec7(_0x11885c['error'][_0x4f56('0x1a')]);}else{logger[_0x4f56('0x13')](_0x4f56('0x19'),_0x2ad047,_0x4f56('0x16'));_0x663ec7(_0x11885c[_0x4f56('0x1b')][_0x4f56('0x1a')]);}})['catch'](function(_0x5836b1){logger[_0x4f56('0x18')]('CmContact,\x20%s,\x20%s',_0x2ad047,_0x5836b1);_0x4d8c3a(_0x5836b1);});});}exports[_0x4f56('0x1c')]=function(_0x20ec36){var _0x31c7e7=this;return new Promise(function(_0x4b4a8d,_0x96e6fb){return db[_0x4f56('0x1d')][_0x4f56('0x1e')]({'raw':_0x20ec36[_0x4f56('0x1f')]?_0x20ec36[_0x4f56('0x1f')][_0x4f56('0x20')]===undefined?!![]:![]:!![],'where':_0x20ec36['options']?_0x20ec36[_0x4f56('0x1f')]['where']||null:null,'attributes':_0x20ec36[_0x4f56('0x1f')]?_0x20ec36[_0x4f56('0x1f')][_0x4f56('0x21')]||null:null,'limit':_0x20ec36[_0x4f56('0x1f')]?_0x20ec36['options']['limit']||null:null,'include':_0x20ec36[_0x4f56('0x1f')]?_0x20ec36['options']['include']?_['map'](_0x20ec36[_0x4f56('0x1f')][_0x4f56('0x22')],function(_0x1e58aa){return{'model':db[_0x1e58aa['model']],'as':_0x1e58aa['as'],'attributes':_0x1e58aa[_0x4f56('0x21')],'include':_0x1e58aa['include']?_[_0x4f56('0x23')](_0x1e58aa[_0x4f56('0x22')],function(_0x2545a9){return{'model':db[_0x2545a9[_0x4f56('0x24')]],'as':_0x2545a9['as'],'attributes':_0x2545a9[_0x4f56('0x21')],'include':_0x2545a9[_0x4f56('0x22')]?_[_0x4f56('0x23')](_0x2545a9[_0x4f56('0x22')],function(_0x30a400){return{'model':db[_0x30a400[_0x4f56('0x24')]],'as':_0x30a400['as'],'attributes':_0x30a400[_0x4f56('0x21')]};}):[]};}):[]};}):[]:[]})[_0x4f56('0x12')](function(_0x4fbc4d){logger[_0x4f56('0x13')](_0x4f56('0x1c'),_0x20ec36);logger[_0x4f56('0x14')]('GetCmContact',_0x20ec36,JSON[_0x4f56('0x17')](_0x4fbc4d));_0x4b4a8d(_0x4fbc4d);})[_0x4f56('0x25')](function(_0x2f7e14){logger[_0x4f56('0x18')](_0x4f56('0x1c'),_0x2f7e14[_0x4f56('0x1a')],_0x20ec36);_0x96e6fb(_0x31c7e7[_0x4f56('0x18')](0x1f4,_0x2f7e14[_0x4f56('0x1a')]));});});};exports[_0x4f56('0x26')]=function(_0x385dcf){var _0x54fc8c=this;return new Promise(function(_0x5b2dbe,_0x1a4258){return db[_0x4f56('0x1d')][_0x4f56('0x27')](_0x385dcf['body'],{'raw':_0x385dcf[_0x4f56('0x1f')]?_0x385dcf[_0x4f56('0x1f')][_0x4f56('0x20')]===undefined?!![]:![]:!![]})[_0x4f56('0x12')](function(_0x40c501){var _0x584657;for(var _0x4c6c8e=0x0;_0x4c6c8e<Object[_0x4f56('0x28')](_0x385dcf['body'])[_0x4f56('0x29')];_0x4c6c8e++){var _0xfa9c16=Object[_0x4f56('0x28')](_0x385dcf[_0x4f56('0x2a')])[_0x4c6c8e];if(_0xfa9c16[_0x4f56('0x2b')](_0x4f56('0x2c'))){_0x584657=squel[_0x4f56('0x2d')]()[_0x4f56('0x2e')](_0x4f56('0x2f'))['set'](_0xfa9c16,_0x385dcf['body'][_0xfa9c16])[_0x4f56('0x30')](_0x4f56('0x31'),_0x40c501['id'])[_0x4f56('0x32')]();break;}}if(!_0x584657)return _0x40c501;return db[_0x4f56('0x33')][_0x4f56('0x34')](_0x584657)[_0x4f56('0x12')](function(){return _0x40c501;});})[_0x4f56('0x12')](function(_0x150735){logger[_0x4f56('0x13')]('CreateCmContact',_0x385dcf);logger[_0x4f56('0x14')](_0x4f56('0x26'),_0x385dcf,JSON['stringify'](_0x150735));_0x5b2dbe(_0x150735);})['catch'](function(_0x3e27ef){logger[_0x4f56('0x18')]('CreateCmContact',_0x3e27ef[_0x4f56('0x1a')],_0x385dcf);_0x1a4258(_0x54fc8c[_0x4f56('0x18')](0x1f4,_0x3e27ef[_0x4f56('0x1a')]));});});};