d2ec36dd3aafe209acb3dfc1348088e918feca74
[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 _0x47b5=['../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','request','then','SquareOdbc,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','SquareOdbc','find','options','raw','where','attributes','include','map','model','ShowSquareOdbc','debug','catch','lodash','moment','randomstring'];(function(_0x1e98b7,_0xd2d354){var _0x377a45=function(_0x35fdea){while(--_0x35fdea){_0x1e98b7['push'](_0x1e98b7['shift']());}};_0x377a45(++_0xd2d354);}(_0x47b5,0xb7));var _0x547b=function(_0x16aa37,_0x26f688){_0x16aa37=_0x16aa37-0x0;var _0x14bb07=_0x47b5[_0x16aa37];return _0x14bb07;};'use strict';var _=require(_0x547b('0x0'));var util=require('util');var moment=require(_0x547b('0x1'));var BPromise=require('bluebird');var rs=require(_0x547b('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x547b('0x3'))['db'];var utils=require(_0x547b('0x4'));var logger=require(_0x547b('0x5'))(_0x547b('0x6'));var config=require(_0x547b('0x7'));var jayson=require('jayson/promise');var client=jayson[_0x547b('0x8')]['http']({'port':0x232a});function respondWithRpcPromise(_0xe9d310,_0x9c23d9,_0x31e2eb){return new BPromise(function(_0xeb6d9c,_0x37e1df){return client[_0x547b('0x9')](_0xe9d310,_0x31e2eb)[_0x547b('0xa')](function(_0x7949a9){logger['info'](_0x547b('0xb'),_0x9c23d9,_0x547b('0xc'));logger['debug']('SquareOdbc,\x20%s,\x20%s,\x20%s',_0x9c23d9,'request\x20sent',JSON[_0x547b('0xd')](_0x7949a9));if(_0x7949a9['error']){if(_0x7949a9[_0x547b('0xe')][_0x547b('0xf')]===0x1f4){logger[_0x547b('0xe')](_0x547b('0xb'),_0x9c23d9,_0x7949a9[_0x547b('0xe')][_0x547b('0x10')]);return _0x37e1df(_0x7949a9[_0x547b('0xe')][_0x547b('0x10')]);}logger[_0x547b('0xe')](_0x547b('0xb'),_0x9c23d9,_0x7949a9[_0x547b('0xe')][_0x547b('0x10')]);return _0xeb6d9c(_0x7949a9[_0x547b('0xe')][_0x547b('0x10')]);}else{logger[_0x547b('0x11')](_0x547b('0xb'),_0x9c23d9,_0x547b('0xc'));_0xeb6d9c(_0x7949a9[_0x547b('0x12')][_0x547b('0x10')]);}})['catch'](function(_0x5829c1){logger[_0x547b('0xe')](_0x547b('0xb'),_0x9c23d9,_0x5829c1);_0x37e1df(_0x5829c1);});});}exports['ShowSquareOdbc']=function(_0x1bf697){var _0x3bde63=this;return new Promise(function(_0x52587b,_0x168c54){return db[_0x547b('0x13')][_0x547b('0x14')]({'raw':_0x1bf697[_0x547b('0x15')]?_0x1bf697[_0x547b('0x15')][_0x547b('0x16')]===undefined?!![]:![]:!![],'where':_0x1bf697['options']?_0x1bf697[_0x547b('0x15')][_0x547b('0x17')]||null:null,'attributes':_0x1bf697['options']?_0x1bf697[_0x547b('0x15')][_0x547b('0x18')]||null:null,'include':_0x1bf697[_0x547b('0x15')]?_0x1bf697[_0x547b('0x15')][_0x547b('0x19')]?_[_0x547b('0x1a')](_0x1bf697[_0x547b('0x15')][_0x547b('0x19')],function(_0x1d18b8){return{'model':db[_0x1d18b8['model']],'as':_0x1d18b8['as'],'attributes':_0x1d18b8['attributes'],'include':_0x1d18b8[_0x547b('0x19')]?_['map'](_0x1d18b8[_0x547b('0x19')],function(_0x24e978){return{'model':db[_0x24e978[_0x547b('0x1b')]],'as':_0x24e978['as'],'attributes':_0x24e978[_0x547b('0x18')],'include':_0x24e978[_0x547b('0x19')]?_['map'](_0x24e978['include'],function(_0x15322a){return{'model':db[_0x15322a['model']],'as':_0x15322a['as'],'attributes':_0x15322a[_0x547b('0x18')]};}):[]};}):[]};}):[]:[]})[_0x547b('0xa')](function(_0x53fd9c){logger['info'](_0x547b('0x1c'),_0x1bf697);logger[_0x547b('0x1d')](_0x547b('0x1c'),_0x1bf697,JSON['stringify'](_0x53fd9c));_0x52587b(_0x53fd9c);})[_0x547b('0x1e')](function(_0x40180f){logger[_0x547b('0xe')](_0x547b('0x1c'),_0x40180f[_0x547b('0x10')],_0x1bf697);_0x168c54(_0x3bde63[_0x547b('0xe')](0x1f4,_0x40180f[_0x547b('0x10')]));});});};