Built motion from commit a61a4a20.|2.5.46
[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 _0xebdc=['cm_contacts','set','id\x20=\x20?','toString','sequelize','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','defaults','localhost','./cmContact.socket','register','info','CmContact,\x20%s,\x20%s','request\x20sent','debug','error','message','result','catch','CmContact','findAll','raw','options','include','model','map','attributes','then','GetCmContact','stringify','CreateCmContact','body','keys','startsWith','cf_','update','table'];(function(_0x51407a,_0x2dd131){var _0x516aae=function(_0x47f66c){while(--_0x47f66c){_0x51407a['push'](_0x51407a['shift']());}};_0x516aae(++_0x2dd131);}(_0xebdc,0x15c));var _0xcebd=function(_0x5ba44c,_0x2adaa3){_0x5ba44c=_0x5ba44c-0x0;var _0x5c38ad=_0xebdc[_0x5ba44c];return _0x5c38ad;};'use strict';var _=require(_0xcebd('0x0'));var util=require(_0xcebd('0x1'));var moment=require(_0xcebd('0x2'));var BPromise=require(_0xcebd('0x3'));var rs=require(_0xcebd('0x4'));var fs=require('fs');var Redis=require(_0xcebd('0x5'));var squel=require('squel');var db=require(_0xcebd('0x6'))['db'];var utils=require(_0xcebd('0x7'));var logger=require(_0xcebd('0x8'))(_0xcebd('0x9'));var config=require(_0xcebd('0xa'));var jayson=require(_0xcebd('0xb'));var client=jayson[_0xcebd('0xc')]['http']({'port':0x232a});config[_0xcebd('0xd')]=_[_0xcebd('0xe')](config[_0xcebd('0xd')],{'host':_0xcebd('0xf'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xcebd('0xd')]));require(_0xcebd('0x10'))[_0xcebd('0x11')](socket);function respondWithRpcPromise(_0x86bd35,_0x49c7df,_0x4ad25b){return new BPromise(function(_0x4d1f22,_0x16afc3){return client['request'](_0x86bd35,_0x4ad25b)['then'](function(_0x1cdb8b){logger[_0xcebd('0x12')](_0xcebd('0x13'),_0x49c7df,_0xcebd('0x14'));logger[_0xcebd('0x15')]('CmContact,\x20%s,\x20%s,\x20%s',_0x49c7df,_0xcebd('0x14'),JSON['stringify'](_0x1cdb8b));if(_0x1cdb8b[_0xcebd('0x16')]){if(_0x1cdb8b[_0xcebd('0x16')]['code']===0x1f4){logger[_0xcebd('0x16')]('CmContact,\x20%s,\x20%s',_0x49c7df,_0x1cdb8b[_0xcebd('0x16')]['message']);return _0x16afc3(_0x1cdb8b['error']['message']);}logger[_0xcebd('0x16')](_0xcebd('0x13'),_0x49c7df,_0x1cdb8b[_0xcebd('0x16')][_0xcebd('0x17')]);return _0x4d1f22(_0x1cdb8b[_0xcebd('0x16')][_0xcebd('0x17')]);}else{logger[_0xcebd('0x12')]('CmContact,\x20%s,\x20%s',_0x49c7df,_0xcebd('0x14'));_0x4d1f22(_0x1cdb8b[_0xcebd('0x18')][_0xcebd('0x17')]);}})[_0xcebd('0x19')](function(_0x67e742){logger[_0xcebd('0x16')]('CmContact,\x20%s,\x20%s',_0x49c7df,_0x67e742);_0x16afc3(_0x67e742);});});}exports['GetCmContact']=function(_0x1a5022){var _0x1d6b9c=this;return new Promise(function(_0x358253,_0x5c5332){return db[_0xcebd('0x1a')][_0xcebd('0x1b')]({'raw':_0x1a5022['options']?_0x1a5022['options'][_0xcebd('0x1c')]===undefined?!![]:![]:!![],'where':_0x1a5022[_0xcebd('0x1d')]?_0x1a5022[_0xcebd('0x1d')]['where']||null:null,'attributes':_0x1a5022[_0xcebd('0x1d')]?_0x1a5022[_0xcebd('0x1d')]['attributes']||null:null,'limit':_0x1a5022['options']?_0x1a5022['options']['limit']||null:null,'include':_0x1a5022['options']?_0x1a5022[_0xcebd('0x1d')][_0xcebd('0x1e')]?_['map'](_0x1a5022[_0xcebd('0x1d')][_0xcebd('0x1e')],function(_0x21328c){return{'model':db[_0x21328c[_0xcebd('0x1f')]],'as':_0x21328c['as'],'attributes':_0x21328c['attributes'],'include':_0x21328c[_0xcebd('0x1e')]?_[_0xcebd('0x20')](_0x21328c[_0xcebd('0x1e')],function(_0x17bd3f){return{'model':db[_0x17bd3f[_0xcebd('0x1f')]],'as':_0x17bd3f['as'],'attributes':_0x17bd3f[_0xcebd('0x21')],'include':_0x17bd3f[_0xcebd('0x1e')]?_[_0xcebd('0x20')](_0x17bd3f[_0xcebd('0x1e')],function(_0x2ccf37){return{'model':db[_0x2ccf37['model']],'as':_0x2ccf37['as'],'attributes':_0x2ccf37[_0xcebd('0x21')]};}):[]};}):[]};}):[]:[]})[_0xcebd('0x22')](function(_0x49f1c3){logger['info'](_0xcebd('0x23'),_0x1a5022);logger['debug'](_0xcebd('0x23'),_0x1a5022,JSON[_0xcebd('0x24')](_0x49f1c3));_0x358253(_0x49f1c3);})[_0xcebd('0x19')](function(_0x20509e){logger[_0xcebd('0x16')](_0xcebd('0x23'),_0x20509e['message'],_0x1a5022);_0x5c5332(_0x1d6b9c[_0xcebd('0x16')](0x1f4,_0x20509e[_0xcebd('0x17')]));});});};exports[_0xcebd('0x25')]=function(_0x53176e){var _0x2789e6=this;return new Promise(function(_0x1783f4,_0x2cce34){return db[_0xcebd('0x1a')]['create'](_0x53176e[_0xcebd('0x26')],{'raw':_0x53176e[_0xcebd('0x1d')]?_0x53176e[_0xcebd('0x1d')][_0xcebd('0x1c')]===undefined?!![]:![]:!![]})[_0xcebd('0x22')](function(_0x600968){var _0x4b5506;for(var _0xca585d=0x0;_0xca585d<Object[_0xcebd('0x27')](_0x53176e['body'])['length'];_0xca585d++){var _0x30102c=Object[_0xcebd('0x27')](_0x53176e[_0xcebd('0x26')])[_0xca585d];if(_0x30102c[_0xcebd('0x28')](_0xcebd('0x29'))){_0x4b5506=squel[_0xcebd('0x2a')]()[_0xcebd('0x2b')](_0xcebd('0x2c'))[_0xcebd('0x2d')](_0x30102c,_0x53176e['body'][_0x30102c])['where'](_0xcebd('0x2e'),_0x600968['id'])[_0xcebd('0x2f')]();break;}}if(!_0x4b5506)return _0x600968;return db[_0xcebd('0x30')]['query'](_0x4b5506)['then'](function(){return _0x600968;});})['then'](function(_0x31f7d3){logger[_0xcebd('0x12')]('CreateCmContact',_0x53176e);logger[_0xcebd('0x15')](_0xcebd('0x25'),_0x53176e,JSON[_0xcebd('0x24')](_0x31f7d3));_0x1783f4(_0x31f7d3);})[_0xcebd('0x19')](function(_0x38dc3e){logger[_0xcebd('0x16')](_0xcebd('0x25'),_0x38dc3e[_0xcebd('0x17')],_0x53176e);_0x2cce34(_0x2789e6[_0xcebd('0x16')](0x1f4,_0x38dc3e[_0xcebd('0x17')]));});});};