Built motion from commit b9b02fed.|2.6.5
[motion2.git] / server / api / trunk / trunk.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 _0xd08a=['../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','info','Trunk,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','GetTrunk','Trunk','findAll','options','where','limit','include','map','model','attributes','then','ShowTrunk','raw','lodash','util','moment','bluebird','ioredis'];(function(_0x5783f4,_0x4a9e0a){var _0x28e380=function(_0x1ffc49){while(--_0x1ffc49){_0x5783f4['push'](_0x5783f4['shift']());}};_0x28e380(++_0x4a9e0a);}(_0xd08a,0x83));var _0xad08=function(_0x5214e3,_0x61113e){_0x5214e3=_0x5214e3-0x0;var _0x26c611=_0xd08a[_0x5214e3];return _0x26c611;};'use strict';var _=require(_0xad08('0x0'));var util=require(_0xad08('0x1'));var moment=require(_0xad08('0x2'));var BPromise=require(_0xad08('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xad08('0x4'));var db=require(_0xad08('0x5'))['db'];var utils=require(_0xad08('0x6'));var logger=require(_0xad08('0x7'))(_0xad08('0x8'));var config=require('../../config/environment');var jayson=require(_0xad08('0x9'));var client=jayson[_0xad08('0xa')]['http']({'port':0x232a});function respondWithRpcPromise(_0xe08a50,_0x43a0ba,_0x2a358a){return new BPromise(function(_0x258773,_0x22483b){return client['request'](_0xe08a50,_0x2a358a)['then'](function(_0x1bd963){logger[_0xad08('0xb')](_0xad08('0xc'),_0x43a0ba,_0xad08('0xd'));logger[_0xad08('0xe')]('Trunk,\x20%s,\x20%s,\x20%s',_0x43a0ba,_0xad08('0xd'),JSON[_0xad08('0xf')](_0x1bd963));if(_0x1bd963['error']){if(_0x1bd963[_0xad08('0x10')][_0xad08('0x11')]===0x1f4){logger[_0xad08('0x10')](_0xad08('0xc'),_0x43a0ba,_0x1bd963[_0xad08('0x10')][_0xad08('0x12')]);return _0x22483b(_0x1bd963[_0xad08('0x10')]['message']);}logger[_0xad08('0x10')](_0xad08('0xc'),_0x43a0ba,_0x1bd963[_0xad08('0x10')][_0xad08('0x12')]);return _0x258773(_0x1bd963[_0xad08('0x10')]['message']);}else{logger[_0xad08('0xb')](_0xad08('0xc'),_0x43a0ba,_0xad08('0xd'));_0x258773(_0x1bd963[_0xad08('0x13')]['message']);}})[_0xad08('0x14')](function(_0x29a2ff){logger[_0xad08('0x10')](_0xad08('0xc'),_0x43a0ba,_0x29a2ff);_0x22483b(_0x29a2ff);});});}exports[_0xad08('0x15')]=function(_0x12469c){var _0x45f4b9=this;return new Promise(function(_0x3b63b2,_0x10fe28){return db[_0xad08('0x16')][_0xad08('0x17')]({'raw':_0x12469c[_0xad08('0x18')]?_0x12469c[_0xad08('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x12469c['options']?_0x12469c[_0xad08('0x18')][_0xad08('0x19')]||null:null,'attributes':_0x12469c[_0xad08('0x18')]?_0x12469c['options']['attributes']||null:null,'limit':_0x12469c[_0xad08('0x18')]?_0x12469c[_0xad08('0x18')][_0xad08('0x1a')]||null:null,'include':_0x12469c[_0xad08('0x18')]?_0x12469c[_0xad08('0x18')][_0xad08('0x1b')]?_[_0xad08('0x1c')](_0x12469c[_0xad08('0x18')][_0xad08('0x1b')],function(_0x84831e){return{'model':db[_0x84831e[_0xad08('0x1d')]],'as':_0x84831e['as'],'attributes':_0x84831e[_0xad08('0x1e')],'include':_0x84831e['include']?_['map'](_0x84831e[_0xad08('0x1b')],function(_0x5ee782){return{'model':db[_0x5ee782[_0xad08('0x1d')]],'as':_0x5ee782['as'],'attributes':_0x5ee782[_0xad08('0x1e')],'include':_0x5ee782[_0xad08('0x1b')]?_[_0xad08('0x1c')](_0x5ee782[_0xad08('0x1b')],function(_0xc68df8){return{'model':db[_0xc68df8[_0xad08('0x1d')]],'as':_0xc68df8['as'],'attributes':_0xc68df8['attributes']};}):[]};}):[]};}):[]:[]})[_0xad08('0x1f')](function(_0x5588c9){logger['info'](_0xad08('0x15'),_0x12469c);logger[_0xad08('0xe')](_0xad08('0x15'),_0x12469c,JSON['stringify'](_0x5588c9));_0x3b63b2(_0x5588c9);})[_0xad08('0x14')](function(_0x5a7443){logger[_0xad08('0x10')](_0xad08('0x15'),_0x5a7443[_0xad08('0x12')],_0x12469c);_0x10fe28(_0x45f4b9[_0xad08('0x10')](0x1f4,_0x5a7443['message']));});});};exports[_0xad08('0x20')]=function(_0x597406){var _0xe21b01=this;return new Promise(function(_0x39667d,_0x493355){return db[_0xad08('0x16')]['find']({'raw':_0x597406[_0xad08('0x18')]?_0x597406[_0xad08('0x18')][_0xad08('0x21')]===undefined?!![]:![]:!![],'where':_0x597406[_0xad08('0x18')]?_0x597406[_0xad08('0x18')][_0xad08('0x19')]||null:null,'attributes':_0x597406[_0xad08('0x18')]?_0x597406[_0xad08('0x18')][_0xad08('0x1e')]||null:null,'include':_0x597406[_0xad08('0x18')]?_0x597406[_0xad08('0x18')][_0xad08('0x1b')]?_[_0xad08('0x1c')](_0x597406[_0xad08('0x18')][_0xad08('0x1b')],function(_0x4e0a40){return{'model':db[_0x4e0a40['model']],'as':_0x4e0a40['as'],'attributes':_0x4e0a40[_0xad08('0x1e')],'include':_0x4e0a40[_0xad08('0x1b')]?_['map'](_0x4e0a40['include'],function(_0x61b1ac){return{'model':db[_0x61b1ac[_0xad08('0x1d')]],'as':_0x61b1ac['as'],'attributes':_0x61b1ac[_0xad08('0x1e')],'include':_0x61b1ac[_0xad08('0x1b')]?_['map'](_0x61b1ac[_0xad08('0x1b')],function(_0x4f9fd1){return{'model':db[_0x4f9fd1['model']],'as':_0x4f9fd1['as'],'attributes':_0x4f9fd1[_0xad08('0x1e')]};}):[]};}):[]};}):[]:[]})[_0xad08('0x1f')](function(_0x59e6ef){logger[_0xad08('0xb')](_0xad08('0x20'),_0x597406);logger[_0xad08('0xe')]('ShowTrunk',_0x597406,JSON['stringify'](_0x59e6ef));_0x39667d(_0x59e6ef);})[_0xad08('0x14')](function(_0x3f94a5){logger[_0xad08('0x10')](_0xad08('0x20'),_0x3f94a5[_0xad08('0x12')],_0x597406);_0x493355(_0xe21b01[_0xad08('0x10')](0x1f4,_0x3f94a5[_0xad08('0x12')]));});});};