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 _0x230f=['moment','randomstring','squel','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','redis','defaults','localhost','register','request','then','info','CmContact,\x20%s,\x20%s','request\x20sent','debug','CmContact,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','catch','GetCmContact','findAll','options','where','limit','include','map','model','attributes','CreateCmContact','CmContact','create','body','raw','keys','length','startsWith','cf_','update','table','cm_contacts','id\x20=\x20?','toString','query','lodash'];(function(_0x1169fd,_0x58b9aa){var _0x2bb3a0=function(_0x1c8402){while(--_0x1c8402){_0x1169fd['push'](_0x1169fd['shift']());}};_0x2bb3a0(++_0x58b9aa);}(_0x230f,0x164));var _0xf230=function(_0x3e1829,_0xc8ccda){_0x3e1829=_0x3e1829-0x0;var _0x129345=_0x230f[_0x3e1829];return _0x129345;};'use strict';var _=require(_0xf230('0x0'));var util=require('util');var moment=require(_0xf230('0x1'));var BPromise=require('bluebird');var rs=require(_0xf230('0x2'));var fs=require('fs');var Redis=require('ioredis');var squel=require(_0xf230('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0xf230('0x4'));var logger=require(_0xf230('0x5'))(_0xf230('0x6'));var config=require(_0xf230('0x7'));var jayson=require(_0xf230('0x8'));var client=jayson[_0xf230('0x9')]['http']({'port':0x232a});config[_0xf230('0xa')]=_[_0xf230('0xb')](config[_0xf230('0xa')],{'host':_0xf230('0xc'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf230('0xa')]));require('./cmContact.socket')[_0xf230('0xd')](socket);function respondWithRpcPromise(_0x57d1bb,_0xb9f176,_0x3d0f68){return new BPromise(function(_0x497099,_0x3ffb56){return client[_0xf230('0xe')](_0x57d1bb,_0x3d0f68)[_0xf230('0xf')](function(_0xb7968){logger[_0xf230('0x10')](_0xf230('0x11'),_0xb9f176,_0xf230('0x12'));logger[_0xf230('0x13')](_0xf230('0x14'),_0xb9f176,_0xf230('0x12'),JSON[_0xf230('0x15')](_0xb7968));if(_0xb7968['error']){if(_0xb7968['error'][_0xf230('0x16')]===0x1f4){logger[_0xf230('0x17')](_0xf230('0x11'),_0xb9f176,_0xb7968[_0xf230('0x17')]['message']);return _0x3ffb56(_0xb7968['error'][_0xf230('0x18')]);}logger[_0xf230('0x17')](_0xf230('0x11'),_0xb9f176,_0xb7968[_0xf230('0x17')]['message']);return _0x497099(_0xb7968[_0xf230('0x17')][_0xf230('0x18')]);}else{logger[_0xf230('0x10')]('CmContact,\x20%s,\x20%s',_0xb9f176,_0xf230('0x12'));_0x497099(_0xb7968[_0xf230('0x19')][_0xf230('0x18')]);}})[_0xf230('0x1a')](function(_0x4d5620){logger['error'](_0xf230('0x11'),_0xb9f176,_0x4d5620);_0x3ffb56(_0x4d5620);});});}exports[_0xf230('0x1b')]=function(_0x1c210c){var _0x2e53fb=this;return new Promise(function(_0x47cdb2,_0x245194){return db['CmContact'][_0xf230('0x1c')]({'raw':_0x1c210c[_0xf230('0x1d')]?_0x1c210c[_0xf230('0x1d')]['raw']===undefined?!![]:![]:!![],'where':_0x1c210c[_0xf230('0x1d')]?_0x1c210c[_0xf230('0x1d')][_0xf230('0x1e')]||null:null,'attributes':_0x1c210c[_0xf230('0x1d')]?_0x1c210c['options']['attributes']||null:null,'limit':_0x1c210c[_0xf230('0x1d')]?_0x1c210c[_0xf230('0x1d')][_0xf230('0x1f')]||null:null,'include':_0x1c210c[_0xf230('0x1d')]?_0x1c210c[_0xf230('0x1d')][_0xf230('0x20')]?_[_0xf230('0x21')](_0x1c210c[_0xf230('0x1d')][_0xf230('0x20')],function(_0x52e53d){return{'model':db[_0x52e53d[_0xf230('0x22')]],'as':_0x52e53d['as'],'attributes':_0x52e53d[_0xf230('0x23')],'include':_0x52e53d[_0xf230('0x20')]?_['map'](_0x52e53d[_0xf230('0x20')],function(_0x1273cc){return{'model':db[_0x1273cc[_0xf230('0x22')]],'as':_0x1273cc['as'],'attributes':_0x1273cc['attributes'],'include':_0x1273cc[_0xf230('0x20')]?_[_0xf230('0x21')](_0x1273cc[_0xf230('0x20')],function(_0x5468a9){return{'model':db[_0x5468a9[_0xf230('0x22')]],'as':_0x5468a9['as'],'attributes':_0x5468a9[_0xf230('0x23')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x182a2b){logger[_0xf230('0x10')](_0xf230('0x1b'),_0x1c210c);logger[_0xf230('0x13')](_0xf230('0x1b'),_0x1c210c,JSON[_0xf230('0x15')](_0x182a2b));_0x47cdb2(_0x182a2b);})[_0xf230('0x1a')](function(_0x373d46){logger[_0xf230('0x17')](_0xf230('0x1b'),_0x373d46['message'],_0x1c210c);_0x245194(_0x2e53fb['error'](0x1f4,_0x373d46[_0xf230('0x18')]));});});};exports[_0xf230('0x24')]=function(_0x27e116){var _0x272d47=this;return new Promise(function(_0x54da50,_0x30ba1a){return db[_0xf230('0x25')][_0xf230('0x26')](_0x27e116[_0xf230('0x27')],{'raw':_0x27e116[_0xf230('0x1d')]?_0x27e116['options'][_0xf230('0x28')]===undefined?!![]:![]:!![]})['then'](function(_0x2d76b5){var _0x3ae6d3;for(var _0x9f9856=0x0;_0x9f9856<Object[_0xf230('0x29')](_0x27e116['body'])[_0xf230('0x2a')];_0x9f9856++){var _0x30d5f0=Object['keys'](_0x27e116[_0xf230('0x27')])[_0x9f9856];if(_0x30d5f0[_0xf230('0x2b')](_0xf230('0x2c'))){_0x3ae6d3=squel[_0xf230('0x2d')]()[_0xf230('0x2e')](_0xf230('0x2f'))['set'](_0x30d5f0,_0x27e116[_0xf230('0x27')][_0x30d5f0])[_0xf230('0x1e')](_0xf230('0x30'),_0x2d76b5['id'])[_0xf230('0x31')]();break;}}if(!_0x3ae6d3)return _0x2d76b5;return db['sequelize'][_0xf230('0x32')](_0x3ae6d3)[_0xf230('0xf')](function(){return _0x2d76b5;});})[_0xf230('0xf')](function(_0x4849a7){logger[_0xf230('0x10')](_0xf230('0x24'),_0x27e116);logger[_0xf230('0x13')]('CreateCmContact',_0x27e116,JSON[_0xf230('0x15')](_0x4849a7));_0x54da50(_0x4849a7);})['catch'](function(_0x1e8a34){logger[_0xf230('0x17')](_0xf230('0x24'),_0x1e8a34[_0xf230('0x18')],_0x27e116);_0x30ba1a(_0x272d47[_0xf230('0x17')](0x1f4,_0x1e8a34[_0xf230('0x18')]));});});};