Built motion from commit (unavailable).|2.5.20
[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 _0x06ce=['body','startsWith','cf_','update','cm_contacts','set','id\x20=\x20?','toString','sequelize','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','defaults','redis','localhost','./cmContact.socket','register','request','then','info','CmContact,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','result','catch','GetCmContact','CmContact','findAll','options','raw','where','attributes','limit','include','map','model','CreateCmContact','create'];(function(_0x6da5e6,_0x42d812){var _0x2e933f=function(_0x6b6b57){while(--_0x6b6b57){_0x6da5e6['push'](_0x6da5e6['shift']());}};_0x2e933f(++_0x42d812);}(_0x06ce,0xd9));var _0xe06c=function(_0x4cf98e,_0xba4b79){_0x4cf98e=_0x4cf98e-0x0;var _0x1623ac=_0x06ce[_0x4cf98e];return _0x1623ac;};'use strict';var _=require('lodash');var util=require(_0xe06c('0x0'));var moment=require(_0xe06c('0x1'));var BPromise=require(_0xe06c('0x2'));var rs=require(_0xe06c('0x3'));var fs=require('fs');var Redis=require(_0xe06c('0x4'));var squel=require('squel');var db=require(_0xe06c('0x5'))['db'];var utils=require(_0xe06c('0x6'));var logger=require(_0xe06c('0x7'))(_0xe06c('0x8'));var config=require(_0xe06c('0x9'));var jayson=require(_0xe06c('0xa'));var client=jayson[_0xe06c('0xb')][_0xe06c('0xc')]({'port':0x232a});config['redis']=_[_0xe06c('0xd')](config[_0xe06c('0xe')],{'host':_0xe06c('0xf'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xe06c('0x10'))[_0xe06c('0x11')](socket);function respondWithRpcPromise(_0x8e80c3,_0x1acb4c,_0x58dead){return new BPromise(function(_0x232b54,_0x29182d){return client[_0xe06c('0x12')](_0x8e80c3,_0x58dead)[_0xe06c('0x13')](function(_0x4ff85c){logger[_0xe06c('0x14')](_0xe06c('0x15'),_0x1acb4c,'request\x20sent');logger[_0xe06c('0x16')]('CmContact,\x20%s,\x20%s,\x20%s',_0x1acb4c,_0xe06c('0x17'),JSON[_0xe06c('0x18')](_0x4ff85c));if(_0x4ff85c[_0xe06c('0x19')]){if(_0x4ff85c[_0xe06c('0x19')][_0xe06c('0x1a')]===0x1f4){logger[_0xe06c('0x19')](_0xe06c('0x15'),_0x1acb4c,_0x4ff85c['error'][_0xe06c('0x1b')]);return _0x29182d(_0x4ff85c['error'][_0xe06c('0x1b')]);}logger['error']('CmContact,\x20%s,\x20%s',_0x1acb4c,_0x4ff85c[_0xe06c('0x19')]['message']);return _0x232b54(_0x4ff85c[_0xe06c('0x19')][_0xe06c('0x1b')]);}else{logger[_0xe06c('0x14')]('CmContact,\x20%s,\x20%s',_0x1acb4c,_0xe06c('0x17'));_0x232b54(_0x4ff85c[_0xe06c('0x1c')][_0xe06c('0x1b')]);}})[_0xe06c('0x1d')](function(_0x182e93){logger['error']('CmContact,\x20%s,\x20%s',_0x1acb4c,_0x182e93);_0x29182d(_0x182e93);});});}exports[_0xe06c('0x1e')]=function(_0x43de8f){var _0x2b0c58=this;return new Promise(function(_0x176c95,_0x290568){return db[_0xe06c('0x1f')][_0xe06c('0x20')]({'raw':_0x43de8f[_0xe06c('0x21')]?_0x43de8f[_0xe06c('0x21')][_0xe06c('0x22')]===undefined?!![]:![]:!![],'where':_0x43de8f[_0xe06c('0x21')]?_0x43de8f['options'][_0xe06c('0x23')]||null:null,'attributes':_0x43de8f[_0xe06c('0x21')]?_0x43de8f[_0xe06c('0x21')][_0xe06c('0x24')]||null:null,'limit':_0x43de8f[_0xe06c('0x21')]?_0x43de8f[_0xe06c('0x21')][_0xe06c('0x25')]||null:null,'include':_0x43de8f[_0xe06c('0x21')]?_0x43de8f[_0xe06c('0x21')][_0xe06c('0x26')]?_[_0xe06c('0x27')](_0x43de8f[_0xe06c('0x21')][_0xe06c('0x26')],function(_0x10191c){return{'model':db[_0x10191c[_0xe06c('0x28')]],'as':_0x10191c['as'],'attributes':_0x10191c[_0xe06c('0x24')],'include':_0x10191c[_0xe06c('0x26')]?_[_0xe06c('0x27')](_0x10191c[_0xe06c('0x26')],function(_0x1cc603){return{'model':db[_0x1cc603[_0xe06c('0x28')]],'as':_0x1cc603['as'],'attributes':_0x1cc603[_0xe06c('0x24')],'include':_0x1cc603[_0xe06c('0x26')]?_[_0xe06c('0x27')](_0x1cc603[_0xe06c('0x26')],function(_0x262adf){return{'model':db[_0x262adf[_0xe06c('0x28')]],'as':_0x262adf['as'],'attributes':_0x262adf[_0xe06c('0x24')]};}):[]};}):[]};}):[]:[]})[_0xe06c('0x13')](function(_0x1a59f7){logger[_0xe06c('0x14')](_0xe06c('0x1e'),_0x43de8f);logger['debug'](_0xe06c('0x1e'),_0x43de8f,JSON['stringify'](_0x1a59f7));_0x176c95(_0x1a59f7);})[_0xe06c('0x1d')](function(_0x837fc0){logger[_0xe06c('0x19')]('GetCmContact',_0x837fc0[_0xe06c('0x1b')],_0x43de8f);_0x290568(_0x2b0c58[_0xe06c('0x19')](0x1f4,_0x837fc0[_0xe06c('0x1b')]));});});};exports[_0xe06c('0x29')]=function(_0x5e3eeb){var _0x13d802=this;return new Promise(function(_0x4422f0,_0x413385){return db[_0xe06c('0x1f')][_0xe06c('0x2a')](_0x5e3eeb[_0xe06c('0x2b')],{'raw':_0x5e3eeb['options']?_0x5e3eeb[_0xe06c('0x21')][_0xe06c('0x22')]===undefined?!![]:![]:!![]})['then'](function(_0x1ef03e){var _0x95f4f;for(var _0xb1f205=0x0;_0xb1f205<Object['keys'](_0x5e3eeb[_0xe06c('0x2b')])['length'];_0xb1f205++){var _0x177bfb=Object['keys'](_0x5e3eeb['body'])[_0xb1f205];if(_0x177bfb[_0xe06c('0x2c')](_0xe06c('0x2d'))){_0x95f4f=squel[_0xe06c('0x2e')]()['table'](_0xe06c('0x2f'))[_0xe06c('0x30')](_0x177bfb,_0x5e3eeb[_0xe06c('0x2b')][_0x177bfb])['where'](_0xe06c('0x31'),_0x1ef03e['id'])[_0xe06c('0x32')]();break;}}if(!_0x95f4f)return _0x1ef03e;return db[_0xe06c('0x33')]['query'](_0x95f4f)['then'](function(){return _0x1ef03e;});})[_0xe06c('0x13')](function(_0x519771){logger['info'](_0xe06c('0x29'),_0x5e3eeb);logger[_0xe06c('0x16')]('CreateCmContact',_0x5e3eeb,JSON[_0xe06c('0x18')](_0x519771));_0x4422f0(_0x519771);})[_0xe06c('0x1d')](function(_0x3af4a8){logger['error'](_0xe06c('0x29'),_0x3af4a8['message'],_0x5e3eeb);_0x413385(_0x13d802[_0xe06c('0x19')](0x1f4,_0x3af4a8['message']));});});};