af9d4caf260616a56aadba43c4eb178b0fdb8f4b
[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 _0x4027=['model','catch','ShowTrunk','Trunk','find','lodash','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','request','then','info','request\x20sent','debug','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','code','Trunk,\x20%s,\x20%s','message','result','GetTrunk','options','raw','attributes','limit','include','map'];(function(_0x503ffd,_0x8ecde){var _0x160437=function(_0x2d45dd){while(--_0x2d45dd){_0x503ffd['push'](_0x503ffd['shift']());}};_0x160437(++_0x8ecde);}(_0x4027,0x1a9));var _0x7402=function(_0x10a608,_0x3877fa){_0x10a608=_0x10a608-0x0;var _0x495161=_0x4027[_0x10a608];return _0x495161;};'use strict';var _=require(_0x7402('0x0'));var util=require('util');var moment=require(_0x7402('0x1'));var BPromise=require(_0x7402('0x2'));var rs=require(_0x7402('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x7402('0x4'))['db'];var utils=require(_0x7402('0x5'));var logger=require(_0x7402('0x6'))(_0x7402('0x7'));var config=require('../../config/environment');var jayson=require(_0x7402('0x8'));var client=jayson[_0x7402('0x9')][_0x7402('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x1919c7,_0x1f2a34,_0x35abfb){return new BPromise(function(_0x1c5624,_0x33bd11){return client[_0x7402('0xb')](_0x1919c7,_0x35abfb)[_0x7402('0xc')](function(_0x2038bb){logger[_0x7402('0xd')]('Trunk,\x20%s,\x20%s',_0x1f2a34,_0x7402('0xe'));logger[_0x7402('0xf')](_0x7402('0x10'),_0x1f2a34,'request\x20sent',JSON[_0x7402('0x11')](_0x2038bb));if(_0x2038bb[_0x7402('0x12')]){if(_0x2038bb['error'][_0x7402('0x13')]===0x1f4){logger['error'](_0x7402('0x14'),_0x1f2a34,_0x2038bb[_0x7402('0x12')][_0x7402('0x15')]);return _0x33bd11(_0x2038bb[_0x7402('0x12')][_0x7402('0x15')]);}logger[_0x7402('0x12')](_0x7402('0x14'),_0x1f2a34,_0x2038bb[_0x7402('0x12')]['message']);return _0x1c5624(_0x2038bb[_0x7402('0x12')][_0x7402('0x15')]);}else{logger[_0x7402('0xd')](_0x7402('0x14'),_0x1f2a34,_0x7402('0xe'));_0x1c5624(_0x2038bb[_0x7402('0x16')][_0x7402('0x15')]);}})['catch'](function(_0x253aeb){logger[_0x7402('0x12')]('Trunk,\x20%s,\x20%s',_0x1f2a34,_0x253aeb);_0x33bd11(_0x253aeb);});});}exports[_0x7402('0x17')]=function(_0x575db7){var _0x186b3e=this;return new Promise(function(_0x4d172a,_0x262ddb){return db['Trunk']['findAll']({'raw':_0x575db7[_0x7402('0x18')]?_0x575db7[_0x7402('0x18')][_0x7402('0x19')]===undefined?!![]:![]:!![],'where':_0x575db7[_0x7402('0x18')]?_0x575db7[_0x7402('0x18')]['where']||null:null,'attributes':_0x575db7[_0x7402('0x18')]?_0x575db7[_0x7402('0x18')][_0x7402('0x1a')]||null:null,'limit':_0x575db7[_0x7402('0x18')]?_0x575db7['options'][_0x7402('0x1b')]||null:null,'include':_0x575db7[_0x7402('0x18')]?_0x575db7[_0x7402('0x18')][_0x7402('0x1c')]?_[_0x7402('0x1d')](_0x575db7[_0x7402('0x18')][_0x7402('0x1c')],function(_0x5761dd){return{'model':db[_0x5761dd['model']],'as':_0x5761dd['as'],'attributes':_0x5761dd['attributes'],'include':_0x5761dd['include']?_[_0x7402('0x1d')](_0x5761dd[_0x7402('0x1c')],function(_0x34de67){return{'model':db[_0x34de67['model']],'as':_0x34de67['as'],'attributes':_0x34de67[_0x7402('0x1a')],'include':_0x34de67['include']?_[_0x7402('0x1d')](_0x34de67[_0x7402('0x1c')],function(_0x35b933){return{'model':db[_0x35b933[_0x7402('0x1e')]],'as':_0x35b933['as'],'attributes':_0x35b933[_0x7402('0x1a')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x463db4){logger['info'](_0x7402('0x17'),_0x575db7);logger[_0x7402('0xf')](_0x7402('0x17'),_0x575db7,JSON[_0x7402('0x11')](_0x463db4));_0x4d172a(_0x463db4);})[_0x7402('0x1f')](function(_0x5242fe){logger[_0x7402('0x12')](_0x7402('0x17'),_0x5242fe['message'],_0x575db7);_0x262ddb(_0x186b3e[_0x7402('0x12')](0x1f4,_0x5242fe['message']));});});};exports[_0x7402('0x20')]=function(_0x318818){var _0x26f459=this;return new Promise(function(_0x21d933,_0x4c08b1){return db[_0x7402('0x21')][_0x7402('0x22')]({'raw':_0x318818['options']?_0x318818['options'][_0x7402('0x19')]===undefined?!![]:![]:!![],'where':_0x318818[_0x7402('0x18')]?_0x318818[_0x7402('0x18')]['where']||null:null,'attributes':_0x318818[_0x7402('0x18')]?_0x318818[_0x7402('0x18')][_0x7402('0x1a')]||null:null,'include':_0x318818['options']?_0x318818[_0x7402('0x18')]['include']?_[_0x7402('0x1d')](_0x318818[_0x7402('0x18')][_0x7402('0x1c')],function(_0x259b16){return{'model':db[_0x259b16[_0x7402('0x1e')]],'as':_0x259b16['as'],'attributes':_0x259b16['attributes'],'include':_0x259b16['include']?_[_0x7402('0x1d')](_0x259b16[_0x7402('0x1c')],function(_0x1e7c5e){return{'model':db[_0x1e7c5e['model']],'as':_0x1e7c5e['as'],'attributes':_0x1e7c5e['attributes'],'include':_0x1e7c5e[_0x7402('0x1c')]?_[_0x7402('0x1d')](_0x1e7c5e[_0x7402('0x1c')],function(_0x1a75d2){return{'model':db[_0x1a75d2[_0x7402('0x1e')]],'as':_0x1a75d2['as'],'attributes':_0x1a75d2[_0x7402('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x7402('0xc')](function(_0xec4482){logger[_0x7402('0xd')](_0x7402('0x20'),_0x318818);logger[_0x7402('0xf')](_0x7402('0x20'),_0x318818,JSON[_0x7402('0x11')](_0xec4482));_0x21d933(_0xec4482);})[_0x7402('0x1f')](function(_0x2f67ab){logger[_0x7402('0x12')](_0x7402('0x20'),_0x2f67ab['message'],_0x318818);_0x4c08b1(_0x26f459[_0x7402('0x12')](0x1f4,_0x2f67ab[_0x7402('0x15')]));});});};