535370bcc7be6b636d83e426ede55984df29a219
[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 _0xabc6=['moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','info','SquareOdbc,\x20%s,\x20%s','request\x20sent','debug','SquareOdbc,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','SquareOdbc','find','options','raw','where','attributes','include','map','model','then','ShowSquareOdbc','catch','util'];(function(_0x3bd2c8,_0x395b96){var _0x25374f=function(_0x5ee528){while(--_0x5ee528){_0x3bd2c8['push'](_0x3bd2c8['shift']());}};_0x25374f(++_0x395b96);}(_0xabc6,0x197));var _0x6abc=function(_0x52bfa5,_0x42cf21){_0x52bfa5=_0x52bfa5-0x0;var _0x26f80b=_0xabc6[_0x52bfa5];return _0x26f80b;};'use strict';var _=require('lodash');var util=require(_0x6abc('0x0'));var moment=require(_0x6abc('0x1'));var BPromise=require(_0x6abc('0x2'));var rs=require(_0x6abc('0x3'));var fs=require('fs');var Redis=require(_0x6abc('0x4'));var db=require(_0x6abc('0x5'))['db'];var utils=require(_0x6abc('0x6'));var logger=require(_0x6abc('0x7'))(_0x6abc('0x8'));var config=require(_0x6abc('0x9'));var jayson=require(_0x6abc('0xa'));var client=jayson[_0x6abc('0xb')]['http']({'port':0x232a});function respondWithRpcPromise(_0x116da0,_0x47a7e2,_0x57fd89){return new BPromise(function(_0x5c7839,_0x434575){return client['request'](_0x116da0,_0x57fd89)['then'](function(_0x1822a1){logger[_0x6abc('0xc')](_0x6abc('0xd'),_0x47a7e2,_0x6abc('0xe'));logger[_0x6abc('0xf')](_0x6abc('0x10'),_0x47a7e2,_0x6abc('0xe'),JSON[_0x6abc('0x11')](_0x1822a1));if(_0x1822a1[_0x6abc('0x12')]){if(_0x1822a1[_0x6abc('0x12')][_0x6abc('0x13')]===0x1f4){logger[_0x6abc('0x12')](_0x6abc('0xd'),_0x47a7e2,_0x1822a1[_0x6abc('0x12')][_0x6abc('0x14')]);return _0x434575(_0x1822a1['error'][_0x6abc('0x14')]);}logger[_0x6abc('0x12')](_0x6abc('0xd'),_0x47a7e2,_0x1822a1[_0x6abc('0x12')][_0x6abc('0x14')]);return _0x5c7839(_0x1822a1['error']['message']);}else{logger[_0x6abc('0xc')](_0x6abc('0xd'),_0x47a7e2,_0x6abc('0xe'));_0x5c7839(_0x1822a1[_0x6abc('0x15')][_0x6abc('0x14')]);}})['catch'](function(_0x1aaa15){logger[_0x6abc('0x12')]('SquareOdbc,\x20%s,\x20%s',_0x47a7e2,_0x1aaa15);_0x434575(_0x1aaa15);});});}exports['ShowSquareOdbc']=function(_0x204e65){var _0x58346a=this;return new Promise(function(_0x56dc76,_0x27bd42){return db[_0x6abc('0x16')][_0x6abc('0x17')]({'raw':_0x204e65[_0x6abc('0x18')]?_0x204e65['options'][_0x6abc('0x19')]===undefined?!![]:![]:!![],'where':_0x204e65[_0x6abc('0x18')]?_0x204e65[_0x6abc('0x18')][_0x6abc('0x1a')]||null:null,'attributes':_0x204e65[_0x6abc('0x18')]?_0x204e65['options'][_0x6abc('0x1b')]||null:null,'include':_0x204e65[_0x6abc('0x18')]?_0x204e65[_0x6abc('0x18')][_0x6abc('0x1c')]?_[_0x6abc('0x1d')](_0x204e65[_0x6abc('0x18')][_0x6abc('0x1c')],function(_0x5657be){return{'model':db[_0x5657be[_0x6abc('0x1e')]],'as':_0x5657be['as'],'attributes':_0x5657be['attributes'],'include':_0x5657be[_0x6abc('0x1c')]?_[_0x6abc('0x1d')](_0x5657be[_0x6abc('0x1c')],function(_0xb1256b){return{'model':db[_0xb1256b[_0x6abc('0x1e')]],'as':_0xb1256b['as'],'attributes':_0xb1256b['attributes'],'include':_0xb1256b[_0x6abc('0x1c')]?_['map'](_0xb1256b[_0x6abc('0x1c')],function(_0x3f8447){return{'model':db[_0x3f8447[_0x6abc('0x1e')]],'as':_0x3f8447['as'],'attributes':_0x3f8447[_0x6abc('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x6abc('0x1f')](function(_0x28f525){logger[_0x6abc('0xc')]('ShowSquareOdbc',_0x204e65);logger[_0x6abc('0xf')](_0x6abc('0x20'),_0x204e65,JSON[_0x6abc('0x11')](_0x28f525));_0x56dc76(_0x28f525);})[_0x6abc('0x21')](function(_0x19402c){logger[_0x6abc('0x12')](_0x6abc('0x20'),_0x19402c[_0x6abc('0x14')],_0x204e65);_0x27bd42(_0x58346a['error'](0x1f4,_0x19402c[_0x6abc('0x14')]));});});};