Built motion from commit 14588770.|2.5.38
[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 _0xab71=['bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','jayson/promise','http','request','then','SquareOdbc,\x20%s,\x20%s,\x20%s','stringify','error','code','SquareOdbc,\x20%s,\x20%s','message','info','result','catch','ShowSquareOdbc','find','options','raw','attributes','include','model','map','debug','lodash','util'];(function(_0xefd519,_0xc62635){var _0x4bb882=function(_0x37e0a1){while(--_0x37e0a1){_0xefd519['push'](_0xefd519['shift']());}};_0x4bb882(++_0xc62635);}(_0xab71,0x1a2));var _0x1ab7=function(_0x1cfe2e,_0x1ebbcd){_0x1cfe2e=_0x1cfe2e-0x0;var _0x39233f=_0xab71[_0x1cfe2e];return _0x39233f;};'use strict';var _=require(_0x1ab7('0x0'));var util=require(_0x1ab7('0x1'));var moment=require('moment');var BPromise=require(_0x1ab7('0x2'));var rs=require(_0x1ab7('0x3'));var fs=require('fs');var Redis=require(_0x1ab7('0x4'));var db=require(_0x1ab7('0x5'))['db'];var utils=require('../../config/utils');var logger=require(_0x1ab7('0x6'))(_0x1ab7('0x7'));var config=require('../../config/environment');var jayson=require(_0x1ab7('0x8'));var client=jayson['client'][_0x1ab7('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x482c1a,_0x5316e1,_0x8a2ba5){return new BPromise(function(_0x4534ff,_0x58577e){return client[_0x1ab7('0xa')](_0x482c1a,_0x8a2ba5)[_0x1ab7('0xb')](function(_0x33c237){logger['info']('SquareOdbc,\x20%s,\x20%s',_0x5316e1,'request\x20sent');logger['debug'](_0x1ab7('0xc'),_0x5316e1,'request\x20sent',JSON[_0x1ab7('0xd')](_0x33c237));if(_0x33c237[_0x1ab7('0xe')]){if(_0x33c237[_0x1ab7('0xe')][_0x1ab7('0xf')]===0x1f4){logger[_0x1ab7('0xe')](_0x1ab7('0x10'),_0x5316e1,_0x33c237[_0x1ab7('0xe')]['message']);return _0x58577e(_0x33c237[_0x1ab7('0xe')][_0x1ab7('0x11')]);}logger[_0x1ab7('0xe')](_0x1ab7('0x10'),_0x5316e1,_0x33c237['error'][_0x1ab7('0x11')]);return _0x4534ff(_0x33c237[_0x1ab7('0xe')][_0x1ab7('0x11')]);}else{logger[_0x1ab7('0x12')]('SquareOdbc,\x20%s,\x20%s',_0x5316e1,'request\x20sent');_0x4534ff(_0x33c237[_0x1ab7('0x13')][_0x1ab7('0x11')]);}})[_0x1ab7('0x14')](function(_0x359fac){logger[_0x1ab7('0xe')]('SquareOdbc,\x20%s,\x20%s',_0x5316e1,_0x359fac);_0x58577e(_0x359fac);});});}exports[_0x1ab7('0x15')]=function(_0x4be3fd){var _0x5d65df=this;return new Promise(function(_0x419acd,_0x2816a0){return db['SquareOdbc'][_0x1ab7('0x16')]({'raw':_0x4be3fd[_0x1ab7('0x17')]?_0x4be3fd[_0x1ab7('0x17')][_0x1ab7('0x18')]===undefined?!![]:![]:!![],'where':_0x4be3fd[_0x1ab7('0x17')]?_0x4be3fd[_0x1ab7('0x17')]['where']||null:null,'attributes':_0x4be3fd['options']?_0x4be3fd[_0x1ab7('0x17')][_0x1ab7('0x19')]||null:null,'include':_0x4be3fd[_0x1ab7('0x17')]?_0x4be3fd[_0x1ab7('0x17')][_0x1ab7('0x1a')]?_['map'](_0x4be3fd[_0x1ab7('0x17')][_0x1ab7('0x1a')],function(_0x4b7ee8){return{'model':db[_0x4b7ee8[_0x1ab7('0x1b')]],'as':_0x4b7ee8['as'],'attributes':_0x4b7ee8[_0x1ab7('0x19')],'include':_0x4b7ee8[_0x1ab7('0x1a')]?_[_0x1ab7('0x1c')](_0x4b7ee8[_0x1ab7('0x1a')],function(_0x51debf){return{'model':db[_0x51debf[_0x1ab7('0x1b')]],'as':_0x51debf['as'],'attributes':_0x51debf['attributes'],'include':_0x51debf['include']?_[_0x1ab7('0x1c')](_0x51debf[_0x1ab7('0x1a')],function(_0x38dd85){return{'model':db[_0x38dd85[_0x1ab7('0x1b')]],'as':_0x38dd85['as'],'attributes':_0x38dd85[_0x1ab7('0x19')]};}):[]};}):[]};}):[]:[]})[_0x1ab7('0xb')](function(_0x3e2cca){logger[_0x1ab7('0x12')](_0x1ab7('0x15'),_0x4be3fd);logger[_0x1ab7('0x1d')](_0x1ab7('0x15'),_0x4be3fd,JSON[_0x1ab7('0xd')](_0x3e2cca));_0x419acd(_0x3e2cca);})['catch'](function(_0x407153){logger[_0x1ab7('0xe')](_0x1ab7('0x15'),_0x407153[_0x1ab7('0x11')],_0x4be3fd);_0x2816a0(_0x5d65df[_0x1ab7('0xe')](0x1f4,_0x407153[_0x1ab7('0x11')]));});});};