Built motion from commit fe909640.|2.6.8
[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 _0xeef7=['message','info','result','catch','GetTrigger','findAll','options','raw','where','attributes','limit','include','map','model','debug','stringify','ShowTrigger','Trigger','find','lodash','moment','ioredis','rpc','../../config/environment','jayson/promise','client','request','then','Trigger,\x20%s,\x20%s','request\x20sent','error'];(function(_0x150c65,_0x303f38){var _0x4ca489=function(_0x2c2e26){while(--_0x2c2e26){_0x150c65['push'](_0x150c65['shift']());}};_0x4ca489(++_0x303f38);}(_0xeef7,0x168));var _0x7eef=function(_0x2c8973,_0x41b1db){_0x2c8973=_0x2c8973-0x0;var _0x4c5244=_0xeef7[_0x2c8973];return _0x4c5244;};'use strict';var _=require(_0x7eef('0x0'));var util=require('util');var moment=require(_0x7eef('0x1'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x7eef('0x2'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x7eef('0x3'));var config=require(_0x7eef('0x4'));var jayson=require(_0x7eef('0x5'));var client=jayson[_0x7eef('0x6')]['http']({'port':0x232a});function respondWithRpcPromise(_0x20aa17,_0x38b2aa,_0x53c578){return new BPromise(function(_0x99cab7,_0x3d65de){return client[_0x7eef('0x7')](_0x20aa17,_0x53c578)[_0x7eef('0x8')](function(_0x49d325){logger['info'](_0x7eef('0x9'),_0x38b2aa,_0x7eef('0xa'));logger['debug']('Trigger,\x20%s,\x20%s,\x20%s',_0x38b2aa,_0x7eef('0xa'),JSON['stringify'](_0x49d325));if(_0x49d325[_0x7eef('0xb')]){if(_0x49d325[_0x7eef('0xb')]['code']===0x1f4){logger[_0x7eef('0xb')]('Trigger,\x20%s,\x20%s',_0x38b2aa,_0x49d325[_0x7eef('0xb')][_0x7eef('0xc')]);return _0x3d65de(_0x49d325[_0x7eef('0xb')][_0x7eef('0xc')]);}logger[_0x7eef('0xb')](_0x7eef('0x9'),_0x38b2aa,_0x49d325[_0x7eef('0xb')][_0x7eef('0xc')]);return _0x99cab7(_0x49d325['error'][_0x7eef('0xc')]);}else{logger[_0x7eef('0xd')]('Trigger,\x20%s,\x20%s',_0x38b2aa,'request\x20sent');_0x99cab7(_0x49d325[_0x7eef('0xe')]['message']);}})[_0x7eef('0xf')](function(_0x581cbe){logger[_0x7eef('0xb')](_0x7eef('0x9'),_0x38b2aa,_0x581cbe);_0x3d65de(_0x581cbe);});});}exports[_0x7eef('0x10')]=function(_0xa39a14){var _0x549adc=this;return new Promise(function(_0x12d285,_0x3d1ebc){return db['Trigger'][_0x7eef('0x11')]({'raw':_0xa39a14[_0x7eef('0x12')]?_0xa39a14[_0x7eef('0x12')][_0x7eef('0x13')]===undefined?!![]:![]:!![],'where':_0xa39a14[_0x7eef('0x12')]?_0xa39a14[_0x7eef('0x12')][_0x7eef('0x14')]||null:null,'attributes':_0xa39a14[_0x7eef('0x12')]?_0xa39a14['options'][_0x7eef('0x15')]||null:null,'limit':_0xa39a14[_0x7eef('0x12')]?_0xa39a14[_0x7eef('0x12')][_0x7eef('0x16')]||null:null,'include':_0xa39a14[_0x7eef('0x12')]?_0xa39a14[_0x7eef('0x12')][_0x7eef('0x17')]?_[_0x7eef('0x18')](_0xa39a14[_0x7eef('0x12')][_0x7eef('0x17')],function(_0x57670e){return{'model':db[_0x57670e[_0x7eef('0x19')]],'as':_0x57670e['as'],'attributes':_0x57670e[_0x7eef('0x15')],'include':_0x57670e[_0x7eef('0x17')]?_[_0x7eef('0x18')](_0x57670e[_0x7eef('0x17')],function(_0x25a278){return{'model':db[_0x25a278[_0x7eef('0x19')]],'as':_0x25a278['as'],'attributes':_0x25a278['attributes'],'include':_0x25a278[_0x7eef('0x17')]?_[_0x7eef('0x18')](_0x25a278[_0x7eef('0x17')],function(_0x517fb4){return{'model':db[_0x517fb4[_0x7eef('0x19')]],'as':_0x517fb4['as'],'attributes':_0x517fb4[_0x7eef('0x15')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x106f11){logger['info'](_0x7eef('0x10'),_0xa39a14);logger[_0x7eef('0x1a')](_0x7eef('0x10'),_0xa39a14,JSON[_0x7eef('0x1b')](_0x106f11));_0x12d285(_0x106f11);})[_0x7eef('0xf')](function(_0x251e76){logger[_0x7eef('0xb')]('GetTrigger',_0x251e76[_0x7eef('0xc')],_0xa39a14);_0x3d1ebc(_0x549adc[_0x7eef('0xb')](0x1f4,_0x251e76[_0x7eef('0xc')]));});});};exports[_0x7eef('0x1c')]=function(_0x2f34d4){var _0x3aafd4=this;return new Promise(function(_0x541ffe,_0xcfa3b5){return db[_0x7eef('0x1d')][_0x7eef('0x1e')]({'raw':_0x2f34d4[_0x7eef('0x12')]?_0x2f34d4['options']['raw']===undefined?!![]:![]:!![],'where':_0x2f34d4[_0x7eef('0x12')]?_0x2f34d4[_0x7eef('0x12')]['where']||null:null,'attributes':_0x2f34d4['options']?_0x2f34d4['options']['attributes']||null:null,'include':_0x2f34d4[_0x7eef('0x12')]?_0x2f34d4[_0x7eef('0x12')][_0x7eef('0x17')]?_[_0x7eef('0x18')](_0x2f34d4[_0x7eef('0x12')][_0x7eef('0x17')],function(_0x7590){return{'model':db[_0x7590[_0x7eef('0x19')]],'as':_0x7590['as'],'attributes':_0x7590[_0x7eef('0x15')],'include':_0x7590['include']?_[_0x7eef('0x18')](_0x7590[_0x7eef('0x17')],function(_0x783f88){return{'model':db[_0x783f88[_0x7eef('0x19')]],'as':_0x783f88['as'],'attributes':_0x783f88[_0x7eef('0x15')],'include':_0x783f88['include']?_[_0x7eef('0x18')](_0x783f88[_0x7eef('0x17')],function(_0x2dd084){return{'model':db[_0x2dd084[_0x7eef('0x19')]],'as':_0x2dd084['as'],'attributes':_0x2dd084['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x199b8b){logger[_0x7eef('0xd')](_0x7eef('0x1c'),_0x2f34d4);logger['debug'](_0x7eef('0x1c'),_0x2f34d4,JSON['stringify'](_0x199b8b));_0x541ffe(_0x199b8b);})[_0x7eef('0xf')](function(_0x2ec927){logger[_0x7eef('0xb')](_0x7eef('0x1c'),_0x2ec927[_0x7eef('0xc')],_0x2f34d4);_0xcfa3b5(_0x3aafd4[_0x7eef('0xb')](0x1f4,_0x2ec927[_0x7eef('0xc')]));});});};