f1ed954cbd2541e29fc6bcd02505bb979ba1b057
[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 _0x67c4=['Trigger','findAll','options','raw','where','attributes','limit','include','map','model','find','ShowTrigger','catch','lodash','util','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','client','http','then','info','Trigger,\x20%s,\x20%s','request\x20sent','debug','Trigger,\x20%s,\x20%s,\x20%s','stringify','error','message','result','GetTrigger'];(function(_0x32ca03,_0x14c7ee){var _0x17967f=function(_0x2175e5){while(--_0x2175e5){_0x32ca03['push'](_0x32ca03['shift']());}};_0x17967f(++_0x14c7ee);}(_0x67c4,0x178));var _0x467c=function(_0x4a53d,_0x58a95e){_0x4a53d=_0x4a53d-0x0;var _0x27410e=_0x67c4[_0x4a53d];return _0x27410e;};'use strict';var _=require(_0x467c('0x0'));var util=require(_0x467c('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x467c('0x2'));var fs=require('fs');var Redis=require(_0x467c('0x3'));var db=require(_0x467c('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x467c('0x5'))(_0x467c('0x6'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x467c('0x7')][_0x467c('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x37da4c,_0x214fb4,_0x139f48){return new BPromise(function(_0x33a0e6,_0x3bf46c){return client['request'](_0x37da4c,_0x139f48)[_0x467c('0x9')](function(_0x506984){logger[_0x467c('0xa')](_0x467c('0xb'),_0x214fb4,_0x467c('0xc'));logger[_0x467c('0xd')](_0x467c('0xe'),_0x214fb4,'request\x20sent',JSON[_0x467c('0xf')](_0x506984));if(_0x506984['error']){if(_0x506984[_0x467c('0x10')]['code']===0x1f4){logger[_0x467c('0x10')](_0x467c('0xb'),_0x214fb4,_0x506984['error'][_0x467c('0x11')]);return _0x3bf46c(_0x506984['error']['message']);}logger[_0x467c('0x10')](_0x467c('0xb'),_0x214fb4,_0x506984[_0x467c('0x10')][_0x467c('0x11')]);return _0x33a0e6(_0x506984[_0x467c('0x10')]['message']);}else{logger[_0x467c('0xa')](_0x467c('0xb'),_0x214fb4,_0x467c('0xc'));_0x33a0e6(_0x506984[_0x467c('0x12')][_0x467c('0x11')]);}})['catch'](function(_0x33a86d){logger[_0x467c('0x10')]('Trigger,\x20%s,\x20%s',_0x214fb4,_0x33a86d);_0x3bf46c(_0x33a86d);});});}exports[_0x467c('0x13')]=function(_0x798709){var _0x4ecb0d=this;return new Promise(function(_0x54593a,_0x4aad82){return db[_0x467c('0x14')][_0x467c('0x15')]({'raw':_0x798709[_0x467c('0x16')]?_0x798709[_0x467c('0x16')][_0x467c('0x17')]===undefined?!![]:![]:!![],'where':_0x798709[_0x467c('0x16')]?_0x798709['options'][_0x467c('0x18')]||null:null,'attributes':_0x798709[_0x467c('0x16')]?_0x798709['options'][_0x467c('0x19')]||null:null,'limit':_0x798709[_0x467c('0x16')]?_0x798709[_0x467c('0x16')][_0x467c('0x1a')]||null:null,'include':_0x798709['options']?_0x798709[_0x467c('0x16')][_0x467c('0x1b')]?_[_0x467c('0x1c')](_0x798709['options'][_0x467c('0x1b')],function(_0x27e57e){return{'model':db[_0x27e57e['model']],'as':_0x27e57e['as'],'attributes':_0x27e57e[_0x467c('0x19')],'include':_0x27e57e[_0x467c('0x1b')]?_[_0x467c('0x1c')](_0x27e57e[_0x467c('0x1b')],function(_0x3166fd){return{'model':db[_0x3166fd[_0x467c('0x1d')]],'as':_0x3166fd['as'],'attributes':_0x3166fd[_0x467c('0x19')],'include':_0x3166fd[_0x467c('0x1b')]?_[_0x467c('0x1c')](_0x3166fd[_0x467c('0x1b')],function(_0x4d6352){return{'model':db[_0x4d6352[_0x467c('0x1d')]],'as':_0x4d6352['as'],'attributes':_0x4d6352[_0x467c('0x19')]};}):[]};}):[]};}):[]:[]})[_0x467c('0x9')](function(_0x5d661f){logger['info']('GetTrigger',_0x798709);logger[_0x467c('0xd')](_0x467c('0x13'),_0x798709,JSON['stringify'](_0x5d661f));_0x54593a(_0x5d661f);})['catch'](function(_0x51a6bc){logger[_0x467c('0x10')]('GetTrigger',_0x51a6bc[_0x467c('0x11')],_0x798709);_0x4aad82(_0x4ecb0d['error'](0x1f4,_0x51a6bc[_0x467c('0x11')]));});});};exports['ShowTrigger']=function(_0x95b824){var _0x563acc=this;return new Promise(function(_0x4bc687,_0x2da9c1){return db[_0x467c('0x14')][_0x467c('0x1e')]({'raw':_0x95b824[_0x467c('0x16')]?_0x95b824[_0x467c('0x16')][_0x467c('0x17')]===undefined?!![]:![]:!![],'where':_0x95b824[_0x467c('0x16')]?_0x95b824[_0x467c('0x16')]['where']||null:null,'attributes':_0x95b824[_0x467c('0x16')]?_0x95b824[_0x467c('0x16')]['attributes']||null:null,'include':_0x95b824['options']?_0x95b824[_0x467c('0x16')]['include']?_['map'](_0x95b824['options'][_0x467c('0x1b')],function(_0x117493){return{'model':db[_0x117493[_0x467c('0x1d')]],'as':_0x117493['as'],'attributes':_0x117493[_0x467c('0x19')],'include':_0x117493['include']?_[_0x467c('0x1c')](_0x117493[_0x467c('0x1b')],function(_0x1176c4){return{'model':db[_0x1176c4['model']],'as':_0x1176c4['as'],'attributes':_0x1176c4['attributes'],'include':_0x1176c4['include']?_[_0x467c('0x1c')](_0x1176c4[_0x467c('0x1b')],function(_0x3bf841){return{'model':db[_0x3bf841[_0x467c('0x1d')]],'as':_0x3bf841['as'],'attributes':_0x3bf841[_0x467c('0x19')]};}):[]};}):[]};}):[]:[]})[_0x467c('0x9')](function(_0x233191){logger[_0x467c('0xa')](_0x467c('0x1f'),_0x95b824);logger['debug'](_0x467c('0x1f'),_0x95b824,JSON[_0x467c('0xf')](_0x233191));_0x4bc687(_0x233191);})[_0x467c('0x20')](function(_0x2c053c){logger[_0x467c('0x10')](_0x467c('0x1f'),_0x2c053c[_0x467c('0x11')],_0x95b824);_0x2da9c1(_0x563acc[_0x467c('0x10')](0x1f4,_0x2c053c['message']));});});};