699f4e84577e5963607b851a3829167def75eb67
[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 _0x231f=['../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','then','SquareOdbc,\x20%s,\x20%s','request\x20sent','SquareOdbc,\x20%s,\x20%s,\x20%s','error','code','message','info','result','catch','ShowSquareOdbc','SquareOdbc','options','raw','where','attributes','include','map','model','debug','stringify','lodash','moment','bluebird','randomstring','../../mysqldb'];(function(_0x1c0991,_0x4f22d2){var _0x5034de=function(_0x520f49){while(--_0x520f49){_0x1c0991['push'](_0x1c0991['shift']());}};_0x5034de(++_0x4f22d2);}(_0x231f,0x13b));var _0xf231=function(_0x595dd1,_0x474422){_0x595dd1=_0x595dd1-0x0;var _0x42064c=_0x231f[_0x595dd1];return _0x42064c;};'use strict';var _=require(_0xf231('0x0'));var util=require('util');var moment=require(_0xf231('0x1'));var BPromise=require(_0xf231('0x2'));var rs=require(_0xf231('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xf231('0x4'))['db'];var utils=require(_0xf231('0x5'));var logger=require(_0xf231('0x6'))(_0xf231('0x7'));var config=require(_0xf231('0x8'));var jayson=require(_0xf231('0x9'));var client=jayson['client'][_0xf231('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x3bf3af,_0x370912,_0x28d161){return new BPromise(function(_0x20bcbe,_0x3fddac){return client['request'](_0x3bf3af,_0x28d161)[_0xf231('0xb')](function(_0x5e336b){logger['info'](_0xf231('0xc'),_0x370912,_0xf231('0xd'));logger['debug'](_0xf231('0xe'),_0x370912,_0xf231('0xd'),JSON['stringify'](_0x5e336b));if(_0x5e336b[_0xf231('0xf')]){if(_0x5e336b[_0xf231('0xf')][_0xf231('0x10')]===0x1f4){logger[_0xf231('0xf')](_0xf231('0xc'),_0x370912,_0x5e336b[_0xf231('0xf')][_0xf231('0x11')]);return _0x3fddac(_0x5e336b['error'][_0xf231('0x11')]);}logger['error']('SquareOdbc,\x20%s,\x20%s',_0x370912,_0x5e336b['error'][_0xf231('0x11')]);return _0x20bcbe(_0x5e336b['error'][_0xf231('0x11')]);}else{logger[_0xf231('0x12')](_0xf231('0xc'),_0x370912,_0xf231('0xd'));_0x20bcbe(_0x5e336b[_0xf231('0x13')][_0xf231('0x11')]);}})[_0xf231('0x14')](function(_0x5a4e1a){logger[_0xf231('0xf')]('SquareOdbc,\x20%s,\x20%s',_0x370912,_0x5a4e1a);_0x3fddac(_0x5a4e1a);});});}exports[_0xf231('0x15')]=function(_0x22b1bc){var _0x1226ad=this;return new Promise(function(_0x37de49,_0x53361f){return db[_0xf231('0x16')]['find']({'raw':_0x22b1bc['options']?_0x22b1bc[_0xf231('0x17')][_0xf231('0x18')]===undefined?!![]:![]:!![],'where':_0x22b1bc[_0xf231('0x17')]?_0x22b1bc[_0xf231('0x17')][_0xf231('0x19')]||null:null,'attributes':_0x22b1bc[_0xf231('0x17')]?_0x22b1bc['options'][_0xf231('0x1a')]||null:null,'include':_0x22b1bc[_0xf231('0x17')]?_0x22b1bc['options'][_0xf231('0x1b')]?_[_0xf231('0x1c')](_0x22b1bc[_0xf231('0x17')][_0xf231('0x1b')],function(_0x153fa2){return{'model':db[_0x153fa2[_0xf231('0x1d')]],'as':_0x153fa2['as'],'attributes':_0x153fa2['attributes'],'include':_0x153fa2[_0xf231('0x1b')]?_[_0xf231('0x1c')](_0x153fa2[_0xf231('0x1b')],function(_0x37c643){return{'model':db[_0x37c643[_0xf231('0x1d')]],'as':_0x37c643['as'],'attributes':_0x37c643[_0xf231('0x1a')],'include':_0x37c643[_0xf231('0x1b')]?_[_0xf231('0x1c')](_0x37c643['include'],function(_0x4fc81c){return{'model':db[_0x4fc81c[_0xf231('0x1d')]],'as':_0x4fc81c['as'],'attributes':_0x4fc81c[_0xf231('0x1a')]};}):[]};}):[]};}):[]:[]})[_0xf231('0xb')](function(_0x86ca8){logger['info'](_0xf231('0x15'),_0x22b1bc);logger[_0xf231('0x1e')](_0xf231('0x15'),_0x22b1bc,JSON[_0xf231('0x1f')](_0x86ca8));_0x37de49(_0x86ca8);})[_0xf231('0x14')](function(_0x4e3c6f){logger[_0xf231('0xf')](_0xf231('0x15'),_0x4e3c6f[_0xf231('0x11')],_0x22b1bc);_0x53361f(_0x1226ad[_0xf231('0xf')](0x1f4,_0x4e3c6f[_0xf231('0x11')]));});});};