Built motion from commit 639a1a7f.|2.6.19
[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 _0x8936=['client','request','then','info','request\x20sent','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','code','Trunk,\x20%s,\x20%s','message','result','catch','GetTrunk','Trunk','findAll','options','where','attributes','limit','include','map','model','raw','ShowTrunk','debug','lodash','util','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise'];(function(_0x8a533c,_0x58eb4b){var _0xbaadd9=function(_0x16ba4e){while(--_0x16ba4e){_0x8a533c['push'](_0x8a533c['shift']());}};_0xbaadd9(++_0x58eb4b);}(_0x8936,0x19b));var _0x6893=function(_0x529870,_0x975245){_0x529870=_0x529870-0x0;var _0x39435f=_0x8936[_0x529870];return _0x39435f;};'use strict';var _=require(_0x6893('0x0'));var util=require(_0x6893('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x6893('0x2'));var fs=require('fs');var Redis=require(_0x6893('0x3'));var db=require(_0x6893('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0x6893('0x5'))(_0x6893('0x6'));var config=require(_0x6893('0x7'));var jayson=require(_0x6893('0x8'));var client=jayson[_0x6893('0x9')]['http']({'port':0x232a});function respondWithRpcPromise(_0x6e1e95,_0x5dcc26,_0x35edea){return new BPromise(function(_0x20536d,_0x2dbddb){return client[_0x6893('0xa')](_0x6e1e95,_0x35edea)[_0x6893('0xb')](function(_0x48ed4c){logger[_0x6893('0xc')]('Trunk,\x20%s,\x20%s',_0x5dcc26,_0x6893('0xd'));logger['debug'](_0x6893('0xe'),_0x5dcc26,_0x6893('0xd'),JSON[_0x6893('0xf')](_0x48ed4c));if(_0x48ed4c[_0x6893('0x10')]){if(_0x48ed4c[_0x6893('0x10')][_0x6893('0x11')]===0x1f4){logger[_0x6893('0x10')](_0x6893('0x12'),_0x5dcc26,_0x48ed4c[_0x6893('0x10')][_0x6893('0x13')]);return _0x2dbddb(_0x48ed4c[_0x6893('0x10')][_0x6893('0x13')]);}logger[_0x6893('0x10')](_0x6893('0x12'),_0x5dcc26,_0x48ed4c[_0x6893('0x10')][_0x6893('0x13')]);return _0x20536d(_0x48ed4c['error']['message']);}else{logger[_0x6893('0xc')]('Trunk,\x20%s,\x20%s',_0x5dcc26,_0x6893('0xd'));_0x20536d(_0x48ed4c[_0x6893('0x14')][_0x6893('0x13')]);}})[_0x6893('0x15')](function(_0x3507f8){logger[_0x6893('0x10')](_0x6893('0x12'),_0x5dcc26,_0x3507f8);_0x2dbddb(_0x3507f8);});});}exports[_0x6893('0x16')]=function(_0x2a7c78){var _0x4938ac=this;return new Promise(function(_0x22f409,_0x7c211c){return db[_0x6893('0x17')][_0x6893('0x18')]({'raw':_0x2a7c78[_0x6893('0x19')]?_0x2a7c78[_0x6893('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x2a7c78[_0x6893('0x19')]?_0x2a7c78['options'][_0x6893('0x1a')]||null:null,'attributes':_0x2a7c78[_0x6893('0x19')]?_0x2a7c78[_0x6893('0x19')][_0x6893('0x1b')]||null:null,'limit':_0x2a7c78[_0x6893('0x19')]?_0x2a7c78['options'][_0x6893('0x1c')]||null:null,'include':_0x2a7c78[_0x6893('0x19')]?_0x2a7c78[_0x6893('0x19')][_0x6893('0x1d')]?_[_0x6893('0x1e')](_0x2a7c78[_0x6893('0x19')][_0x6893('0x1d')],function(_0x9d458e){return{'model':db[_0x9d458e[_0x6893('0x1f')]],'as':_0x9d458e['as'],'attributes':_0x9d458e[_0x6893('0x1b')],'include':_0x9d458e['include']?_['map'](_0x9d458e[_0x6893('0x1d')],function(_0x44d4ed){return{'model':db[_0x44d4ed[_0x6893('0x1f')]],'as':_0x44d4ed['as'],'attributes':_0x44d4ed[_0x6893('0x1b')],'include':_0x44d4ed[_0x6893('0x1d')]?_['map'](_0x44d4ed[_0x6893('0x1d')],function(_0x13ea3e){return{'model':db[_0x13ea3e[_0x6893('0x1f')]],'as':_0x13ea3e['as'],'attributes':_0x13ea3e['attributes']};}):[]};}):[]};}):[]:[]})[_0x6893('0xb')](function(_0x1fb72d){logger['info'](_0x6893('0x16'),_0x2a7c78);logger['debug'](_0x6893('0x16'),_0x2a7c78,JSON['stringify'](_0x1fb72d));_0x22f409(_0x1fb72d);})[_0x6893('0x15')](function(_0x1afbde){logger[_0x6893('0x10')](_0x6893('0x16'),_0x1afbde[_0x6893('0x13')],_0x2a7c78);_0x7c211c(_0x4938ac[_0x6893('0x10')](0x1f4,_0x1afbde[_0x6893('0x13')]));});});};exports['ShowTrunk']=function(_0xd88cf1){var _0xeb7d44=this;return new Promise(function(_0x1ba2e3,_0x1c2f00){return db[_0x6893('0x17')]['find']({'raw':_0xd88cf1['options']?_0xd88cf1[_0x6893('0x19')][_0x6893('0x20')]===undefined?!![]:![]:!![],'where':_0xd88cf1[_0x6893('0x19')]?_0xd88cf1['options'][_0x6893('0x1a')]||null:null,'attributes':_0xd88cf1[_0x6893('0x19')]?_0xd88cf1['options'][_0x6893('0x1b')]||null:null,'include':_0xd88cf1[_0x6893('0x19')]?_0xd88cf1['options'][_0x6893('0x1d')]?_['map'](_0xd88cf1[_0x6893('0x19')][_0x6893('0x1d')],function(_0x4a8d60){return{'model':db[_0x4a8d60[_0x6893('0x1f')]],'as':_0x4a8d60['as'],'attributes':_0x4a8d60['attributes'],'include':_0x4a8d60[_0x6893('0x1d')]?_[_0x6893('0x1e')](_0x4a8d60['include'],function(_0x5e1232){return{'model':db[_0x5e1232[_0x6893('0x1f')]],'as':_0x5e1232['as'],'attributes':_0x5e1232[_0x6893('0x1b')],'include':_0x5e1232[_0x6893('0x1d')]?_['map'](_0x5e1232[_0x6893('0x1d')],function(_0x1e927a){return{'model':db[_0x1e927a[_0x6893('0x1f')]],'as':_0x1e927a['as'],'attributes':_0x1e927a['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x185737){logger[_0x6893('0xc')](_0x6893('0x21'),_0xd88cf1);logger[_0x6893('0x22')]('ShowTrunk',_0xd88cf1,JSON[_0x6893('0xf')](_0x185737));_0x1ba2e3(_0x185737);})[_0x6893('0x15')](function(_0x18560c){logger[_0x6893('0x10')](_0x6893('0x21'),_0x18560c[_0x6893('0x13')],_0xd88cf1);_0x1c2f00(_0xeb7d44[_0x6893('0x10')](0x1f4,_0x18560c[_0x6893('0x13')]));});});};