d482c4626b80f56192a17fdc2048ae4b6f8f896f
[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 _0xe1aa=['ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','request\x20sent','debug','SquareOdbc,\x20%s,\x20%s,\x20%s','stringify','error','code','SquareOdbc,\x20%s,\x20%s','message','catch','ShowSquareOdbc','find','options','attributes','include','model','map','then','info','lodash','util','moment','bluebird','randomstring'];(function(_0x107464,_0x1c5318){var _0x220dbd=function(_0x5f229d){while(--_0x5f229d){_0x107464['push'](_0x107464['shift']());}};_0x220dbd(++_0x1c5318);}(_0xe1aa,0x1bb));var _0xae1a=function(_0x5ddb1c,_0x5ea4df){_0x5ddb1c=_0x5ddb1c-0x0;var _0x354adc=_0xe1aa[_0x5ddb1c];return _0x354adc;};'use strict';var _=require(_0xae1a('0x0'));var util=require(_0xae1a('0x1'));var moment=require(_0xae1a('0x2'));var BPromise=require(_0xae1a('0x3'));var rs=require(_0xae1a('0x4'));var fs=require('fs');var Redis=require(_0xae1a('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0xae1a('0x6'));var logger=require(_0xae1a('0x7'))(_0xae1a('0x8'));var config=require(_0xae1a('0x9'));var jayson=require(_0xae1a('0xa'));var client=jayson[_0xae1a('0xb')][_0xae1a('0xc')]({'port':0x232a});function respondWithRpcPromise(_0x5a4c35,_0x579045,_0x16dd95){return new BPromise(function(_0x1f4389,_0x2081a4){return client[_0xae1a('0xd')](_0x5a4c35,_0x16dd95)['then'](function(_0x566af3){logger['info']('SquareOdbc,\x20%s,\x20%s',_0x579045,_0xae1a('0xe'));logger[_0xae1a('0xf')](_0xae1a('0x10'),_0x579045,_0xae1a('0xe'),JSON[_0xae1a('0x11')](_0x566af3));if(_0x566af3[_0xae1a('0x12')]){if(_0x566af3['error'][_0xae1a('0x13')]===0x1f4){logger['error'](_0xae1a('0x14'),_0x579045,_0x566af3['error'][_0xae1a('0x15')]);return _0x2081a4(_0x566af3[_0xae1a('0x12')][_0xae1a('0x15')]);}logger[_0xae1a('0x12')]('SquareOdbc,\x20%s,\x20%s',_0x579045,_0x566af3[_0xae1a('0x12')][_0xae1a('0x15')]);return _0x1f4389(_0x566af3[_0xae1a('0x12')][_0xae1a('0x15')]);}else{logger['info']('SquareOdbc,\x20%s,\x20%s',_0x579045,_0xae1a('0xe'));_0x1f4389(_0x566af3['result']['message']);}})[_0xae1a('0x16')](function(_0x2344e1){logger[_0xae1a('0x12')](_0xae1a('0x14'),_0x579045,_0x2344e1);_0x2081a4(_0x2344e1);});});}exports[_0xae1a('0x17')]=function(_0x3b239a){var _0x49578f=this;return new Promise(function(_0x49645a,_0x240aa8){return db['SquareOdbc'][_0xae1a('0x18')]({'raw':_0x3b239a[_0xae1a('0x19')]?_0x3b239a[_0xae1a('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x3b239a[_0xae1a('0x19')]?_0x3b239a['options']['where']||null:null,'attributes':_0x3b239a[_0xae1a('0x19')]?_0x3b239a[_0xae1a('0x19')][_0xae1a('0x1a')]||null:null,'include':_0x3b239a[_0xae1a('0x19')]?_0x3b239a[_0xae1a('0x19')][_0xae1a('0x1b')]?_['map'](_0x3b239a['options']['include'],function(_0x3800bb){return{'model':db[_0x3800bb[_0xae1a('0x1c')]],'as':_0x3800bb['as'],'attributes':_0x3800bb['attributes'],'include':_0x3800bb['include']?_[_0xae1a('0x1d')](_0x3800bb[_0xae1a('0x1b')],function(_0x27ea1d){return{'model':db[_0x27ea1d[_0xae1a('0x1c')]],'as':_0x27ea1d['as'],'attributes':_0x27ea1d[_0xae1a('0x1a')],'include':_0x27ea1d[_0xae1a('0x1b')]?_[_0xae1a('0x1d')](_0x27ea1d[_0xae1a('0x1b')],function(_0x1cdeef){return{'model':db[_0x1cdeef['model']],'as':_0x1cdeef['as'],'attributes':_0x1cdeef['attributes']};}):[]};}):[]};}):[]:[]})[_0xae1a('0x1e')](function(_0x5db020){logger[_0xae1a('0x1f')](_0xae1a('0x17'),_0x3b239a);logger[_0xae1a('0xf')](_0xae1a('0x17'),_0x3b239a,JSON[_0xae1a('0x11')](_0x5db020));_0x49645a(_0x5db020);})[_0xae1a('0x16')](function(_0x20e694){logger[_0xae1a('0x12')](_0xae1a('0x17'),_0x20e694[_0xae1a('0x15')],_0x3b239a);_0x240aa8(_0x49578f[_0xae1a('0x12')](0x1f4,_0x20e694[_0xae1a('0x15')]));});});};