Built motion from commit (unavailable).|2.5.30
[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 _0x9b7c=['sequelize','catch','lodash','util','moment','squel','../../config/utils','../../config/logger','client','http','redis','defaults','localhost','register','request','then','info','CmContact,\x20%s,\x20%s','request\x20sent','debug','CmContact,\x20%s,\x20%s,\x20%s','error','code','message','CmContact','findAll','options','raw','attributes','limit','include','map','model','GetCmContact','stringify','CreateCmContact','body','keys','cf_','table','cm_contacts','set','where','id\x20=\x20?','toString'];(function(_0x1f1b05,_0x4a9825){var _0x510bd7=function(_0x143fe2){while(--_0x143fe2){_0x1f1b05['push'](_0x1f1b05['shift']());}};_0x510bd7(++_0x4a9825);}(_0x9b7c,0x1f1));var _0xc9b7=function(_0x13b330,_0x297092){_0x13b330=_0x13b330-0x0;var _0x1f666c=_0x9b7c[_0x13b330];return _0x1f666c;};'use strict';var _=require(_0xc9b7('0x0'));var util=require(_0xc9b7('0x1'));var moment=require(_0xc9b7('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var squel=require(_0xc9b7('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0xc9b7('0x4'));var logger=require(_0xc9b7('0x5'))('rpc');var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0xc9b7('0x6')][_0xc9b7('0x7')]({'port':0x232a});config[_0xc9b7('0x8')]=_[_0xc9b7('0x9')](config['redis'],{'host':_0xc9b7('0xa'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./cmContact.socket')[_0xc9b7('0xb')](socket);function respondWithRpcPromise(_0x598237,_0x6571b0,_0x3d0547){return new BPromise(function(_0x3972d3,_0x2a2019){return client[_0xc9b7('0xc')](_0x598237,_0x3d0547)[_0xc9b7('0xd')](function(_0xb6b54){logger[_0xc9b7('0xe')](_0xc9b7('0xf'),_0x6571b0,_0xc9b7('0x10'));logger[_0xc9b7('0x11')](_0xc9b7('0x12'),_0x6571b0,'request\x20sent',JSON['stringify'](_0xb6b54));if(_0xb6b54[_0xc9b7('0x13')]){if(_0xb6b54[_0xc9b7('0x13')][_0xc9b7('0x14')]===0x1f4){logger[_0xc9b7('0x13')](_0xc9b7('0xf'),_0x6571b0,_0xb6b54[_0xc9b7('0x13')][_0xc9b7('0x15')]);return _0x2a2019(_0xb6b54[_0xc9b7('0x13')][_0xc9b7('0x15')]);}logger[_0xc9b7('0x13')](_0xc9b7('0xf'),_0x6571b0,_0xb6b54[_0xc9b7('0x13')][_0xc9b7('0x15')]);return _0x3972d3(_0xb6b54['error'][_0xc9b7('0x15')]);}else{logger[_0xc9b7('0xe')]('CmContact,\x20%s,\x20%s',_0x6571b0,'request\x20sent');_0x3972d3(_0xb6b54['result']['message']);}})['catch'](function(_0x124c7f){logger[_0xc9b7('0x13')](_0xc9b7('0xf'),_0x6571b0,_0x124c7f);_0x2a2019(_0x124c7f);});});}exports['GetCmContact']=function(_0x295cf0){var _0x1bc68d=this;return new Promise(function(_0x3595cd,_0x28236d){return db[_0xc9b7('0x16')][_0xc9b7('0x17')]({'raw':_0x295cf0['options']?_0x295cf0[_0xc9b7('0x18')][_0xc9b7('0x19')]===undefined?!![]:![]:!![],'where':_0x295cf0[_0xc9b7('0x18')]?_0x295cf0[_0xc9b7('0x18')]['where']||null:null,'attributes':_0x295cf0['options']?_0x295cf0[_0xc9b7('0x18')][_0xc9b7('0x1a')]||null:null,'limit':_0x295cf0[_0xc9b7('0x18')]?_0x295cf0[_0xc9b7('0x18')][_0xc9b7('0x1b')]||null:null,'include':_0x295cf0[_0xc9b7('0x18')]?_0x295cf0['options'][_0xc9b7('0x1c')]?_[_0xc9b7('0x1d')](_0x295cf0[_0xc9b7('0x18')][_0xc9b7('0x1c')],function(_0x14ae16){return{'model':db[_0x14ae16[_0xc9b7('0x1e')]],'as':_0x14ae16['as'],'attributes':_0x14ae16[_0xc9b7('0x1a')],'include':_0x14ae16[_0xc9b7('0x1c')]?_[_0xc9b7('0x1d')](_0x14ae16[_0xc9b7('0x1c')],function(_0x214be7){return{'model':db[_0x214be7[_0xc9b7('0x1e')]],'as':_0x214be7['as'],'attributes':_0x214be7['attributes'],'include':_0x214be7[_0xc9b7('0x1c')]?_['map'](_0x214be7[_0xc9b7('0x1c')],function(_0x3c8ef4){return{'model':db[_0x3c8ef4['model']],'as':_0x3c8ef4['as'],'attributes':_0x3c8ef4[_0xc9b7('0x1a')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x48f3ff){logger['info'](_0xc9b7('0x1f'),_0x295cf0);logger[_0xc9b7('0x11')](_0xc9b7('0x1f'),_0x295cf0,JSON[_0xc9b7('0x20')](_0x48f3ff));_0x3595cd(_0x48f3ff);})['catch'](function(_0xcd4b40){logger['error']('GetCmContact',_0xcd4b40['message'],_0x295cf0);_0x28236d(_0x1bc68d[_0xc9b7('0x13')](0x1f4,_0xcd4b40['message']));});});};exports[_0xc9b7('0x21')]=function(_0xeeef12){var _0x5bd90d=this;return new Promise(function(_0x1e244a,_0x59aed3){return db[_0xc9b7('0x16')]['create'](_0xeeef12[_0xc9b7('0x22')],{'raw':_0xeeef12[_0xc9b7('0x18')]?_0xeeef12[_0xc9b7('0x18')][_0xc9b7('0x19')]===undefined?!![]:![]:!![]})['then'](function(_0x4d8991){var _0x484eab;for(var _0x3c3a84=0x0;_0x3c3a84<Object['keys'](_0xeeef12[_0xc9b7('0x22')])['length'];_0x3c3a84++){var _0x47e36a=Object[_0xc9b7('0x23')](_0xeeef12[_0xc9b7('0x22')])[_0x3c3a84];if(_0x47e36a['startsWith'](_0xc9b7('0x24'))){_0x484eab=squel['update']()[_0xc9b7('0x25')](_0xc9b7('0x26'))[_0xc9b7('0x27')](_0x47e36a,_0xeeef12[_0xc9b7('0x22')][_0x47e36a])[_0xc9b7('0x28')](_0xc9b7('0x29'),_0x4d8991['id'])[_0xc9b7('0x2a')]();break;}}if(!_0x484eab)return _0x4d8991;return db[_0xc9b7('0x2b')]['query'](_0x484eab)[_0xc9b7('0xd')](function(){return _0x4d8991;});})['then'](function(_0x1be3c5){logger[_0xc9b7('0xe')](_0xc9b7('0x21'),_0xeeef12);logger[_0xc9b7('0x11')](_0xc9b7('0x21'),_0xeeef12,JSON[_0xc9b7('0x20')](_0x1be3c5));_0x1e244a(_0x1be3c5);})[_0xc9b7('0x2c')](function(_0x1afffc){logger[_0xc9b7('0x13')](_0xc9b7('0x21'),_0x1afffc[_0xc9b7('0x15')],_0xeeef12);_0x59aed3(_0x5bd90d[_0xc9b7('0x13')](0x1f4,_0x1afffc['message']));});});};