481eba7067ef85637a3844528fd05f78aa68bf8e
[motion2.git] / server / api / intZohoAccount / intZohoAccount.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 _0x6209=['moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','client','http','then','info','ZohoAccount,\x20%s,\x20%s','request\x20sent','debug','ZohoAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','GetZohoAccount','ZohoAccount','findAll','options','limit','include','map','model','attributes','where','ShowZohoAccount','catch','lodash','util'];(function(_0x599570,_0x460668){var _0x3d743f=function(_0x179db6){while(--_0x179db6){_0x599570['push'](_0x599570['shift']());}};_0x3d743f(++_0x460668);}(_0x6209,0x1e8));var _0x9620=function(_0x1facfa,_0x1acf7d){_0x1facfa=_0x1facfa-0x0;var _0x9ec701=_0x6209[_0x1facfa];return _0x9ec701;};'use strict';var _=require(_0x9620('0x0'));var util=require(_0x9620('0x1'));var moment=require(_0x9620('0x2'));var BPromise=require(_0x9620('0x3'));var rs=require(_0x9620('0x4'));var fs=require('fs');var Redis=require(_0x9620('0x5'));var db=require(_0x9620('0x6'))['db'];var utils=require('../../config/utils');var logger=require(_0x9620('0x7'))(_0x9620('0x8'));var config=require(_0x9620('0x9'));var jayson=require('jayson/promise');var client=jayson[_0x9620('0xa')][_0x9620('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x2bdb4e,_0x339bdc,_0x488d59){return new BPromise(function(_0x4e9082,_0x11af3d){return client['request'](_0x2bdb4e,_0x488d59)[_0x9620('0xc')](function(_0x345acb){logger[_0x9620('0xd')](_0x9620('0xe'),_0x339bdc,_0x9620('0xf'));logger[_0x9620('0x10')](_0x9620('0x11'),_0x339bdc,'request\x20sent',JSON[_0x9620('0x12')](_0x345acb));if(_0x345acb['error']){if(_0x345acb[_0x9620('0x13')][_0x9620('0x14')]===0x1f4){logger[_0x9620('0x13')](_0x9620('0xe'),_0x339bdc,_0x345acb[_0x9620('0x13')][_0x9620('0x15')]);return _0x11af3d(_0x345acb[_0x9620('0x13')][_0x9620('0x15')]);}logger[_0x9620('0x13')](_0x9620('0xe'),_0x339bdc,_0x345acb['error']['message']);return _0x4e9082(_0x345acb[_0x9620('0x13')][_0x9620('0x15')]);}else{logger['info'](_0x9620('0xe'),_0x339bdc,_0x9620('0xf'));_0x4e9082(_0x345acb[_0x9620('0x16')][_0x9620('0x15')]);}})['catch'](function(_0x2cb40e){logger[_0x9620('0x13')]('ZohoAccount,\x20%s,\x20%s',_0x339bdc,_0x2cb40e);_0x11af3d(_0x2cb40e);});});}exports[_0x9620('0x17')]=function(_0x4b81ea){var _0x10a166=this;return new Promise(function(_0x16514e,_0x2c8975){return db[_0x9620('0x18')][_0x9620('0x19')]({'raw':_0x4b81ea['options']?_0x4b81ea[_0x9620('0x1a')]['raw']===undefined?!![]:![]:!![],'where':_0x4b81ea['options']?_0x4b81ea['options']['where']||null:null,'attributes':_0x4b81ea['options']?_0x4b81ea[_0x9620('0x1a')]['attributes']||null:null,'limit':_0x4b81ea[_0x9620('0x1a')]?_0x4b81ea[_0x9620('0x1a')][_0x9620('0x1b')]||null:null,'include':_0x4b81ea[_0x9620('0x1a')]?_0x4b81ea[_0x9620('0x1a')][_0x9620('0x1c')]?_[_0x9620('0x1d')](_0x4b81ea['options']['include'],function(_0x1d8665){return{'model':db[_0x1d8665[_0x9620('0x1e')]],'as':_0x1d8665['as'],'attributes':_0x1d8665['attributes'],'include':_0x1d8665[_0x9620('0x1c')]?_[_0x9620('0x1d')](_0x1d8665[_0x9620('0x1c')],function(_0x156298){return{'model':db[_0x156298[_0x9620('0x1e')]],'as':_0x156298['as'],'attributes':_0x156298[_0x9620('0x1f')],'include':_0x156298[_0x9620('0x1c')]?_[_0x9620('0x1d')](_0x156298[_0x9620('0x1c')],function(_0x30c0cf){return{'model':db[_0x30c0cf[_0x9620('0x1e')]],'as':_0x30c0cf['as'],'attributes':_0x30c0cf['attributes']};}):[]};}):[]};}):[]:[]})[_0x9620('0xc')](function(_0x3e40aa){logger[_0x9620('0xd')](_0x9620('0x17'),_0x4b81ea);logger['debug']('GetZohoAccount',_0x4b81ea,JSON[_0x9620('0x12')](_0x3e40aa));_0x16514e(_0x3e40aa);})['catch'](function(_0xf2cb11){logger['error']('GetZohoAccount',_0xf2cb11[_0x9620('0x15')],_0x4b81ea);_0x2c8975(_0x10a166[_0x9620('0x13')](0x1f4,_0xf2cb11[_0x9620('0x15')]));});});};exports['ShowZohoAccount']=function(_0x19ddaf){var _0x186b4f=this;return new Promise(function(_0x42bfe6,_0x4cc78e){return db[_0x9620('0x18')]['find']({'raw':_0x19ddaf[_0x9620('0x1a')]?_0x19ddaf[_0x9620('0x1a')]['raw']===undefined?!![]:![]:!![],'where':_0x19ddaf[_0x9620('0x1a')]?_0x19ddaf[_0x9620('0x1a')][_0x9620('0x20')]||null:null,'attributes':_0x19ddaf[_0x9620('0x1a')]?_0x19ddaf['options']['attributes']||null:null,'include':_0x19ddaf['options']?_0x19ddaf['options'][_0x9620('0x1c')]?_[_0x9620('0x1d')](_0x19ddaf['options'][_0x9620('0x1c')],function(_0x3d80f9){return{'model':db[_0x3d80f9['model']],'as':_0x3d80f9['as'],'attributes':_0x3d80f9[_0x9620('0x1f')],'include':_0x3d80f9[_0x9620('0x1c')]?_['map'](_0x3d80f9[_0x9620('0x1c')],function(_0x360c64){return{'model':db[_0x360c64[_0x9620('0x1e')]],'as':_0x360c64['as'],'attributes':_0x360c64[_0x9620('0x1f')],'include':_0x360c64['include']?_[_0x9620('0x1d')](_0x360c64['include'],function(_0x908b02){return{'model':db[_0x908b02[_0x9620('0x1e')]],'as':_0x908b02['as'],'attributes':_0x908b02['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x2b213f){logger[_0x9620('0xd')](_0x9620('0x21'),_0x19ddaf);logger[_0x9620('0x10')](_0x9620('0x21'),_0x19ddaf,JSON['stringify'](_0x2b213f));_0x42bfe6(_0x2b213f);})[_0x9620('0x22')](function(_0x2d87fa){logger[_0x9620('0x13')](_0x9620('0x21'),_0x2d87fa[_0x9620('0x15')],_0x19ddaf);_0x4cc78e(_0x186b4f['error'](0x1f4,_0x2d87fa[_0x9620('0x15')]));});});};