84dec79972d7cce654915355dc387f930a279b4d
[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 _0x3fd5=['attributes','limit','map','include','model','debug','ShowTrigger','find','where','lodash','util','moment','../../config/utils','../../config/logger','../../config/environment','client','http','request','then','info','Trigger,\x20%s,\x20%s','request\x20sent','Trigger,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','GetTrigger','Trigger','findAll','options','raw'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0x3fd5,0x1a9));var _0x53fd=function(_0x30a948,_0x559675){_0x30a948=_0x30a948-0x0;var _0x4dfef3=_0x3fd5[_0x30a948];return _0x4dfef3;};'use strict';var _=require(_0x53fd('0x0'));var util=require(_0x53fd('0x1'));var moment=require(_0x53fd('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x53fd('0x3'));var logger=require(_0x53fd('0x4'))('rpc');var config=require(_0x53fd('0x5'));var jayson=require('jayson/promise');var client=jayson[_0x53fd('0x6')][_0x53fd('0x7')]({'port':0x232a});function respondWithRpcPromise(_0x21ee38,_0x5a6c1e,_0x56b366){return new BPromise(function(_0x28f97a,_0x53b5e0){return client[_0x53fd('0x8')](_0x21ee38,_0x56b366)[_0x53fd('0x9')](function(_0x36d5bc){logger[_0x53fd('0xa')](_0x53fd('0xb'),_0x5a6c1e,_0x53fd('0xc'));logger['debug'](_0x53fd('0xd'),_0x5a6c1e,_0x53fd('0xc'),JSON[_0x53fd('0xe')](_0x36d5bc));if(_0x36d5bc[_0x53fd('0xf')]){if(_0x36d5bc[_0x53fd('0xf')]['code']===0x1f4){logger[_0x53fd('0xf')](_0x53fd('0xb'),_0x5a6c1e,_0x36d5bc[_0x53fd('0xf')][_0x53fd('0x10')]);return _0x53b5e0(_0x36d5bc[_0x53fd('0xf')][_0x53fd('0x10')]);}logger['error'](_0x53fd('0xb'),_0x5a6c1e,_0x36d5bc[_0x53fd('0xf')][_0x53fd('0x10')]);return _0x28f97a(_0x36d5bc[_0x53fd('0xf')][_0x53fd('0x10')]);}else{logger['info'](_0x53fd('0xb'),_0x5a6c1e,_0x53fd('0xc'));_0x28f97a(_0x36d5bc['result'][_0x53fd('0x10')]);}})[_0x53fd('0x11')](function(_0x121fa8){logger['error'](_0x53fd('0xb'),_0x5a6c1e,_0x121fa8);_0x53b5e0(_0x121fa8);});});}exports[_0x53fd('0x12')]=function(_0x10e692){var _0x1b8834=this;return new Promise(function(_0x44fe24,_0x2211d2){return db[_0x53fd('0x13')][_0x53fd('0x14')]({'raw':_0x10e692['options']?_0x10e692[_0x53fd('0x15')][_0x53fd('0x16')]===undefined?!![]:![]:!![],'where':_0x10e692['options']?_0x10e692['options']['where']||null:null,'attributes':_0x10e692[_0x53fd('0x15')]?_0x10e692['options'][_0x53fd('0x17')]||null:null,'limit':_0x10e692[_0x53fd('0x15')]?_0x10e692['options'][_0x53fd('0x18')]||null:null,'include':_0x10e692[_0x53fd('0x15')]?_0x10e692['options']['include']?_[_0x53fd('0x19')](_0x10e692['options'][_0x53fd('0x1a')],function(_0x5a391f){return{'model':db[_0x5a391f[_0x53fd('0x1b')]],'as':_0x5a391f['as'],'attributes':_0x5a391f[_0x53fd('0x17')],'include':_0x5a391f['include']?_[_0x53fd('0x19')](_0x5a391f['include'],function(_0x5cf958){return{'model':db[_0x5cf958[_0x53fd('0x1b')]],'as':_0x5cf958['as'],'attributes':_0x5cf958[_0x53fd('0x17')],'include':_0x5cf958['include']?_['map'](_0x5cf958[_0x53fd('0x1a')],function(_0x5b1558){return{'model':db[_0x5b1558[_0x53fd('0x1b')]],'as':_0x5b1558['as'],'attributes':_0x5b1558['attributes']};}):[]};}):[]};}):[]:[]})[_0x53fd('0x9')](function(_0x3ec5f9){logger[_0x53fd('0xa')](_0x53fd('0x12'),_0x10e692);logger[_0x53fd('0x1c')](_0x53fd('0x12'),_0x10e692,JSON['stringify'](_0x3ec5f9));_0x44fe24(_0x3ec5f9);})[_0x53fd('0x11')](function(_0x5cc826){logger[_0x53fd('0xf')](_0x53fd('0x12'),_0x5cc826['message'],_0x10e692);_0x2211d2(_0x1b8834[_0x53fd('0xf')](0x1f4,_0x5cc826['message']));});});};exports[_0x53fd('0x1d')]=function(_0x435066){var _0x6599c3=this;return new Promise(function(_0x286e15,_0x921a8b){return db['Trigger'][_0x53fd('0x1e')]({'raw':_0x435066[_0x53fd('0x15')]?_0x435066[_0x53fd('0x15')][_0x53fd('0x16')]===undefined?!![]:![]:!![],'where':_0x435066[_0x53fd('0x15')]?_0x435066['options'][_0x53fd('0x1f')]||null:null,'attributes':_0x435066['options']?_0x435066['options']['attributes']||null:null,'include':_0x435066[_0x53fd('0x15')]?_0x435066[_0x53fd('0x15')][_0x53fd('0x1a')]?_[_0x53fd('0x19')](_0x435066['options']['include'],function(_0x5bf104){return{'model':db[_0x5bf104['model']],'as':_0x5bf104['as'],'attributes':_0x5bf104[_0x53fd('0x17')],'include':_0x5bf104['include']?_[_0x53fd('0x19')](_0x5bf104['include'],function(_0x5587bd){return{'model':db[_0x5587bd[_0x53fd('0x1b')]],'as':_0x5587bd['as'],'attributes':_0x5587bd[_0x53fd('0x17')],'include':_0x5587bd['include']?_[_0x53fd('0x19')](_0x5587bd[_0x53fd('0x1a')],function(_0x190972){return{'model':db[_0x190972[_0x53fd('0x1b')]],'as':_0x190972['as'],'attributes':_0x190972[_0x53fd('0x17')]};}):[]};}):[]};}):[]:[]})[_0x53fd('0x9')](function(_0x122eec){logger['info'](_0x53fd('0x1d'),_0x435066);logger['debug'](_0x53fd('0x1d'),_0x435066,JSON[_0x53fd('0xe')](_0x122eec));_0x286e15(_0x122eec);})[_0x53fd('0x11')](function(_0x1554a3){logger['error'](_0x53fd('0x1d'),_0x1554a3[_0x53fd('0x10')],_0x435066);_0x921a8b(_0x6599c3[_0x53fd('0xf')](0x1f4,_0x1554a3[_0x53fd('0x10')]));});});};