Built motion from commit (unavailable).|2.5.24
[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 _0x4405=['error','code','message','info','request\x20sent','result','GetCmContact','CmContact','findAll','options','raw','where','include','map','model','attributes','then','catch','CreateCmContact','body','length','keys','startsWith','cf_','update','table','cm_contacts','set','id\x20=\x20?','toString','sequelize','query','lodash','moment','bluebird','ioredis','squel','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','defaults','localhost','request','CmContact,\x20%s,\x20%s','debug','stringify'];(function(_0x423a09,_0xbb6428){var _0x40ebda=function(_0x1e37fa){while(--_0x1e37fa){_0x423a09['push'](_0x423a09['shift']());}};_0x40ebda(++_0xbb6428);}(_0x4405,0x84));var _0x5440=function(_0x30f463,_0x5de677){_0x30f463=_0x30f463-0x0;var _0x1d8d0b=_0x4405[_0x30f463];return _0x1d8d0b;};'use strict';var _=require(_0x5440('0x0'));var util=require('util');var moment=require(_0x5440('0x1'));var BPromise=require(_0x5440('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x5440('0x3'));var squel=require(_0x5440('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x5440('0x5'));var logger=require(_0x5440('0x6'))(_0x5440('0x7'));var config=require(_0x5440('0x8'));var jayson=require(_0x5440('0x9'));var client=jayson[_0x5440('0xa')]['http']({'port':0x232a});config[_0x5440('0xb')]=_[_0x5440('0xc')](config[_0x5440('0xb')],{'host':_0x5440('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x5440('0xb')]));require('./cmContact.socket')['register'](socket);function respondWithRpcPromise(_0x22fe63,_0x2758fd,_0x7be837){return new BPromise(function(_0x2ccf20,_0x13a6c2){return client[_0x5440('0xe')](_0x22fe63,_0x7be837)['then'](function(_0x129cbb){logger['info'](_0x5440('0xf'),_0x2758fd,'request\x20sent');logger[_0x5440('0x10')]('CmContact,\x20%s,\x20%s,\x20%s',_0x2758fd,'request\x20sent',JSON[_0x5440('0x11')](_0x129cbb));if(_0x129cbb[_0x5440('0x12')]){if(_0x129cbb[_0x5440('0x12')][_0x5440('0x13')]===0x1f4){logger[_0x5440('0x12')](_0x5440('0xf'),_0x2758fd,_0x129cbb[_0x5440('0x12')]['message']);return _0x13a6c2(_0x129cbb[_0x5440('0x12')][_0x5440('0x14')]);}logger[_0x5440('0x12')](_0x5440('0xf'),_0x2758fd,_0x129cbb[_0x5440('0x12')][_0x5440('0x14')]);return _0x2ccf20(_0x129cbb[_0x5440('0x12')]['message']);}else{logger[_0x5440('0x15')]('CmContact,\x20%s,\x20%s',_0x2758fd,_0x5440('0x16'));_0x2ccf20(_0x129cbb[_0x5440('0x17')]['message']);}})['catch'](function(_0x5d7fc8){logger['error'](_0x5440('0xf'),_0x2758fd,_0x5d7fc8);_0x13a6c2(_0x5d7fc8);});});}exports[_0x5440('0x18')]=function(_0x50dacc){var _0x115dba=this;return new Promise(function(_0x550119,_0x3c0a2d){return db[_0x5440('0x19')][_0x5440('0x1a')]({'raw':_0x50dacc[_0x5440('0x1b')]?_0x50dacc[_0x5440('0x1b')][_0x5440('0x1c')]===undefined?!![]:![]:!![],'where':_0x50dacc[_0x5440('0x1b')]?_0x50dacc[_0x5440('0x1b')][_0x5440('0x1d')]||null:null,'attributes':_0x50dacc[_0x5440('0x1b')]?_0x50dacc['options']['attributes']||null:null,'limit':_0x50dacc[_0x5440('0x1b')]?_0x50dacc[_0x5440('0x1b')]['limit']||null:null,'include':_0x50dacc['options']?_0x50dacc[_0x5440('0x1b')][_0x5440('0x1e')]?_[_0x5440('0x1f')](_0x50dacc[_0x5440('0x1b')][_0x5440('0x1e')],function(_0x5ed28c){return{'model':db[_0x5ed28c[_0x5440('0x20')]],'as':_0x5ed28c['as'],'attributes':_0x5ed28c[_0x5440('0x21')],'include':_0x5ed28c[_0x5440('0x1e')]?_[_0x5440('0x1f')](_0x5ed28c[_0x5440('0x1e')],function(_0x27c9a4){return{'model':db[_0x27c9a4[_0x5440('0x20')]],'as':_0x27c9a4['as'],'attributes':_0x27c9a4[_0x5440('0x21')],'include':_0x27c9a4['include']?_[_0x5440('0x1f')](_0x27c9a4[_0x5440('0x1e')],function(_0x154c91){return{'model':db[_0x154c91[_0x5440('0x20')]],'as':_0x154c91['as'],'attributes':_0x154c91[_0x5440('0x21')]};}):[]};}):[]};}):[]:[]})[_0x5440('0x22')](function(_0x345703){logger['info']('GetCmContact',_0x50dacc);logger[_0x5440('0x10')](_0x5440('0x18'),_0x50dacc,JSON[_0x5440('0x11')](_0x345703));_0x550119(_0x345703);})[_0x5440('0x23')](function(_0x366d8c){logger[_0x5440('0x12')](_0x5440('0x18'),_0x366d8c[_0x5440('0x14')],_0x50dacc);_0x3c0a2d(_0x115dba[_0x5440('0x12')](0x1f4,_0x366d8c[_0x5440('0x14')]));});});};exports[_0x5440('0x24')]=function(_0x3501db){var _0x11aa5b=this;return new Promise(function(_0x197154,_0x2c62d7){return db['CmContact']['create'](_0x3501db[_0x5440('0x25')],{'raw':_0x3501db[_0x5440('0x1b')]?_0x3501db[_0x5440('0x1b')][_0x5440('0x1c')]===undefined?!![]:![]:!![]})[_0x5440('0x22')](function(_0x51daa5){var _0x2cc1f0;for(var _0x54b3d9=0x0;_0x54b3d9<Object['keys'](_0x3501db['body'])[_0x5440('0x26')];_0x54b3d9++){var _0x2ae94d=Object[_0x5440('0x27')](_0x3501db[_0x5440('0x25')])[_0x54b3d9];if(_0x2ae94d[_0x5440('0x28')](_0x5440('0x29'))){_0x2cc1f0=squel[_0x5440('0x2a')]()[_0x5440('0x2b')](_0x5440('0x2c'))[_0x5440('0x2d')](_0x2ae94d,_0x3501db[_0x5440('0x25')][_0x2ae94d])[_0x5440('0x1d')](_0x5440('0x2e'),_0x51daa5['id'])[_0x5440('0x2f')]();break;}}if(!_0x2cc1f0)return _0x51daa5;return db[_0x5440('0x30')][_0x5440('0x31')](_0x2cc1f0)[_0x5440('0x22')](function(){return _0x51daa5;});})[_0x5440('0x22')](function(_0x30f3d6){logger[_0x5440('0x15')](_0x5440('0x24'),_0x3501db);logger[_0x5440('0x10')](_0x5440('0x24'),_0x3501db,JSON[_0x5440('0x11')](_0x30f3d6));_0x197154(_0x30f3d6);})[_0x5440('0x23')](function(_0x46feab){logger[_0x5440('0x12')](_0x5440('0x24'),_0x46feab['message'],_0x3501db);_0x2c62d7(_0x11aa5b[_0x5440('0x12')](0x1f4,_0x46feab[_0x5440('0x14')]));});});};