Built motion from commit (unavailable).|2.6.0
[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 _0xe6a8=['../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','localhost','socket.io-emitter','./cmContact.socket','register','request','then','info','CmContact,\x20%s,\x20%s','request\x20sent','debug','CmContact,\x20%s,\x20%s,\x20%s','stringify','error','message','result','CmContact','findAll','options','raw','attributes','limit','include','map','model','GetCmContact','catch','CreateCmContact','create','body','length','keys','cf_','update','table','cm_contacts','set','toString','sequelize','query','lodash','util','moment','bluebird','randomstring','ioredis','squel','../../mysqldb'];(function(_0x4ca1b8,_0x9faad5){var _0x49b9e4=function(_0x360bcd){while(--_0x360bcd){_0x4ca1b8['push'](_0x4ca1b8['shift']());}};_0x49b9e4(++_0x9faad5);}(_0xe6a8,0x13c));var _0x8e6a=function(_0x171807,_0x541cc5){_0x171807=_0x171807-0x0;var _0x13ab8a=_0xe6a8[_0x171807];return _0x13ab8a;};'use strict';var _=require(_0x8e6a('0x0'));var util=require(_0x8e6a('0x1'));var moment=require(_0x8e6a('0x2'));var BPromise=require(_0x8e6a('0x3'));var rs=require(_0x8e6a('0x4'));var fs=require('fs');var Redis=require(_0x8e6a('0x5'));var squel=require(_0x8e6a('0x6'));var db=require(_0x8e6a('0x7'))['db'];var utils=require(_0x8e6a('0x8'));var logger=require(_0x8e6a('0x9'))('rpc');var config=require(_0x8e6a('0xa'));var jayson=require(_0x8e6a('0xb'));var client=jayson[_0x8e6a('0xc')][_0x8e6a('0xd')]({'port':0x232a});config[_0x8e6a('0xe')]=_['defaults'](config[_0x8e6a('0xe')],{'host':_0x8e6a('0xf'),'port':0x18eb});var socket=require(_0x8e6a('0x10'))(new Redis(config[_0x8e6a('0xe')]));require(_0x8e6a('0x11'))[_0x8e6a('0x12')](socket);function respondWithRpcPromise(_0x1aaa21,_0xc3355c,_0x29cd3c){return new BPromise(function(_0x20361b,_0x4fee07){return client[_0x8e6a('0x13')](_0x1aaa21,_0x29cd3c)[_0x8e6a('0x14')](function(_0x5bfa1d){logger[_0x8e6a('0x15')](_0x8e6a('0x16'),_0xc3355c,_0x8e6a('0x17'));logger[_0x8e6a('0x18')](_0x8e6a('0x19'),_0xc3355c,'request\x20sent',JSON[_0x8e6a('0x1a')](_0x5bfa1d));if(_0x5bfa1d[_0x8e6a('0x1b')]){if(_0x5bfa1d['error']['code']===0x1f4){logger[_0x8e6a('0x1b')](_0x8e6a('0x16'),_0xc3355c,_0x5bfa1d[_0x8e6a('0x1b')][_0x8e6a('0x1c')]);return _0x4fee07(_0x5bfa1d[_0x8e6a('0x1b')][_0x8e6a('0x1c')]);}logger['error']('CmContact,\x20%s,\x20%s',_0xc3355c,_0x5bfa1d[_0x8e6a('0x1b')][_0x8e6a('0x1c')]);return _0x20361b(_0x5bfa1d[_0x8e6a('0x1b')]['message']);}else{logger[_0x8e6a('0x15')](_0x8e6a('0x16'),_0xc3355c,'request\x20sent');_0x20361b(_0x5bfa1d[_0x8e6a('0x1d')][_0x8e6a('0x1c')]);}})['catch'](function(_0x21b9d2){logger[_0x8e6a('0x1b')]('CmContact,\x20%s,\x20%s',_0xc3355c,_0x21b9d2);_0x4fee07(_0x21b9d2);});});}exports['GetCmContact']=function(_0x16b37b){var _0x49fe06=this;return new Promise(function(_0x387a38,_0x3e40e8){return db[_0x8e6a('0x1e')][_0x8e6a('0x1f')]({'raw':_0x16b37b['options']?_0x16b37b[_0x8e6a('0x20')][_0x8e6a('0x21')]===undefined?!![]:![]:!![],'where':_0x16b37b[_0x8e6a('0x20')]?_0x16b37b[_0x8e6a('0x20')]['where']||null:null,'attributes':_0x16b37b[_0x8e6a('0x20')]?_0x16b37b[_0x8e6a('0x20')][_0x8e6a('0x22')]||null:null,'limit':_0x16b37b[_0x8e6a('0x20')]?_0x16b37b[_0x8e6a('0x20')][_0x8e6a('0x23')]||null:null,'include':_0x16b37b[_0x8e6a('0x20')]?_0x16b37b[_0x8e6a('0x20')][_0x8e6a('0x24')]?_[_0x8e6a('0x25')](_0x16b37b['options']['include'],function(_0x3485d9){return{'model':db[_0x3485d9[_0x8e6a('0x26')]],'as':_0x3485d9['as'],'attributes':_0x3485d9[_0x8e6a('0x22')],'include':_0x3485d9['include']?_[_0x8e6a('0x25')](_0x3485d9[_0x8e6a('0x24')],function(_0x4860f2){return{'model':db[_0x4860f2[_0x8e6a('0x26')]],'as':_0x4860f2['as'],'attributes':_0x4860f2[_0x8e6a('0x22')],'include':_0x4860f2[_0x8e6a('0x24')]?_[_0x8e6a('0x25')](_0x4860f2[_0x8e6a('0x24')],function(_0x40cbd7){return{'model':db[_0x40cbd7['model']],'as':_0x40cbd7['as'],'attributes':_0x40cbd7[_0x8e6a('0x22')]};}):[]};}):[]};}):[]:[]})[_0x8e6a('0x14')](function(_0x4bb319){logger[_0x8e6a('0x15')]('GetCmContact',_0x16b37b);logger[_0x8e6a('0x18')](_0x8e6a('0x27'),_0x16b37b,JSON['stringify'](_0x4bb319));_0x387a38(_0x4bb319);})[_0x8e6a('0x28')](function(_0x56f088){logger[_0x8e6a('0x1b')]('GetCmContact',_0x56f088['message'],_0x16b37b);_0x3e40e8(_0x49fe06[_0x8e6a('0x1b')](0x1f4,_0x56f088[_0x8e6a('0x1c')]));});});};exports[_0x8e6a('0x29')]=function(_0x52015a){var _0x352603=this;return new Promise(function(_0x164ec6,_0x484f3e){return db['CmContact'][_0x8e6a('0x2a')](_0x52015a[_0x8e6a('0x2b')],{'raw':_0x52015a[_0x8e6a('0x20')]?_0x52015a[_0x8e6a('0x20')]['raw']===undefined?!![]:![]:!![]})[_0x8e6a('0x14')](function(_0x45b56f){var _0x452c60;for(var _0x3b250f=0x0;_0x3b250f<Object['keys'](_0x52015a[_0x8e6a('0x2b')])[_0x8e6a('0x2c')];_0x3b250f++){var _0x1896e7=Object[_0x8e6a('0x2d')](_0x52015a['body'])[_0x3b250f];if(_0x1896e7['startsWith'](_0x8e6a('0x2e'))){_0x452c60=squel[_0x8e6a('0x2f')]()[_0x8e6a('0x30')](_0x8e6a('0x31'))[_0x8e6a('0x32')](_0x1896e7,_0x52015a[_0x8e6a('0x2b')][_0x1896e7])['where']('id\x20=\x20?',_0x45b56f['id'])[_0x8e6a('0x33')]();break;}}if(!_0x452c60)return _0x45b56f;return db[_0x8e6a('0x34')][_0x8e6a('0x35')](_0x452c60)[_0x8e6a('0x14')](function(){return _0x45b56f;});})['then'](function(_0x40d7f9){logger['info'](_0x8e6a('0x29'),_0x52015a);logger[_0x8e6a('0x18')](_0x8e6a('0x29'),_0x52015a,JSON[_0x8e6a('0x1a')](_0x40d7f9));_0x164ec6(_0x40d7f9);})['catch'](function(_0x333a2a){logger['error'](_0x8e6a('0x29'),_0x333a2a[_0x8e6a('0x1c')],_0x52015a);_0x484f3e(_0x352603['error'](0x1f4,_0x333a2a[_0x8e6a('0x1c')]));});});};