5e7e2e641f534b4d74d8b9388b7f20cc7f906c14
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.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 _0xa2ae=['bluebird','randomstring','ioredis','../../mysqldb','rpc','../../config/environment','client','http','then','SugarcrmAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','result','catch','GetSugarcrmAccount','options','raw','where','attributes','limit','map','include','model','ShowSugarcrmAccount','find','lodash','moment'];(function(_0x56bda4,_0x5ba818){var _0x3f2edb=function(_0x4c0109){while(--_0x4c0109){_0x56bda4['push'](_0x56bda4['shift']());}};_0x3f2edb(++_0x5ba818);}(_0xa2ae,0x13e));var _0xea2a=function(_0x26447e,_0x2e9c94){_0x26447e=_0x26447e-0x0;var _0x38cc1a=_0xa2ae[_0x26447e];return _0x38cc1a;};'use strict';var _=require(_0xea2a('0x0'));var util=require('util');var moment=require(_0xea2a('0x1'));var BPromise=require(_0xea2a('0x2'));var rs=require(_0xea2a('0x3'));var fs=require('fs');var Redis=require(_0xea2a('0x4'));var db=require(_0xea2a('0x5'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0xea2a('0x6'));var config=require(_0xea2a('0x7'));var jayson=require('jayson/promise');var client=jayson[_0xea2a('0x8')][_0xea2a('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x3069c8,_0x747c7a,_0x38af7f){return new BPromise(function(_0x58fc32,_0x9157be){return client['request'](_0x3069c8,_0x38af7f)[_0xea2a('0xa')](function(_0x5d02a8){logger['info'](_0xea2a('0xb'),_0x747c7a,_0xea2a('0xc'));logger[_0xea2a('0xd')]('SugarcrmAccount,\x20%s,\x20%s,\x20%s',_0x747c7a,'request\x20sent',JSON[_0xea2a('0xe')](_0x5d02a8));if(_0x5d02a8[_0xea2a('0xf')]){if(_0x5d02a8[_0xea2a('0xf')][_0xea2a('0x10')]===0x1f4){logger['error'](_0xea2a('0xb'),_0x747c7a,_0x5d02a8[_0xea2a('0xf')]['message']);return _0x9157be(_0x5d02a8[_0xea2a('0xf')]['message']);}logger['error']('SugarcrmAccount,\x20%s,\x20%s',_0x747c7a,_0x5d02a8[_0xea2a('0xf')][_0xea2a('0x11')]);return _0x58fc32(_0x5d02a8[_0xea2a('0xf')][_0xea2a('0x11')]);}else{logger[_0xea2a('0x12')](_0xea2a('0xb'),_0x747c7a,_0xea2a('0xc'));_0x58fc32(_0x5d02a8[_0xea2a('0x13')][_0xea2a('0x11')]);}})[_0xea2a('0x14')](function(_0x4016a3){logger[_0xea2a('0xf')](_0xea2a('0xb'),_0x747c7a,_0x4016a3);_0x9157be(_0x4016a3);});});}exports[_0xea2a('0x15')]=function(_0x2f55c2){var _0x572e69=this;return new Promise(function(_0x5d4440,_0x156585){return db['SugarcrmAccount']['findAll']({'raw':_0x2f55c2[_0xea2a('0x16')]?_0x2f55c2[_0xea2a('0x16')][_0xea2a('0x17')]===undefined?!![]:![]:!![],'where':_0x2f55c2[_0xea2a('0x16')]?_0x2f55c2['options'][_0xea2a('0x18')]||null:null,'attributes':_0x2f55c2[_0xea2a('0x16')]?_0x2f55c2['options'][_0xea2a('0x19')]||null:null,'limit':_0x2f55c2['options']?_0x2f55c2[_0xea2a('0x16')][_0xea2a('0x1a')]||null:null,'include':_0x2f55c2['options']?_0x2f55c2[_0xea2a('0x16')]['include']?_[_0xea2a('0x1b')](_0x2f55c2['options'][_0xea2a('0x1c')],function(_0x3d34f1){return{'model':db[_0x3d34f1[_0xea2a('0x1d')]],'as':_0x3d34f1['as'],'attributes':_0x3d34f1[_0xea2a('0x19')],'include':_0x3d34f1[_0xea2a('0x1c')]?_[_0xea2a('0x1b')](_0x3d34f1[_0xea2a('0x1c')],function(_0x26a349){return{'model':db[_0x26a349[_0xea2a('0x1d')]],'as':_0x26a349['as'],'attributes':_0x26a349[_0xea2a('0x19')],'include':_0x26a349['include']?_['map'](_0x26a349[_0xea2a('0x1c')],function(_0xc528da){return{'model':db[_0xc528da[_0xea2a('0x1d')]],'as':_0xc528da['as'],'attributes':_0xc528da[_0xea2a('0x19')]};}):[]};}):[]};}):[]:[]})[_0xea2a('0xa')](function(_0x5501f4){logger[_0xea2a('0x12')](_0xea2a('0x15'),_0x2f55c2);logger[_0xea2a('0xd')](_0xea2a('0x15'),_0x2f55c2,JSON[_0xea2a('0xe')](_0x5501f4));_0x5d4440(_0x5501f4);})[_0xea2a('0x14')](function(_0xe42a3d){logger[_0xea2a('0xf')](_0xea2a('0x15'),_0xe42a3d[_0xea2a('0x11')],_0x2f55c2);_0x156585(_0x572e69[_0xea2a('0xf')](0x1f4,_0xe42a3d[_0xea2a('0x11')]));});});};exports[_0xea2a('0x1e')]=function(_0x2ad319){var _0x2e89f6=this;return new Promise(function(_0x2eca87,_0x21ea4a){return db['SugarcrmAccount'][_0xea2a('0x1f')]({'raw':_0x2ad319[_0xea2a('0x16')]?_0x2ad319[_0xea2a('0x16')][_0xea2a('0x17')]===undefined?!![]:![]:!![],'where':_0x2ad319[_0xea2a('0x16')]?_0x2ad319[_0xea2a('0x16')][_0xea2a('0x18')]||null:null,'attributes':_0x2ad319[_0xea2a('0x16')]?_0x2ad319[_0xea2a('0x16')][_0xea2a('0x19')]||null:null,'include':_0x2ad319[_0xea2a('0x16')]?_0x2ad319[_0xea2a('0x16')][_0xea2a('0x1c')]?_[_0xea2a('0x1b')](_0x2ad319[_0xea2a('0x16')][_0xea2a('0x1c')],function(_0x69df7c){return{'model':db[_0x69df7c[_0xea2a('0x1d')]],'as':_0x69df7c['as'],'attributes':_0x69df7c[_0xea2a('0x19')],'include':_0x69df7c['include']?_[_0xea2a('0x1b')](_0x69df7c['include'],function(_0x318aac){return{'model':db[_0x318aac[_0xea2a('0x1d')]],'as':_0x318aac['as'],'attributes':_0x318aac['attributes'],'include':_0x318aac[_0xea2a('0x1c')]?_[_0xea2a('0x1b')](_0x318aac[_0xea2a('0x1c')],function(_0x3e0a08){return{'model':db[_0x3e0a08[_0xea2a('0x1d')]],'as':_0x3e0a08['as'],'attributes':_0x3e0a08['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x15e2bc){logger[_0xea2a('0x12')](_0xea2a('0x1e'),_0x2ad319);logger[_0xea2a('0xd')](_0xea2a('0x1e'),_0x2ad319,JSON[_0xea2a('0xe')](_0x15e2bc));_0x2eca87(_0x15e2bc);})['catch'](function(_0x14efdb){logger[_0xea2a('0xf')](_0xea2a('0x1e'),_0x14efdb[_0xea2a('0x11')],_0x2ad319);_0x21ea4a(_0x2e89f6[_0xea2a('0xf')](0x1f4,_0x14efdb['message']));});});};