Built motion from commit 10af8726.|2.6.34
[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 _0x217f=['debug','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','GetTrunk','Trunk','findAll','options','where','attributes','limit','include','map','model','ShowTrunk','find','raw','util','moment','randomstring','../../mysqldb','../../config/utils','../../config/environment','jayson/promise','client','request','then','info','Trunk,\x20%s,\x20%s','request\x20sent'];(function(_0x40f073,_0x3c3efc){var _0x298bdc=function(_0x352c0c){while(--_0x352c0c){_0x40f073['push'](_0x40f073['shift']());}};_0x298bdc(++_0x3c3efc);}(_0x217f,0xb3));var _0xf217=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x217f[_0x20a584];return _0x4b41a8;};'use strict';var _=require('lodash');var util=require(_0xf217('0x0'));var moment=require(_0xf217('0x1'));var BPromise=require('bluebird');var rs=require(_0xf217('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xf217('0x3'))['db'];var utils=require(_0xf217('0x4'));var logger=require('../../config/logger')('rpc');var config=require(_0xf217('0x5'));var jayson=require(_0xf217('0x6'));var client=jayson[_0xf217('0x7')]['http']({'port':0x232a});function respondWithRpcPromise(_0xf37d90,_0x5dd44f,_0x3e1685){return new BPromise(function(_0x101f89,_0x5e3c43){return client[_0xf217('0x8')](_0xf37d90,_0x3e1685)[_0xf217('0x9')](function(_0xb61aec){logger[_0xf217('0xa')](_0xf217('0xb'),_0x5dd44f,_0xf217('0xc'));logger[_0xf217('0xd')](_0xf217('0xe'),_0x5dd44f,_0xf217('0xc'),JSON[_0xf217('0xf')](_0xb61aec));if(_0xb61aec[_0xf217('0x10')]){if(_0xb61aec[_0xf217('0x10')]['code']===0x1f4){logger[_0xf217('0x10')](_0xf217('0xb'),_0x5dd44f,_0xb61aec[_0xf217('0x10')][_0xf217('0x11')]);return _0x5e3c43(_0xb61aec[_0xf217('0x10')][_0xf217('0x11')]);}logger[_0xf217('0x10')]('Trunk,\x20%s,\x20%s',_0x5dd44f,_0xb61aec[_0xf217('0x10')][_0xf217('0x11')]);return _0x101f89(_0xb61aec['error'][_0xf217('0x11')]);}else{logger[_0xf217('0xa')]('Trunk,\x20%s,\x20%s',_0x5dd44f,_0xf217('0xc'));_0x101f89(_0xb61aec['result']['message']);}})[_0xf217('0x12')](function(_0x49a697){logger[_0xf217('0x10')](_0xf217('0xb'),_0x5dd44f,_0x49a697);_0x5e3c43(_0x49a697);});});}exports[_0xf217('0x13')]=function(_0x4f59e7){var _0x385815=this;return new Promise(function(_0x2a3456,_0x38ca09){return db[_0xf217('0x14')][_0xf217('0x15')]({'raw':_0x4f59e7[_0xf217('0x16')]?_0x4f59e7[_0xf217('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x4f59e7['options']?_0x4f59e7[_0xf217('0x16')][_0xf217('0x17')]||null:null,'attributes':_0x4f59e7[_0xf217('0x16')]?_0x4f59e7['options'][_0xf217('0x18')]||null:null,'limit':_0x4f59e7[_0xf217('0x16')]?_0x4f59e7['options'][_0xf217('0x19')]||null:null,'include':_0x4f59e7['options']?_0x4f59e7[_0xf217('0x16')][_0xf217('0x1a')]?_[_0xf217('0x1b')](_0x4f59e7['options'][_0xf217('0x1a')],function(_0x3f6b04){return{'model':db[_0x3f6b04[_0xf217('0x1c')]],'as':_0x3f6b04['as'],'attributes':_0x3f6b04[_0xf217('0x18')],'include':_0x3f6b04['include']?_[_0xf217('0x1b')](_0x3f6b04['include'],function(_0x2ceada){return{'model':db[_0x2ceada[_0xf217('0x1c')]],'as':_0x2ceada['as'],'attributes':_0x2ceada['attributes'],'include':_0x2ceada[_0xf217('0x1a')]?_[_0xf217('0x1b')](_0x2ceada['include'],function(_0xaa0a1f){return{'model':db[_0xaa0a1f[_0xf217('0x1c')]],'as':_0xaa0a1f['as'],'attributes':_0xaa0a1f[_0xf217('0x18')]};}):[]};}):[]};}):[]:[]})[_0xf217('0x9')](function(_0x771823){logger[_0xf217('0xa')](_0xf217('0x13'),_0x4f59e7);logger[_0xf217('0xd')](_0xf217('0x13'),_0x4f59e7,JSON[_0xf217('0xf')](_0x771823));_0x2a3456(_0x771823);})[_0xf217('0x12')](function(_0x4d56d7){logger[_0xf217('0x10')](_0xf217('0x13'),_0x4d56d7[_0xf217('0x11')],_0x4f59e7);_0x38ca09(_0x385815[_0xf217('0x10')](0x1f4,_0x4d56d7[_0xf217('0x11')]));});});};exports[_0xf217('0x1d')]=function(_0x598bfc){var _0x3aa0c0=this;return new Promise(function(_0x12ad38,_0x27ff1e){return db[_0xf217('0x14')][_0xf217('0x1e')]({'raw':_0x598bfc[_0xf217('0x16')]?_0x598bfc[_0xf217('0x16')][_0xf217('0x1f')]===undefined?!![]:![]:!![],'where':_0x598bfc[_0xf217('0x16')]?_0x598bfc['options'][_0xf217('0x17')]||null:null,'attributes':_0x598bfc[_0xf217('0x16')]?_0x598bfc['options']['attributes']||null:null,'include':_0x598bfc['options']?_0x598bfc[_0xf217('0x16')]['include']?_[_0xf217('0x1b')](_0x598bfc[_0xf217('0x16')][_0xf217('0x1a')],function(_0x2ffa30){return{'model':db[_0x2ffa30[_0xf217('0x1c')]],'as':_0x2ffa30['as'],'attributes':_0x2ffa30[_0xf217('0x18')],'include':_0x2ffa30['include']?_[_0xf217('0x1b')](_0x2ffa30[_0xf217('0x1a')],function(_0x549b5a){return{'model':db[_0x549b5a[_0xf217('0x1c')]],'as':_0x549b5a['as'],'attributes':_0x549b5a[_0xf217('0x18')],'include':_0x549b5a[_0xf217('0x1a')]?_[_0xf217('0x1b')](_0x549b5a[_0xf217('0x1a')],function(_0x549089){return{'model':db[_0x549089[_0xf217('0x1c')]],'as':_0x549089['as'],'attributes':_0x549089[_0xf217('0x18')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x5e983a){logger[_0xf217('0xa')]('ShowTrunk',_0x598bfc);logger['debug'](_0xf217('0x1d'),_0x598bfc,JSON[_0xf217('0xf')](_0x5e983a));_0x12ad38(_0x5e983a);})[_0xf217('0x12')](function(_0x5bd102){logger[_0xf217('0x10')](_0xf217('0x1d'),_0x5bd102[_0xf217('0x11')],_0x598bfc);_0x27ff1e(_0x3aa0c0[_0xf217('0x10')](0x1f4,_0x5bd102[_0xf217('0x11')]));});});};