393a07bfd14830f80e11341301be684dc86f583d
[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 _0xe21c=['code','message','result','catch','SugarcrmAccount','options','raw','where','attributes','model','include','map','GetSugarcrmAccount','ShowSugarcrmAccount','randomstring','../../mysqldb','../../config/logger','../../config/environment','jayson/promise','client','http','request','then','info','SugarcrmAccount,\x20%s,\x20%s','debug','SugarcrmAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error'];(function(_0x17f6a5,_0x1d5148){var _0x315255=function(_0x30169d){while(--_0x30169d){_0x17f6a5['push'](_0x17f6a5['shift']());}};_0x315255(++_0x1d5148);}(_0xe21c,0x1d0));var _0xce21=function(_0x285c85,_0x132c21){_0x285c85=_0x285c85-0x0;var _0x2f81cd=_0xe21c[_0x285c85];return _0x2f81cd;};'use strict';var _=require('lodash');var util=require('util');var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0xce21('0x0'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xce21('0x1'))['db'];var utils=require('../../config/utils');var logger=require(_0xce21('0x2'))('rpc');var config=require(_0xce21('0x3'));var jayson=require(_0xce21('0x4'));var client=jayson[_0xce21('0x5')][_0xce21('0x6')]({'port':0x232a});function respondWithRpcPromise(_0x55ff0c,_0x1e6d82,_0x27dc88){return new BPromise(function(_0x39130e,_0x2084ff){return client[_0xce21('0x7')](_0x55ff0c,_0x27dc88)[_0xce21('0x8')](function(_0x56ece2){logger[_0xce21('0x9')](_0xce21('0xa'),_0x1e6d82,'request\x20sent');logger[_0xce21('0xb')](_0xce21('0xc'),_0x1e6d82,_0xce21('0xd'),JSON[_0xce21('0xe')](_0x56ece2));if(_0x56ece2[_0xce21('0xf')]){if(_0x56ece2['error'][_0xce21('0x10')]===0x1f4){logger[_0xce21('0xf')](_0xce21('0xa'),_0x1e6d82,_0x56ece2[_0xce21('0xf')][_0xce21('0x11')]);return _0x2084ff(_0x56ece2[_0xce21('0xf')]['message']);}logger[_0xce21('0xf')](_0xce21('0xa'),_0x1e6d82,_0x56ece2['error'][_0xce21('0x11')]);return _0x39130e(_0x56ece2[_0xce21('0xf')][_0xce21('0x11')]);}else{logger[_0xce21('0x9')](_0xce21('0xa'),_0x1e6d82,_0xce21('0xd'));_0x39130e(_0x56ece2[_0xce21('0x12')][_0xce21('0x11')]);}})[_0xce21('0x13')](function(_0x5aaf03){logger[_0xce21('0xf')](_0xce21('0xa'),_0x1e6d82,_0x5aaf03);_0x2084ff(_0x5aaf03);});});}exports['GetSugarcrmAccount']=function(_0x12cca1){var _0x13acae=this;return new Promise(function(_0x28fb02,_0x5cb20b){return db[_0xce21('0x14')]['findAll']({'raw':_0x12cca1[_0xce21('0x15')]?_0x12cca1['options'][_0xce21('0x16')]===undefined?!![]:![]:!![],'where':_0x12cca1[_0xce21('0x15')]?_0x12cca1[_0xce21('0x15')][_0xce21('0x17')]||null:null,'attributes':_0x12cca1[_0xce21('0x15')]?_0x12cca1[_0xce21('0x15')][_0xce21('0x18')]||null:null,'limit':_0x12cca1[_0xce21('0x15')]?_0x12cca1['options']['limit']||null:null,'include':_0x12cca1[_0xce21('0x15')]?_0x12cca1[_0xce21('0x15')]['include']?_['map'](_0x12cca1[_0xce21('0x15')]['include'],function(_0x2b62b1){return{'model':db[_0x2b62b1[_0xce21('0x19')]],'as':_0x2b62b1['as'],'attributes':_0x2b62b1[_0xce21('0x18')],'include':_0x2b62b1[_0xce21('0x1a')]?_[_0xce21('0x1b')](_0x2b62b1[_0xce21('0x1a')],function(_0x47a4cd){return{'model':db[_0x47a4cd[_0xce21('0x19')]],'as':_0x47a4cd['as'],'attributes':_0x47a4cd[_0xce21('0x18')],'include':_0x47a4cd[_0xce21('0x1a')]?_[_0xce21('0x1b')](_0x47a4cd['include'],function(_0x19f7bc){return{'model':db[_0x19f7bc[_0xce21('0x19')]],'as':_0x19f7bc['as'],'attributes':_0x19f7bc[_0xce21('0x18')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x4467b6){logger[_0xce21('0x9')]('GetSugarcrmAccount',_0x12cca1);logger[_0xce21('0xb')](_0xce21('0x1c'),_0x12cca1,JSON[_0xce21('0xe')](_0x4467b6));_0x28fb02(_0x4467b6);})[_0xce21('0x13')](function(_0x334e57){logger[_0xce21('0xf')](_0xce21('0x1c'),_0x334e57[_0xce21('0x11')],_0x12cca1);_0x5cb20b(_0x13acae[_0xce21('0xf')](0x1f4,_0x334e57[_0xce21('0x11')]));});});};exports[_0xce21('0x1d')]=function(_0x4745d5){var _0x40ab05=this;return new Promise(function(_0x4100f7,_0x2faa68){return db[_0xce21('0x14')]['find']({'raw':_0x4745d5[_0xce21('0x15')]?_0x4745d5[_0xce21('0x15')][_0xce21('0x16')]===undefined?!![]:![]:!![],'where':_0x4745d5[_0xce21('0x15')]?_0x4745d5[_0xce21('0x15')][_0xce21('0x17')]||null:null,'attributes':_0x4745d5[_0xce21('0x15')]?_0x4745d5[_0xce21('0x15')][_0xce21('0x18')]||null:null,'include':_0x4745d5[_0xce21('0x15')]?_0x4745d5[_0xce21('0x15')][_0xce21('0x1a')]?_[_0xce21('0x1b')](_0x4745d5[_0xce21('0x15')][_0xce21('0x1a')],function(_0x436a6a){return{'model':db[_0x436a6a[_0xce21('0x19')]],'as':_0x436a6a['as'],'attributes':_0x436a6a['attributes'],'include':_0x436a6a[_0xce21('0x1a')]?_[_0xce21('0x1b')](_0x436a6a['include'],function(_0x5018f5){return{'model':db[_0x5018f5[_0xce21('0x19')]],'as':_0x5018f5['as'],'attributes':_0x5018f5[_0xce21('0x18')],'include':_0x5018f5['include']?_[_0xce21('0x1b')](_0x5018f5[_0xce21('0x1a')],function(_0x420bc4){return{'model':db[_0x420bc4[_0xce21('0x19')]],'as':_0x420bc4['as'],'attributes':_0x420bc4[_0xce21('0x18')]};}):[]};}):[]};}):[]:[]})[_0xce21('0x8')](function(_0x36fd31){logger['info'](_0xce21('0x1d'),_0x4745d5);logger[_0xce21('0xb')]('ShowSugarcrmAccount',_0x4745d5,JSON['stringify'](_0x36fd31));_0x4100f7(_0x36fd31);})[_0xce21('0x13')](function(_0x4fc474){logger[_0xce21('0xf')]('ShowSugarcrmAccount',_0x4fc474[_0xce21('0x11')],_0x4745d5);_0x2faa68(_0x40ab05['error'](0x1f4,_0x4fc474[_0xce21('0x11')]));});});};