Built motion from commit 87cd5f02.|2.5.48
[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 _0x9f0b=['jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','register','request','then','info','CmContact,\x20%s,\x20%s','request\x20sent','debug','error','code','message','result','catch','GetCmContact','CmContact','findAll','raw','options','where','limit','map','model','include','attributes','stringify','CreateCmContact','create','keys','body','length','startsWith','cf_','update','table','cm_contacts','id\x20=\x20?','toString','sequelize','query','util','moment','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment'];(function(_0xb6269b,_0x19a5c8){var _0x1c26cb=function(_0x4e5a54){while(--_0x4e5a54){_0xb6269b['push'](_0xb6269b['shift']());}};_0x1c26cb(++_0x19a5c8);}(_0x9f0b,0xfd));var _0xb9f0=function(_0x3e8270,_0x293590){_0x3e8270=_0x3e8270-0x0;var _0x1ccde9=_0x9f0b[_0x3e8270];return _0x1ccde9;};'use strict';var _=require('lodash');var util=require(_0xb9f0('0x0'));var moment=require(_0xb9f0('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xb9f0('0x2'));var squel=require('squel');var db=require('../../mysqldb')['db'];var utils=require(_0xb9f0('0x3'));var logger=require(_0xb9f0('0x4'))(_0xb9f0('0x5'));var config=require(_0xb9f0('0x6'));var jayson=require(_0xb9f0('0x7'));var client=jayson[_0xb9f0('0x8')][_0xb9f0('0x9')]({'port':0x232a});config[_0xb9f0('0xa')]=_[_0xb9f0('0xb')](config['redis'],{'host':_0xb9f0('0xc'),'port':0x18eb});var socket=require(_0xb9f0('0xd'))(new Redis(config[_0xb9f0('0xa')]));require('./cmContact.socket')[_0xb9f0('0xe')](socket);function respondWithRpcPromise(_0x493daa,_0x4981e3,_0x406d73){return new BPromise(function(_0xb6b859,_0x274e8d){return client[_0xb9f0('0xf')](_0x493daa,_0x406d73)[_0xb9f0('0x10')](function(_0x3ca2fc){logger[_0xb9f0('0x11')](_0xb9f0('0x12'),_0x4981e3,_0xb9f0('0x13'));logger[_0xb9f0('0x14')]('CmContact,\x20%s,\x20%s,\x20%s',_0x4981e3,_0xb9f0('0x13'),JSON['stringify'](_0x3ca2fc));if(_0x3ca2fc[_0xb9f0('0x15')]){if(_0x3ca2fc[_0xb9f0('0x15')][_0xb9f0('0x16')]===0x1f4){logger['error'](_0xb9f0('0x12'),_0x4981e3,_0x3ca2fc[_0xb9f0('0x15')][_0xb9f0('0x17')]);return _0x274e8d(_0x3ca2fc['error'][_0xb9f0('0x17')]);}logger['error'](_0xb9f0('0x12'),_0x4981e3,_0x3ca2fc[_0xb9f0('0x15')][_0xb9f0('0x17')]);return _0xb6b859(_0x3ca2fc[_0xb9f0('0x15')][_0xb9f0('0x17')]);}else{logger['info'](_0xb9f0('0x12'),_0x4981e3,_0xb9f0('0x13'));_0xb6b859(_0x3ca2fc[_0xb9f0('0x18')][_0xb9f0('0x17')]);}})[_0xb9f0('0x19')](function(_0x4278cb){logger[_0xb9f0('0x15')](_0xb9f0('0x12'),_0x4981e3,_0x4278cb);_0x274e8d(_0x4278cb);});});}exports[_0xb9f0('0x1a')]=function(_0x3d1f2f){var _0x3e2623=this;return new Promise(function(_0x2f30c5,_0x26f1d4){return db[_0xb9f0('0x1b')][_0xb9f0('0x1c')]({'raw':_0x3d1f2f['options']?_0x3d1f2f['options'][_0xb9f0('0x1d')]===undefined?!![]:![]:!![],'where':_0x3d1f2f[_0xb9f0('0x1e')]?_0x3d1f2f[_0xb9f0('0x1e')][_0xb9f0('0x1f')]||null:null,'attributes':_0x3d1f2f[_0xb9f0('0x1e')]?_0x3d1f2f[_0xb9f0('0x1e')]['attributes']||null:null,'limit':_0x3d1f2f[_0xb9f0('0x1e')]?_0x3d1f2f[_0xb9f0('0x1e')][_0xb9f0('0x20')]||null:null,'include':_0x3d1f2f[_0xb9f0('0x1e')]?_0x3d1f2f[_0xb9f0('0x1e')]['include']?_[_0xb9f0('0x21')](_0x3d1f2f[_0xb9f0('0x1e')]['include'],function(_0x540d3c){return{'model':db[_0x540d3c[_0xb9f0('0x22')]],'as':_0x540d3c['as'],'attributes':_0x540d3c['attributes'],'include':_0x540d3c[_0xb9f0('0x23')]?_[_0xb9f0('0x21')](_0x540d3c[_0xb9f0('0x23')],function(_0x55b314){return{'model':db[_0x55b314[_0xb9f0('0x22')]],'as':_0x55b314['as'],'attributes':_0x55b314['attributes'],'include':_0x55b314[_0xb9f0('0x23')]?_[_0xb9f0('0x21')](_0x55b314[_0xb9f0('0x23')],function(_0x37794b){return{'model':db[_0x37794b[_0xb9f0('0x22')]],'as':_0x37794b['as'],'attributes':_0x37794b[_0xb9f0('0x24')]};}):[]};}):[]};}):[]:[]})[_0xb9f0('0x10')](function(_0x8c508b){logger[_0xb9f0('0x11')]('GetCmContact',_0x3d1f2f);logger[_0xb9f0('0x14')](_0xb9f0('0x1a'),_0x3d1f2f,JSON[_0xb9f0('0x25')](_0x8c508b));_0x2f30c5(_0x8c508b);})['catch'](function(_0x4e6e33){logger[_0xb9f0('0x15')](_0xb9f0('0x1a'),_0x4e6e33['message'],_0x3d1f2f);_0x26f1d4(_0x3e2623['error'](0x1f4,_0x4e6e33[_0xb9f0('0x17')]));});});};exports[_0xb9f0('0x26')]=function(_0x240d69){var _0x13024a=this;return new Promise(function(_0x3fec55,_0x16025a){return db[_0xb9f0('0x1b')][_0xb9f0('0x27')](_0x240d69['body'],{'raw':_0x240d69[_0xb9f0('0x1e')]?_0x240d69[_0xb9f0('0x1e')]['raw']===undefined?!![]:![]:!![]})[_0xb9f0('0x10')](function(_0x43684b){var _0xa489f4;for(var _0x2f7a4f=0x0;_0x2f7a4f<Object[_0xb9f0('0x28')](_0x240d69[_0xb9f0('0x29')])[_0xb9f0('0x2a')];_0x2f7a4f++){var _0x1c48bb=Object[_0xb9f0('0x28')](_0x240d69['body'])[_0x2f7a4f];if(_0x1c48bb[_0xb9f0('0x2b')](_0xb9f0('0x2c'))){_0xa489f4=squel[_0xb9f0('0x2d')]()[_0xb9f0('0x2e')](_0xb9f0('0x2f'))['set'](_0x1c48bb,_0x240d69[_0xb9f0('0x29')][_0x1c48bb])[_0xb9f0('0x1f')](_0xb9f0('0x30'),_0x43684b['id'])[_0xb9f0('0x31')]();break;}}if(!_0xa489f4)return _0x43684b;return db[_0xb9f0('0x32')][_0xb9f0('0x33')](_0xa489f4)[_0xb9f0('0x10')](function(){return _0x43684b;});})[_0xb9f0('0x10')](function(_0x21926a){logger['info'](_0xb9f0('0x26'),_0x240d69);logger[_0xb9f0('0x14')](_0xb9f0('0x26'),_0x240d69,JSON['stringify'](_0x21926a));_0x3fec55(_0x21926a);})[_0xb9f0('0x19')](function(_0x3a3863){logger[_0xb9f0('0x15')](_0xb9f0('0x26'),_0x3a3863['message'],_0x240d69);_0x16025a(_0x13024a[_0xb9f0('0x15')](0x1f4,_0x3a3863['message']));});});};