f55adbe500ed8e22f52c95f6206cfb375e7f0b7c
[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 _0xf909=['moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','jayson/promise','client','http','request','Trunk,\x20%s,\x20%s','request\x20sent','debug','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','GetTrunk','Trunk','options','raw','attributes','limit','include','map','model','then','ShowTrunk','find','where','lodash','util'];(function(_0xce7328,_0x298b60){var _0x3da846=function(_0x1b79e8){while(--_0x1b79e8){_0xce7328['push'](_0xce7328['shift']());}};_0x3da846(++_0x298b60);}(_0xf909,0x11e));var _0x9f90=function(_0x4c92e5,_0x57b104){_0x4c92e5=_0x4c92e5-0x0;var _0x1705e0=_0xf909[_0x4c92e5];return _0x1705e0;};'use strict';var _=require(_0x9f90('0x0'));var util=require(_0x9f90('0x1'));var moment=require(_0x9f90('0x2'));var BPromise=require(_0x9f90('0x3'));var rs=require(_0x9f90('0x4'));var fs=require('fs');var Redis=require(_0x9f90('0x5'));var db=require(_0x9f90('0x6'))['db'];var utils=require('../../config/utils');var logger=require(_0x9f90('0x7'))(_0x9f90('0x8'));var config=require('../../config/environment');var jayson=require(_0x9f90('0x9'));var client=jayson[_0x9f90('0xa')][_0x9f90('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x1046bf,_0x55aeb2,_0x2a2f8d){return new BPromise(function(_0x63b5fd,_0x1d3785){return client[_0x9f90('0xc')](_0x1046bf,_0x2a2f8d)['then'](function(_0xdf6328){logger['info'](_0x9f90('0xd'),_0x55aeb2,_0x9f90('0xe'));logger[_0x9f90('0xf')](_0x9f90('0x10'),_0x55aeb2,_0x9f90('0xe'),JSON[_0x9f90('0x11')](_0xdf6328));if(_0xdf6328[_0x9f90('0x12')]){if(_0xdf6328[_0x9f90('0x12')][_0x9f90('0x13')]===0x1f4){logger[_0x9f90('0x12')](_0x9f90('0xd'),_0x55aeb2,_0xdf6328[_0x9f90('0x12')]['message']);return _0x1d3785(_0xdf6328[_0x9f90('0x12')][_0x9f90('0x14')]);}logger['error'](_0x9f90('0xd'),_0x55aeb2,_0xdf6328[_0x9f90('0x12')][_0x9f90('0x14')]);return _0x63b5fd(_0xdf6328[_0x9f90('0x12')]['message']);}else{logger[_0x9f90('0x15')](_0x9f90('0xd'),_0x55aeb2,_0x9f90('0xe'));_0x63b5fd(_0xdf6328[_0x9f90('0x16')]['message']);}})['catch'](function(_0x9f891a){logger['error'](_0x9f90('0xd'),_0x55aeb2,_0x9f891a);_0x1d3785(_0x9f891a);});});}exports[_0x9f90('0x17')]=function(_0x33b144){var _0x1dbaa4=this;return new Promise(function(_0x2b4f6c,_0x379366){return db[_0x9f90('0x18')]['findAll']({'raw':_0x33b144['options']?_0x33b144[_0x9f90('0x19')][_0x9f90('0x1a')]===undefined?!![]:![]:!![],'where':_0x33b144[_0x9f90('0x19')]?_0x33b144[_0x9f90('0x19')]['where']||null:null,'attributes':_0x33b144[_0x9f90('0x19')]?_0x33b144['options'][_0x9f90('0x1b')]||null:null,'limit':_0x33b144[_0x9f90('0x19')]?_0x33b144[_0x9f90('0x19')][_0x9f90('0x1c')]||null:null,'include':_0x33b144[_0x9f90('0x19')]?_0x33b144[_0x9f90('0x19')][_0x9f90('0x1d')]?_[_0x9f90('0x1e')](_0x33b144['options'][_0x9f90('0x1d')],function(_0x5888d9){return{'model':db[_0x5888d9[_0x9f90('0x1f')]],'as':_0x5888d9['as'],'attributes':_0x5888d9[_0x9f90('0x1b')],'include':_0x5888d9[_0x9f90('0x1d')]?_[_0x9f90('0x1e')](_0x5888d9[_0x9f90('0x1d')],function(_0x6bc295){return{'model':db[_0x6bc295[_0x9f90('0x1f')]],'as':_0x6bc295['as'],'attributes':_0x6bc295[_0x9f90('0x1b')],'include':_0x6bc295[_0x9f90('0x1d')]?_[_0x9f90('0x1e')](_0x6bc295[_0x9f90('0x1d')],function(_0x37902d){return{'model':db[_0x37902d[_0x9f90('0x1f')]],'as':_0x37902d['as'],'attributes':_0x37902d[_0x9f90('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x9f90('0x20')](function(_0x1be7c9){logger[_0x9f90('0x15')](_0x9f90('0x17'),_0x33b144);logger[_0x9f90('0xf')](_0x9f90('0x17'),_0x33b144,JSON[_0x9f90('0x11')](_0x1be7c9));_0x2b4f6c(_0x1be7c9);})['catch'](function(_0x1961e9){logger['error'](_0x9f90('0x17'),_0x1961e9[_0x9f90('0x14')],_0x33b144);_0x379366(_0x1dbaa4[_0x9f90('0x12')](0x1f4,_0x1961e9[_0x9f90('0x14')]));});});};exports[_0x9f90('0x21')]=function(_0x1a23fc){var _0x31547b=this;return new Promise(function(_0x2dbd8f,_0x29de66){return db[_0x9f90('0x18')][_0x9f90('0x22')]({'raw':_0x1a23fc[_0x9f90('0x19')]?_0x1a23fc[_0x9f90('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x1a23fc[_0x9f90('0x19')]?_0x1a23fc['options'][_0x9f90('0x23')]||null:null,'attributes':_0x1a23fc[_0x9f90('0x19')]?_0x1a23fc[_0x9f90('0x19')]['attributes']||null:null,'include':_0x1a23fc[_0x9f90('0x19')]?_0x1a23fc[_0x9f90('0x19')][_0x9f90('0x1d')]?_['map'](_0x1a23fc[_0x9f90('0x19')][_0x9f90('0x1d')],function(_0x156f91){return{'model':db[_0x156f91['model']],'as':_0x156f91['as'],'attributes':_0x156f91[_0x9f90('0x1b')],'include':_0x156f91[_0x9f90('0x1d')]?_[_0x9f90('0x1e')](_0x156f91['include'],function(_0x2f16e6){return{'model':db[_0x2f16e6[_0x9f90('0x1f')]],'as':_0x2f16e6['as'],'attributes':_0x2f16e6[_0x9f90('0x1b')],'include':_0x2f16e6[_0x9f90('0x1d')]?_['map'](_0x2f16e6['include'],function(_0x363ec2){return{'model':db[_0x363ec2[_0x9f90('0x1f')]],'as':_0x363ec2['as'],'attributes':_0x363ec2['attributes']};}):[]};}):[]};}):[]:[]})[_0x9f90('0x20')](function(_0x26f9a6){logger[_0x9f90('0x15')]('ShowTrunk',_0x1a23fc);logger[_0x9f90('0xf')](_0x9f90('0x21'),_0x1a23fc,JSON[_0x9f90('0x11')](_0x26f9a6));_0x2dbd8f(_0x26f9a6);})['catch'](function(_0x289886){logger['error']('ShowTrunk',_0x289886[_0x9f90('0x14')],_0x1a23fc);_0x29de66(_0x31547b[_0x9f90('0x12')](0x1f4,_0x289886[_0x9f90('0x14')]));});});};