8281bc69b0d262024d693171dad86b31093b9c7a
[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 _0xad2b=['message','catch','GetTrigger','Trigger','options','raw','attributes','limit','map','include','model','ShowTrigger','where','lodash','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','request','then','info','Trigger,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code'];(function(_0x30ba3e,_0x4e8994){var _0x43cfae=function(_0x1604f5){while(--_0x1604f5){_0x30ba3e['push'](_0x30ba3e['shift']());}};_0x43cfae(++_0x4e8994);}(_0xad2b,0x16d));var _0xbad2=function(_0x2cc842,_0x4f889f){_0x2cc842=_0x2cc842-0x0;var _0xa1cb6f=_0xad2b[_0x2cc842];return _0xa1cb6f;};'use strict';var _=require(_0xbad2('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0xbad2('0x1'));var rs=require(_0xbad2('0x2'));var fs=require('fs');var Redis=require(_0xbad2('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0xbad2('0x4'));var logger=require(_0xbad2('0x5'))(_0xbad2('0x6'));var config=require(_0xbad2('0x7'));var jayson=require('jayson/promise');var client=jayson[_0xbad2('0x8')][_0xbad2('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x4f91e9,_0x475115,_0x48d1e6){return new BPromise(function(_0x454270,_0x4aee02){return client[_0xbad2('0xa')](_0x4f91e9,_0x48d1e6)[_0xbad2('0xb')](function(_0x5ba9b3){logger[_0xbad2('0xc')](_0xbad2('0xd'),_0x475115,'request\x20sent');logger[_0xbad2('0xe')]('Trigger,\x20%s,\x20%s,\x20%s',_0x475115,_0xbad2('0xf'),JSON[_0xbad2('0x10')](_0x5ba9b3));if(_0x5ba9b3[_0xbad2('0x11')]){if(_0x5ba9b3['error'][_0xbad2('0x12')]===0x1f4){logger['error'](_0xbad2('0xd'),_0x475115,_0x5ba9b3[_0xbad2('0x11')][_0xbad2('0x13')]);return _0x4aee02(_0x5ba9b3[_0xbad2('0x11')][_0xbad2('0x13')]);}logger['error'](_0xbad2('0xd'),_0x475115,_0x5ba9b3['error'][_0xbad2('0x13')]);return _0x454270(_0x5ba9b3[_0xbad2('0x11')][_0xbad2('0x13')]);}else{logger['info'](_0xbad2('0xd'),_0x475115,'request\x20sent');_0x454270(_0x5ba9b3['result'][_0xbad2('0x13')]);}})[_0xbad2('0x14')](function(_0x3b2bc5){logger[_0xbad2('0x11')](_0xbad2('0xd'),_0x475115,_0x3b2bc5);_0x4aee02(_0x3b2bc5);});});}exports[_0xbad2('0x15')]=function(_0x16efd3){var _0x2e4159=this;return new Promise(function(_0x221538,_0x1cda45){return db[_0xbad2('0x16')]['findAll']({'raw':_0x16efd3[_0xbad2('0x17')]?_0x16efd3[_0xbad2('0x17')][_0xbad2('0x18')]===undefined?!![]:![]:!![],'where':_0x16efd3[_0xbad2('0x17')]?_0x16efd3[_0xbad2('0x17')]['where']||null:null,'attributes':_0x16efd3[_0xbad2('0x17')]?_0x16efd3[_0xbad2('0x17')][_0xbad2('0x19')]||null:null,'limit':_0x16efd3[_0xbad2('0x17')]?_0x16efd3[_0xbad2('0x17')][_0xbad2('0x1a')]||null:null,'include':_0x16efd3[_0xbad2('0x17')]?_0x16efd3[_0xbad2('0x17')]['include']?_[_0xbad2('0x1b')](_0x16efd3[_0xbad2('0x17')][_0xbad2('0x1c')],function(_0x327d85){return{'model':db[_0x327d85[_0xbad2('0x1d')]],'as':_0x327d85['as'],'attributes':_0x327d85[_0xbad2('0x19')],'include':_0x327d85['include']?_[_0xbad2('0x1b')](_0x327d85[_0xbad2('0x1c')],function(_0x35dfd1){return{'model':db[_0x35dfd1[_0xbad2('0x1d')]],'as':_0x35dfd1['as'],'attributes':_0x35dfd1[_0xbad2('0x19')],'include':_0x35dfd1['include']?_[_0xbad2('0x1b')](_0x35dfd1[_0xbad2('0x1c')],function(_0x3033fd){return{'model':db[_0x3033fd[_0xbad2('0x1d')]],'as':_0x3033fd['as'],'attributes':_0x3033fd['attributes']};}):[]};}):[]};}):[]:[]})[_0xbad2('0xb')](function(_0xea90fa){logger['info'](_0xbad2('0x15'),_0x16efd3);logger['debug'](_0xbad2('0x15'),_0x16efd3,JSON[_0xbad2('0x10')](_0xea90fa));_0x221538(_0xea90fa);})[_0xbad2('0x14')](function(_0x3b2a1d){logger['error'](_0xbad2('0x15'),_0x3b2a1d[_0xbad2('0x13')],_0x16efd3);_0x1cda45(_0x2e4159[_0xbad2('0x11')](0x1f4,_0x3b2a1d['message']));});});};exports[_0xbad2('0x1e')]=function(_0x269d2d){var _0x437c9a=this;return new Promise(function(_0x50e6f9,_0x4b8aa4){return db[_0xbad2('0x16')]['find']({'raw':_0x269d2d[_0xbad2('0x17')]?_0x269d2d['options'][_0xbad2('0x18')]===undefined?!![]:![]:!![],'where':_0x269d2d[_0xbad2('0x17')]?_0x269d2d[_0xbad2('0x17')][_0xbad2('0x1f')]||null:null,'attributes':_0x269d2d[_0xbad2('0x17')]?_0x269d2d[_0xbad2('0x17')][_0xbad2('0x19')]||null:null,'include':_0x269d2d[_0xbad2('0x17')]?_0x269d2d[_0xbad2('0x17')][_0xbad2('0x1c')]?_[_0xbad2('0x1b')](_0x269d2d[_0xbad2('0x17')][_0xbad2('0x1c')],function(_0xa6be76){return{'model':db[_0xa6be76['model']],'as':_0xa6be76['as'],'attributes':_0xa6be76[_0xbad2('0x19')],'include':_0xa6be76[_0xbad2('0x1c')]?_['map'](_0xa6be76[_0xbad2('0x1c')],function(_0x43666f){return{'model':db[_0x43666f[_0xbad2('0x1d')]],'as':_0x43666f['as'],'attributes':_0x43666f[_0xbad2('0x19')],'include':_0x43666f[_0xbad2('0x1c')]?_[_0xbad2('0x1b')](_0x43666f[_0xbad2('0x1c')],function(_0x23a105){return{'model':db[_0x23a105[_0xbad2('0x1d')]],'as':_0x23a105['as'],'attributes':_0x23a105[_0xbad2('0x19')]};}):[]};}):[]};}):[]:[]})[_0xbad2('0xb')](function(_0x9d920a){logger['info'](_0xbad2('0x1e'),_0x269d2d);logger[_0xbad2('0xe')]('ShowTrigger',_0x269d2d,JSON[_0xbad2('0x10')](_0x9d920a));_0x50e6f9(_0x9d920a);})[_0xbad2('0x14')](function(_0x2c05de){logger[_0xbad2('0x11')](_0xbad2('0x1e'),_0x2c05de['message'],_0x269d2d);_0x4b8aa4(_0x437c9a[_0xbad2('0x11')](0x1f4,_0x2c05de[_0xbad2('0x13')]));});});};