c8baba71faebbfb1e7342eab4b9a53c571989386
[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 _0x48b4=['map','model','ShowSquareOdbc','stringify','lodash','moment','bluebird','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','request','then','info','SquareOdbc,\x20%s,\x20%s','request\x20sent','debug','SquareOdbc,\x20%s,\x20%s,\x20%s','error','message','catch','SquareOdbc','find','options','attributes','include'];(function(_0xaa0309,_0x1c8008){var _0x5de7ce=function(_0x3aa6ae){while(--_0x3aa6ae){_0xaa0309['push'](_0xaa0309['shift']());}};_0x5de7ce(++_0x1c8008);}(_0x48b4,0xf4));var _0x448b=function(_0x14320d,_0x1e3877){_0x14320d=_0x14320d-0x0;var _0x5302a7=_0x48b4[_0x14320d];return _0x5302a7;};'use strict';var _=require(_0x448b('0x0'));var util=require('util');var moment=require(_0x448b('0x1'));var BPromise=require(_0x448b('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x448b('0x3'));var db=require(_0x448b('0x4'))['db'];var utils=require(_0x448b('0x5'));var logger=require(_0x448b('0x6'))(_0x448b('0x7'));var config=require('../../config/environment');var jayson=require(_0x448b('0x8'));var client=jayson[_0x448b('0x9')][_0x448b('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x1d03e5,_0x250e5c,_0x21c4a3){return new BPromise(function(_0x1178bd,_0x266de7){return client[_0x448b('0xb')](_0x1d03e5,_0x21c4a3)[_0x448b('0xc')](function(_0x1a27e2){logger[_0x448b('0xd')](_0x448b('0xe'),_0x250e5c,_0x448b('0xf'));logger[_0x448b('0x10')](_0x448b('0x11'),_0x250e5c,_0x448b('0xf'),JSON['stringify'](_0x1a27e2));if(_0x1a27e2[_0x448b('0x12')]){if(_0x1a27e2['error']['code']===0x1f4){logger[_0x448b('0x12')](_0x448b('0xe'),_0x250e5c,_0x1a27e2['error'][_0x448b('0x13')]);return _0x266de7(_0x1a27e2[_0x448b('0x12')][_0x448b('0x13')]);}logger[_0x448b('0x12')](_0x448b('0xe'),_0x250e5c,_0x1a27e2['error']['message']);return _0x1178bd(_0x1a27e2[_0x448b('0x12')][_0x448b('0x13')]);}else{logger[_0x448b('0xd')]('SquareOdbc,\x20%s,\x20%s',_0x250e5c,_0x448b('0xf'));_0x1178bd(_0x1a27e2['result'][_0x448b('0x13')]);}})[_0x448b('0x14')](function(_0x403a3b){logger['error'](_0x448b('0xe'),_0x250e5c,_0x403a3b);_0x266de7(_0x403a3b);});});}exports['ShowSquareOdbc']=function(_0x311228){var _0x2dd6f1=this;return new Promise(function(_0x5333d7,_0x1355da){return db[_0x448b('0x15')][_0x448b('0x16')]({'raw':_0x311228[_0x448b('0x17')]?_0x311228['options']['raw']===undefined?!![]:![]:!![],'where':_0x311228[_0x448b('0x17')]?_0x311228['options']['where']||null:null,'attributes':_0x311228[_0x448b('0x17')]?_0x311228[_0x448b('0x17')][_0x448b('0x18')]||null:null,'include':_0x311228[_0x448b('0x17')]?_0x311228[_0x448b('0x17')][_0x448b('0x19')]?_[_0x448b('0x1a')](_0x311228['options'][_0x448b('0x19')],function(_0x1ae4eb){return{'model':db[_0x1ae4eb[_0x448b('0x1b')]],'as':_0x1ae4eb['as'],'attributes':_0x1ae4eb[_0x448b('0x18')],'include':_0x1ae4eb[_0x448b('0x19')]?_[_0x448b('0x1a')](_0x1ae4eb['include'],function(_0x5dc845){return{'model':db[_0x5dc845[_0x448b('0x1b')]],'as':_0x5dc845['as'],'attributes':_0x5dc845[_0x448b('0x18')],'include':_0x5dc845[_0x448b('0x19')]?_[_0x448b('0x1a')](_0x5dc845[_0x448b('0x19')],function(_0x503b7b){return{'model':db[_0x503b7b['model']],'as':_0x503b7b['as'],'attributes':_0x503b7b[_0x448b('0x18')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x3dce1f){logger[_0x448b('0xd')](_0x448b('0x1c'),_0x311228);logger[_0x448b('0x10')](_0x448b('0x1c'),_0x311228,JSON[_0x448b('0x1d')](_0x3dce1f));_0x5333d7(_0x3dce1f);})['catch'](function(_0x2c5dce){logger[_0x448b('0x12')](_0x448b('0x1c'),_0x2c5dce['message'],_0x311228);_0x1355da(_0x2dd6f1[_0x448b('0x12')](0x1f4,_0x2c5dce[_0x448b('0x13')]));});});};