7ea663a46ef8594466c257a2b6763742bba7ed08
[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 _0x0253=['map','model','stringify','ShowTrunk','lodash','util','bluebird','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','then','Trunk,\x20%s,\x20%s','debug','Trunk,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','result','catch','GetTrunk','findAll','options','where','attributes','limit','include'];(function(_0x824e2b,_0x296489){var _0x55d1e1=function(_0x463c27){while(--_0x463c27){_0x824e2b['push'](_0x824e2b['shift']());}};_0x55d1e1(++_0x296489);}(_0x0253,0x16f));var _0x3025=function(_0x37f21d,_0xf276c7){_0x37f21d=_0x37f21d-0x0;var _0x3bc474=_0x0253[_0x37f21d];return _0x3bc474;};'use strict';var _=require(_0x3025('0x0'));var util=require(_0x3025('0x1'));var moment=require('moment');var BPromise=require(_0x3025('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x3025('0x3'));var db=require(_0x3025('0x4'))['db'];var utils=require(_0x3025('0x5'));var logger=require(_0x3025('0x6'))(_0x3025('0x7'));var config=require(_0x3025('0x8'));var jayson=require(_0x3025('0x9'));var client=jayson[_0x3025('0xa')][_0x3025('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x412e86,_0x372e4a,_0x5e785f){return new BPromise(function(_0x272315,_0x333216){return client['request'](_0x412e86,_0x5e785f)[_0x3025('0xc')](function(_0x1a784a){logger['info'](_0x3025('0xd'),_0x372e4a,'request\x20sent');logger[_0x3025('0xe')](_0x3025('0xf'),_0x372e4a,_0x3025('0x10'),JSON['stringify'](_0x1a784a));if(_0x1a784a[_0x3025('0x11')]){if(_0x1a784a[_0x3025('0x11')][_0x3025('0x12')]===0x1f4){logger['error'](_0x3025('0xd'),_0x372e4a,_0x1a784a[_0x3025('0x11')][_0x3025('0x13')]);return _0x333216(_0x1a784a[_0x3025('0x11')][_0x3025('0x13')]);}logger[_0x3025('0x11')](_0x3025('0xd'),_0x372e4a,_0x1a784a[_0x3025('0x11')][_0x3025('0x13')]);return _0x272315(_0x1a784a[_0x3025('0x11')][_0x3025('0x13')]);}else{logger['info'](_0x3025('0xd'),_0x372e4a,_0x3025('0x10'));_0x272315(_0x1a784a[_0x3025('0x14')]['message']);}})[_0x3025('0x15')](function(_0x2cf5dc){logger[_0x3025('0x11')](_0x3025('0xd'),_0x372e4a,_0x2cf5dc);_0x333216(_0x2cf5dc);});});}exports[_0x3025('0x16')]=function(_0x27b097){var _0x1cf2d4=this;return new Promise(function(_0x5872c1,_0x391418){return db['Trunk'][_0x3025('0x17')]({'raw':_0x27b097[_0x3025('0x18')]?_0x27b097[_0x3025('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x27b097[_0x3025('0x18')]?_0x27b097['options'][_0x3025('0x19')]||null:null,'attributes':_0x27b097[_0x3025('0x18')]?_0x27b097[_0x3025('0x18')][_0x3025('0x1a')]||null:null,'limit':_0x27b097[_0x3025('0x18')]?_0x27b097[_0x3025('0x18')][_0x3025('0x1b')]||null:null,'include':_0x27b097[_0x3025('0x18')]?_0x27b097['options'][_0x3025('0x1c')]?_[_0x3025('0x1d')](_0x27b097[_0x3025('0x18')]['include'],function(_0x46c75e){return{'model':db[_0x46c75e[_0x3025('0x1e')]],'as':_0x46c75e['as'],'attributes':_0x46c75e[_0x3025('0x1a')],'include':_0x46c75e[_0x3025('0x1c')]?_[_0x3025('0x1d')](_0x46c75e[_0x3025('0x1c')],function(_0x40c7fd){return{'model':db[_0x40c7fd['model']],'as':_0x40c7fd['as'],'attributes':_0x40c7fd[_0x3025('0x1a')],'include':_0x40c7fd[_0x3025('0x1c')]?_['map'](_0x40c7fd[_0x3025('0x1c')],function(_0x2ed96e){return{'model':db[_0x2ed96e[_0x3025('0x1e')]],'as':_0x2ed96e['as'],'attributes':_0x2ed96e[_0x3025('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x3025('0xc')](function(_0x257944){logger['info'](_0x3025('0x16'),_0x27b097);logger[_0x3025('0xe')](_0x3025('0x16'),_0x27b097,JSON[_0x3025('0x1f')](_0x257944));_0x5872c1(_0x257944);})[_0x3025('0x15')](function(_0x395dd1){logger[_0x3025('0x11')]('GetTrunk',_0x395dd1[_0x3025('0x13')],_0x27b097);_0x391418(_0x1cf2d4[_0x3025('0x11')](0x1f4,_0x395dd1[_0x3025('0x13')]));});});};exports[_0x3025('0x20')]=function(_0x65b944){var _0x150d50=this;return new Promise(function(_0x4e78dd,_0xa6c3b9){return db['Trunk']['find']({'raw':_0x65b944[_0x3025('0x18')]?_0x65b944['options']['raw']===undefined?!![]:![]:!![],'where':_0x65b944[_0x3025('0x18')]?_0x65b944[_0x3025('0x18')][_0x3025('0x19')]||null:null,'attributes':_0x65b944['options']?_0x65b944[_0x3025('0x18')]['attributes']||null:null,'include':_0x65b944[_0x3025('0x18')]?_0x65b944[_0x3025('0x18')][_0x3025('0x1c')]?_[_0x3025('0x1d')](_0x65b944[_0x3025('0x18')][_0x3025('0x1c')],function(_0x3ae2ed){return{'model':db[_0x3ae2ed['model']],'as':_0x3ae2ed['as'],'attributes':_0x3ae2ed[_0x3025('0x1a')],'include':_0x3ae2ed['include']?_[_0x3025('0x1d')](_0x3ae2ed[_0x3025('0x1c')],function(_0x4453d3){return{'model':db[_0x4453d3[_0x3025('0x1e')]],'as':_0x4453d3['as'],'attributes':_0x4453d3[_0x3025('0x1a')],'include':_0x4453d3[_0x3025('0x1c')]?_[_0x3025('0x1d')](_0x4453d3['include'],function(_0x3ab2c4){return{'model':db[_0x3ab2c4[_0x3025('0x1e')]],'as':_0x3ab2c4['as'],'attributes':_0x3ab2c4[_0x3025('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x3025('0xc')](function(_0xe9ee30){logger['info']('ShowTrunk',_0x65b944);logger[_0x3025('0xe')](_0x3025('0x20'),_0x65b944,JSON[_0x3025('0x1f')](_0xe9ee30));_0x4e78dd(_0xe9ee30);})['catch'](function(_0x3acfee){logger[_0x3025('0x11')](_0x3025('0x20'),_0x3acfee['message'],_0x65b944);_0xa6c3b9(_0x150d50[_0x3025('0x11')](0x1f4,_0x3acfee['message']));});});};