Built motion from commit 9e1399f3.|2.5.37
[motion2.git] / server / api / squareOdbc / squareOdbc.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 _0xea67=['request','info','SquareOdbc,\x20%s,\x20%s','request\x20sent','SquareOdbc,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','SquareOdbc','options','attributes','include','map','model','then','ShowSquareOdbc','debug','util','bluebird','../../mysqldb','../../config/logger','rpc','../../config/environment','client','http'];(function(_0x539fb2,_0x5b6718){var _0x4d583d=function(_0x55fa69){while(--_0x55fa69){_0x539fb2['push'](_0x539fb2['shift']());}};_0x4d583d(++_0x5b6718);}(_0xea67,0xbc));var _0x7ea6=function(_0x57ac3b,_0x32e884){_0x57ac3b=_0x57ac3b-0x0;var _0x4204c9=_0xea67[_0x57ac3b];return _0x4204c9;};'use strict';var _=require('lodash');var util=require(_0x7ea6('0x0'));var moment=require('moment');var BPromise=require(_0x7ea6('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x7ea6('0x2'))['db'];var utils=require('../../config/utils');var logger=require(_0x7ea6('0x3'))(_0x7ea6('0x4'));var config=require(_0x7ea6('0x5'));var jayson=require('jayson/promise');var client=jayson[_0x7ea6('0x6')][_0x7ea6('0x7')]({'port':0x232a});function respondWithRpcPromise(_0x28857d,_0x511a15,_0x3a3870){return new BPromise(function(_0x2cbb2d,_0x1a1523){return client[_0x7ea6('0x8')](_0x28857d,_0x3a3870)['then'](function(_0x245949){logger[_0x7ea6('0x9')](_0x7ea6('0xa'),_0x511a15,_0x7ea6('0xb'));logger['debug'](_0x7ea6('0xc'),_0x511a15,'request\x20sent',JSON[_0x7ea6('0xd')](_0x245949));if(_0x245949[_0x7ea6('0xe')]){if(_0x245949['error'][_0x7ea6('0xf')]===0x1f4){logger['error'](_0x7ea6('0xa'),_0x511a15,_0x245949['error']['message']);return _0x1a1523(_0x245949[_0x7ea6('0xe')]['message']);}logger['error'](_0x7ea6('0xa'),_0x511a15,_0x245949['error'][_0x7ea6('0x10')]);return _0x2cbb2d(_0x245949[_0x7ea6('0xe')]['message']);}else{logger[_0x7ea6('0x9')]('SquareOdbc,\x20%s,\x20%s',_0x511a15,_0x7ea6('0xb'));_0x2cbb2d(_0x245949[_0x7ea6('0x11')][_0x7ea6('0x10')]);}})[_0x7ea6('0x12')](function(_0x4cc888){logger[_0x7ea6('0xe')](_0x7ea6('0xa'),_0x511a15,_0x4cc888);_0x1a1523(_0x4cc888);});});}exports['ShowSquareOdbc']=function(_0x20607e){var _0x29ad92=this;return new Promise(function(_0xe80127,_0x3aae09){return db[_0x7ea6('0x13')]['find']({'raw':_0x20607e[_0x7ea6('0x14')]?_0x20607e[_0x7ea6('0x14')]['raw']===undefined?!![]:![]:!![],'where':_0x20607e['options']?_0x20607e[_0x7ea6('0x14')]['where']||null:null,'attributes':_0x20607e[_0x7ea6('0x14')]?_0x20607e['options'][_0x7ea6('0x15')]||null:null,'include':_0x20607e[_0x7ea6('0x14')]?_0x20607e[_0x7ea6('0x14')][_0x7ea6('0x16')]?_[_0x7ea6('0x17')](_0x20607e[_0x7ea6('0x14')][_0x7ea6('0x16')],function(_0x4aced1){return{'model':db[_0x4aced1[_0x7ea6('0x18')]],'as':_0x4aced1['as'],'attributes':_0x4aced1[_0x7ea6('0x15')],'include':_0x4aced1[_0x7ea6('0x16')]?_['map'](_0x4aced1[_0x7ea6('0x16')],function(_0x3d9818){return{'model':db[_0x3d9818[_0x7ea6('0x18')]],'as':_0x3d9818['as'],'attributes':_0x3d9818[_0x7ea6('0x15')],'include':_0x3d9818[_0x7ea6('0x16')]?_[_0x7ea6('0x17')](_0x3d9818[_0x7ea6('0x16')],function(_0x45d937){return{'model':db[_0x45d937['model']],'as':_0x45d937['as'],'attributes':_0x45d937[_0x7ea6('0x15')]};}):[]};}):[]};}):[]:[]})[_0x7ea6('0x19')](function(_0x530a18){logger[_0x7ea6('0x9')](_0x7ea6('0x1a'),_0x20607e);logger[_0x7ea6('0x1b')](_0x7ea6('0x1a'),_0x20607e,JSON[_0x7ea6('0xd')](_0x530a18));_0xe80127(_0x530a18);})[_0x7ea6('0x12')](function(_0x14eb00){logger[_0x7ea6('0xe')]('ShowSquareOdbc',_0x14eb00[_0x7ea6('0x10')],_0x20607e);_0x3aae09(_0x29ad92[_0x7ea6('0xe')](0x1f4,_0x14eb00['message']));});});};