Built motion from commit e0fa946e.|2.6.5
[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 _0x9af3=['info','lodash','util','moment','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','then','Trigger,\x20%s,\x20%s','request\x20sent','debug','error','code','message','result','GetTrigger','Trigger','findAll','options','attributes','limit','map','model','include','stringify','catch','ShowTrigger','raw'];(function(_0x8070c8,_0x6279a8){var _0x53d39b=function(_0x3758c2){while(--_0x3758c2){_0x8070c8['push'](_0x8070c8['shift']());}};_0x53d39b(++_0x6279a8);}(_0x9af3,0xf6));var _0x39af=function(_0x37d882,_0x298915){_0x37d882=_0x37d882-0x0;var _0x35b856=_0x9af3[_0x37d882];return _0x35b856;};'use strict';var _=require(_0x39af('0x0'));var util=require(_0x39af('0x1'));var moment=require(_0x39af('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x39af('0x3'));var db=require(_0x39af('0x4'))['db'];var utils=require(_0x39af('0x5'));var logger=require(_0x39af('0x6'))(_0x39af('0x7'));var config=require(_0x39af('0x8'));var jayson=require(_0x39af('0x9'));var client=jayson[_0x39af('0xa')][_0x39af('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x2971e2,_0x224b7e,_0x416b50){return new BPromise(function(_0x4d65f7,_0x1e184c){return client[_0x39af('0xc')](_0x2971e2,_0x416b50)[_0x39af('0xd')](function(_0x207905){logger['info'](_0x39af('0xe'),_0x224b7e,_0x39af('0xf'));logger[_0x39af('0x10')]('Trigger,\x20%s,\x20%s,\x20%s',_0x224b7e,_0x39af('0xf'),JSON['stringify'](_0x207905));if(_0x207905[_0x39af('0x11')]){if(_0x207905['error'][_0x39af('0x12')]===0x1f4){logger[_0x39af('0x11')]('Trigger,\x20%s,\x20%s',_0x224b7e,_0x207905['error'][_0x39af('0x13')]);return _0x1e184c(_0x207905[_0x39af('0x11')][_0x39af('0x13')]);}logger[_0x39af('0x11')]('Trigger,\x20%s,\x20%s',_0x224b7e,_0x207905['error'][_0x39af('0x13')]);return _0x4d65f7(_0x207905[_0x39af('0x11')]['message']);}else{logger['info'](_0x39af('0xe'),_0x224b7e,'request\x20sent');_0x4d65f7(_0x207905[_0x39af('0x14')][_0x39af('0x13')]);}})['catch'](function(_0x36808c){logger['error'](_0x39af('0xe'),_0x224b7e,_0x36808c);_0x1e184c(_0x36808c);});});}exports[_0x39af('0x15')]=function(_0x317877){var _0x155738=this;return new Promise(function(_0x419ad1,_0x20cc5b){return db[_0x39af('0x16')][_0x39af('0x17')]({'raw':_0x317877['options']?_0x317877['options']['raw']===undefined?!![]:![]:!![],'where':_0x317877[_0x39af('0x18')]?_0x317877[_0x39af('0x18')]['where']||null:null,'attributes':_0x317877['options']?_0x317877[_0x39af('0x18')][_0x39af('0x19')]||null:null,'limit':_0x317877[_0x39af('0x18')]?_0x317877[_0x39af('0x18')][_0x39af('0x1a')]||null:null,'include':_0x317877['options']?_0x317877['options']['include']?_[_0x39af('0x1b')](_0x317877['options']['include'],function(_0x1c16b4){return{'model':db[_0x1c16b4[_0x39af('0x1c')]],'as':_0x1c16b4['as'],'attributes':_0x1c16b4[_0x39af('0x19')],'include':_0x1c16b4[_0x39af('0x1d')]?_['map'](_0x1c16b4['include'],function(_0x3f46e3){return{'model':db[_0x3f46e3[_0x39af('0x1c')]],'as':_0x3f46e3['as'],'attributes':_0x3f46e3[_0x39af('0x19')],'include':_0x3f46e3[_0x39af('0x1d')]?_[_0x39af('0x1b')](_0x3f46e3[_0x39af('0x1d')],function(_0x589b32){return{'model':db[_0x589b32[_0x39af('0x1c')]],'as':_0x589b32['as'],'attributes':_0x589b32[_0x39af('0x19')]};}):[]};}):[]};}):[]:[]})[_0x39af('0xd')](function(_0x107d22){logger['info'](_0x39af('0x15'),_0x317877);logger[_0x39af('0x10')](_0x39af('0x15'),_0x317877,JSON[_0x39af('0x1e')](_0x107d22));_0x419ad1(_0x107d22);})[_0x39af('0x1f')](function(_0x1280d3){logger['error'](_0x39af('0x15'),_0x1280d3[_0x39af('0x13')],_0x317877);_0x20cc5b(_0x155738[_0x39af('0x11')](0x1f4,_0x1280d3['message']));});});};exports[_0x39af('0x20')]=function(_0x481295){var _0x18ba9c=this;return new Promise(function(_0x2b8dbb,_0x5207b3){return db['Trigger']['find']({'raw':_0x481295[_0x39af('0x18')]?_0x481295[_0x39af('0x18')][_0x39af('0x21')]===undefined?!![]:![]:!![],'where':_0x481295['options']?_0x481295['options']['where']||null:null,'attributes':_0x481295[_0x39af('0x18')]?_0x481295['options'][_0x39af('0x19')]||null:null,'include':_0x481295[_0x39af('0x18')]?_0x481295[_0x39af('0x18')][_0x39af('0x1d')]?_[_0x39af('0x1b')](_0x481295[_0x39af('0x18')]['include'],function(_0x10ace9){return{'model':db[_0x10ace9['model']],'as':_0x10ace9['as'],'attributes':_0x10ace9[_0x39af('0x19')],'include':_0x10ace9[_0x39af('0x1d')]?_[_0x39af('0x1b')](_0x10ace9[_0x39af('0x1d')],function(_0x1e6eed){return{'model':db[_0x1e6eed[_0x39af('0x1c')]],'as':_0x1e6eed['as'],'attributes':_0x1e6eed[_0x39af('0x19')],'include':_0x1e6eed[_0x39af('0x1d')]?_[_0x39af('0x1b')](_0x1e6eed['include'],function(_0xcfb9cc){return{'model':db[_0xcfb9cc[_0x39af('0x1c')]],'as':_0xcfb9cc['as'],'attributes':_0xcfb9cc[_0x39af('0x19')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x157656){logger[_0x39af('0x22')](_0x39af('0x20'),_0x481295);logger[_0x39af('0x10')](_0x39af('0x20'),_0x481295,JSON[_0x39af('0x1e')](_0x157656));_0x2b8dbb(_0x157656);})[_0x39af('0x1f')](function(_0xd612aa){logger[_0x39af('0x11')]('ShowTrigger',_0xd612aa[_0x39af('0x13')],_0x481295);_0x5207b3(_0x18ba9c['error'](0x1f4,_0xd612aa['message']));});});};