04a35a19fafbf4ef7d32f87d610bd4489c7ec43b
[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 _0xcc20=['model','debug','catch','ShowTrunk','find','lodash','util','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','request','then','info','Trunk,\x20%s,\x20%s','request\x20sent','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','GetTrunk','Trunk','findAll','options','raw','where','attributes','limit','map','include'];(function(_0xf1f80b,_0x44d17f){var _0x480b6a=function(_0x25199d){while(--_0x25199d){_0xf1f80b['push'](_0xf1f80b['shift']());}};_0x480b6a(++_0x44d17f);}(_0xcc20,0x108));var _0x0cc2=function(_0x587b46,_0x5195fa){_0x587b46=_0x587b46-0x0;var _0x2a4fd2=_0xcc20[_0x587b46];return _0x2a4fd2;};'use strict';var _=require(_0x0cc2('0x0'));var util=require(_0x0cc2('0x1'));var moment=require('moment');var BPromise=require(_0x0cc2('0x2'));var rs=require(_0x0cc2('0x3'));var fs=require('fs');var Redis=require(_0x0cc2('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x0cc2('0x5'));var logger=require(_0x0cc2('0x6'))(_0x0cc2('0x7'));var config=require(_0x0cc2('0x8'));var jayson=require(_0x0cc2('0x9'));var client=jayson['client'][_0x0cc2('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x4eb5d3,_0xa1d19,_0x144680){return new BPromise(function(_0x4304f7,_0x1a2d79){return client[_0x0cc2('0xb')](_0x4eb5d3,_0x144680)[_0x0cc2('0xc')](function(_0x1153d5){logger[_0x0cc2('0xd')](_0x0cc2('0xe'),_0xa1d19,_0x0cc2('0xf'));logger['debug'](_0x0cc2('0x10'),_0xa1d19,'request\x20sent',JSON[_0x0cc2('0x11')](_0x1153d5));if(_0x1153d5[_0x0cc2('0x12')]){if(_0x1153d5['error'][_0x0cc2('0x13')]===0x1f4){logger[_0x0cc2('0x12')]('Trunk,\x20%s,\x20%s',_0xa1d19,_0x1153d5['error'][_0x0cc2('0x14')]);return _0x1a2d79(_0x1153d5['error'][_0x0cc2('0x14')]);}logger[_0x0cc2('0x12')](_0x0cc2('0xe'),_0xa1d19,_0x1153d5[_0x0cc2('0x12')]['message']);return _0x4304f7(_0x1153d5['error']['message']);}else{logger[_0x0cc2('0xd')](_0x0cc2('0xe'),_0xa1d19,'request\x20sent');_0x4304f7(_0x1153d5[_0x0cc2('0x15')][_0x0cc2('0x14')]);}})['catch'](function(_0x4a0c56){logger[_0x0cc2('0x12')](_0x0cc2('0xe'),_0xa1d19,_0x4a0c56);_0x1a2d79(_0x4a0c56);});});}exports[_0x0cc2('0x16')]=function(_0x3d5d88){var _0x114673=this;return new Promise(function(_0xbb25e0,_0x4b63f1){return db[_0x0cc2('0x17')][_0x0cc2('0x18')]({'raw':_0x3d5d88[_0x0cc2('0x19')]?_0x3d5d88[_0x0cc2('0x19')][_0x0cc2('0x1a')]===undefined?!![]:![]:!![],'where':_0x3d5d88[_0x0cc2('0x19')]?_0x3d5d88[_0x0cc2('0x19')][_0x0cc2('0x1b')]||null:null,'attributes':_0x3d5d88[_0x0cc2('0x19')]?_0x3d5d88['options'][_0x0cc2('0x1c')]||null:null,'limit':_0x3d5d88[_0x0cc2('0x19')]?_0x3d5d88['options'][_0x0cc2('0x1d')]||null:null,'include':_0x3d5d88[_0x0cc2('0x19')]?_0x3d5d88[_0x0cc2('0x19')]['include']?_[_0x0cc2('0x1e')](_0x3d5d88[_0x0cc2('0x19')][_0x0cc2('0x1f')],function(_0x1fabb2){return{'model':db[_0x1fabb2['model']],'as':_0x1fabb2['as'],'attributes':_0x1fabb2[_0x0cc2('0x1c')],'include':_0x1fabb2[_0x0cc2('0x1f')]?_['map'](_0x1fabb2[_0x0cc2('0x1f')],function(_0x7fcc79){return{'model':db[_0x7fcc79[_0x0cc2('0x20')]],'as':_0x7fcc79['as'],'attributes':_0x7fcc79[_0x0cc2('0x1c')],'include':_0x7fcc79[_0x0cc2('0x1f')]?_[_0x0cc2('0x1e')](_0x7fcc79[_0x0cc2('0x1f')],function(_0x286a36){return{'model':db[_0x286a36[_0x0cc2('0x20')]],'as':_0x286a36['as'],'attributes':_0x286a36[_0x0cc2('0x1c')]};}):[]};}):[]};}):[]:[]})[_0x0cc2('0xc')](function(_0x3fa558){logger[_0x0cc2('0xd')](_0x0cc2('0x16'),_0x3d5d88);logger[_0x0cc2('0x21')](_0x0cc2('0x16'),_0x3d5d88,JSON[_0x0cc2('0x11')](_0x3fa558));_0xbb25e0(_0x3fa558);})[_0x0cc2('0x22')](function(_0x4a6aa2){logger[_0x0cc2('0x12')](_0x0cc2('0x16'),_0x4a6aa2[_0x0cc2('0x14')],_0x3d5d88);_0x4b63f1(_0x114673[_0x0cc2('0x12')](0x1f4,_0x4a6aa2[_0x0cc2('0x14')]));});});};exports[_0x0cc2('0x23')]=function(_0x37ff72){var _0x37009d=this;return new Promise(function(_0x516d0a,_0x2839a9){return db['Trunk'][_0x0cc2('0x24')]({'raw':_0x37ff72[_0x0cc2('0x19')]?_0x37ff72[_0x0cc2('0x19')][_0x0cc2('0x1a')]===undefined?!![]:![]:!![],'where':_0x37ff72[_0x0cc2('0x19')]?_0x37ff72['options'][_0x0cc2('0x1b')]||null:null,'attributes':_0x37ff72[_0x0cc2('0x19')]?_0x37ff72[_0x0cc2('0x19')][_0x0cc2('0x1c')]||null:null,'include':_0x37ff72['options']?_0x37ff72['options'][_0x0cc2('0x1f')]?_[_0x0cc2('0x1e')](_0x37ff72[_0x0cc2('0x19')][_0x0cc2('0x1f')],function(_0x4e42f0){return{'model':db[_0x4e42f0[_0x0cc2('0x20')]],'as':_0x4e42f0['as'],'attributes':_0x4e42f0[_0x0cc2('0x1c')],'include':_0x4e42f0[_0x0cc2('0x1f')]?_[_0x0cc2('0x1e')](_0x4e42f0['include'],function(_0x5ce7be){return{'model':db[_0x5ce7be[_0x0cc2('0x20')]],'as':_0x5ce7be['as'],'attributes':_0x5ce7be[_0x0cc2('0x1c')],'include':_0x5ce7be[_0x0cc2('0x1f')]?_['map'](_0x5ce7be[_0x0cc2('0x1f')],function(_0x42131d){return{'model':db[_0x42131d[_0x0cc2('0x20')]],'as':_0x42131d['as'],'attributes':_0x42131d['attributes']};}):[]};}):[]};}):[]:[]})[_0x0cc2('0xc')](function(_0xdfafe3){logger['info'](_0x0cc2('0x23'),_0x37ff72);logger['debug']('ShowTrunk',_0x37ff72,JSON[_0x0cc2('0x11')](_0xdfafe3));_0x516d0a(_0xdfafe3);})[_0x0cc2('0x22')](function(_0x2b65b9){logger[_0x0cc2('0x12')](_0x0cc2('0x23'),_0x2b65b9[_0x0cc2('0x14')],_0x37ff72);_0x2839a9(_0x37009d[_0x0cc2('0x12')](0x1f4,_0x2b65b9[_0x0cc2('0x14')]));});});};