Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / api / trigger / trigger.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 _0xfeba=['Trigger,\x20%s,\x20%s,\x20%s','error','Trigger,\x20%s,\x20%s','message','request\x20sent','result','catch','Trigger','findAll','options','raw','where','attributes','include','map','model','GetTrigger','stringify','ShowTrigger','lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','request','then','info','debug'];(function(_0x2c00ab,_0x7ff8de){var _0xbe2216=function(_0x2393e0){while(--_0x2393e0){_0x2c00ab['push'](_0x2c00ab['shift']());}};_0xbe2216(++_0x7ff8de);}(_0xfeba,0x1cd));var _0xafeb=function(_0x21974e,_0x57d7a2){_0x21974e=_0x21974e-0x0;var _0x3e65a5=_0xfeba[_0x21974e];return _0x3e65a5;};'use strict';var _=require(_0xafeb('0x0'));var util=require(_0xafeb('0x1'));var moment=require(_0xafeb('0x2'));var BPromise=require(_0xafeb('0x3'));var rs=require(_0xafeb('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xafeb('0x5'))['db'];var utils=require(_0xafeb('0x6'));var logger=require(_0xafeb('0x7'))('rpc');var config=require(_0xafeb('0x8'));var jayson=require(_0xafeb('0x9'));var client=jayson[_0xafeb('0xa')]['http']({'port':0x232a});function respondWithRpcPromise(_0xa34f8c,_0xc6e50a,_0x23e126){return new BPromise(function(_0x1b21f8,_0x3d4b18){return client[_0xafeb('0xb')](_0xa34f8c,_0x23e126)[_0xafeb('0xc')](function(_0x5b3a81){logger[_0xafeb('0xd')]('Trigger,\x20%s,\x20%s',_0xc6e50a,'request\x20sent');logger[_0xafeb('0xe')](_0xafeb('0xf'),_0xc6e50a,'request\x20sent',JSON['stringify'](_0x5b3a81));if(_0x5b3a81[_0xafeb('0x10')]){if(_0x5b3a81[_0xafeb('0x10')]['code']===0x1f4){logger[_0xafeb('0x10')](_0xafeb('0x11'),_0xc6e50a,_0x5b3a81[_0xafeb('0x10')][_0xafeb('0x12')]);return _0x3d4b18(_0x5b3a81[_0xafeb('0x10')][_0xafeb('0x12')]);}logger[_0xafeb('0x10')](_0xafeb('0x11'),_0xc6e50a,_0x5b3a81[_0xafeb('0x10')][_0xafeb('0x12')]);return _0x1b21f8(_0x5b3a81['error'][_0xafeb('0x12')]);}else{logger['info'](_0xafeb('0x11'),_0xc6e50a,_0xafeb('0x13'));_0x1b21f8(_0x5b3a81[_0xafeb('0x14')][_0xafeb('0x12')]);}})[_0xafeb('0x15')](function(_0x4b3b72){logger[_0xafeb('0x10')](_0xafeb('0x11'),_0xc6e50a,_0x4b3b72);_0x3d4b18(_0x4b3b72);});});}exports['GetTrigger']=function(_0x599067){var _0x423bc1=this;return new Promise(function(_0x141afe,_0x398c60){return db[_0xafeb('0x16')][_0xafeb('0x17')]({'raw':_0x599067['options']?_0x599067[_0xafeb('0x18')][_0xafeb('0x19')]===undefined?!![]:![]:!![],'where':_0x599067[_0xafeb('0x18')]?_0x599067[_0xafeb('0x18')][_0xafeb('0x1a')]||null:null,'attributes':_0x599067[_0xafeb('0x18')]?_0x599067[_0xafeb('0x18')][_0xafeb('0x1b')]||null:null,'limit':_0x599067[_0xafeb('0x18')]?_0x599067[_0xafeb('0x18')]['limit']||null:null,'include':_0x599067['options']?_0x599067[_0xafeb('0x18')][_0xafeb('0x1c')]?_[_0xafeb('0x1d')](_0x599067['options'][_0xafeb('0x1c')],function(_0x331fe1){return{'model':db[_0x331fe1[_0xafeb('0x1e')]],'as':_0x331fe1['as'],'attributes':_0x331fe1[_0xafeb('0x1b')],'include':_0x331fe1[_0xafeb('0x1c')]?_[_0xafeb('0x1d')](_0x331fe1['include'],function(_0x2b1b52){return{'model':db[_0x2b1b52['model']],'as':_0x2b1b52['as'],'attributes':_0x2b1b52[_0xafeb('0x1b')],'include':_0x2b1b52[_0xafeb('0x1c')]?_[_0xafeb('0x1d')](_0x2b1b52['include'],function(_0x255cdf){return{'model':db[_0x255cdf[_0xafeb('0x1e')]],'as':_0x255cdf['as'],'attributes':_0x255cdf['attributes']};}):[]};}):[]};}):[]:[]})[_0xafeb('0xc')](function(_0x288aa8){logger['info']('GetTrigger',_0x599067);logger[_0xafeb('0xe')](_0xafeb('0x1f'),_0x599067,JSON[_0xafeb('0x20')](_0x288aa8));_0x141afe(_0x288aa8);})[_0xafeb('0x15')](function(_0x5ef8af){logger[_0xafeb('0x10')](_0xafeb('0x1f'),_0x5ef8af[_0xafeb('0x12')],_0x599067);_0x398c60(_0x423bc1['error'](0x1f4,_0x5ef8af[_0xafeb('0x12')]));});});};exports['ShowTrigger']=function(_0x4a08d7){var _0x1ae2f1=this;return new Promise(function(_0x47118a,_0x38eb58){return db[_0xafeb('0x16')]['find']({'raw':_0x4a08d7[_0xafeb('0x18')]?_0x4a08d7['options'][_0xafeb('0x19')]===undefined?!![]:![]:!![],'where':_0x4a08d7[_0xafeb('0x18')]?_0x4a08d7[_0xafeb('0x18')]['where']||null:null,'attributes':_0x4a08d7[_0xafeb('0x18')]?_0x4a08d7[_0xafeb('0x18')]['attributes']||null:null,'include':_0x4a08d7['options']?_0x4a08d7[_0xafeb('0x18')][_0xafeb('0x1c')]?_[_0xafeb('0x1d')](_0x4a08d7['options']['include'],function(_0x4b6d5a){return{'model':db[_0x4b6d5a['model']],'as':_0x4b6d5a['as'],'attributes':_0x4b6d5a[_0xafeb('0x1b')],'include':_0x4b6d5a[_0xafeb('0x1c')]?_['map'](_0x4b6d5a[_0xafeb('0x1c')],function(_0x154f79){return{'model':db[_0x154f79[_0xafeb('0x1e')]],'as':_0x154f79['as'],'attributes':_0x154f79[_0xafeb('0x1b')],'include':_0x154f79['include']?_[_0xafeb('0x1d')](_0x154f79[_0xafeb('0x1c')],function(_0x4403a4){return{'model':db[_0x4403a4[_0xafeb('0x1e')]],'as':_0x4403a4['as'],'attributes':_0x4403a4[_0xafeb('0x1b')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x3a57df){logger[_0xafeb('0xd')]('ShowTrigger',_0x4a08d7);logger['debug'](_0xafeb('0x21'),_0x4a08d7,JSON[_0xafeb('0x20')](_0x3a57df));_0x47118a(_0x3a57df);})[_0xafeb('0x15')](function(_0x41a6ee){logger[_0xafeb('0x10')](_0xafeb('0x21'),_0x41a6ee[_0xafeb('0x12')],_0x4a08d7);_0x38eb58(_0x1ae2f1[_0xafeb('0x10')](0x1f4,_0x41a6ee[_0xafeb('0x12')]));});});};