Built motion from commit (unavailable).|2.2.0
[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 _0xea51=['randomstring','ioredis','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','then','Trunk,\x20%s,\x20%s','request\x20sent','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','catch','GetTrunk','findAll','options','where','attributes','limit','include','map','model','debug','ShowTrunk','Trunk','find','raw','lodash','moment','bluebird'];(function(_0x4c9e8a,_0x46795){var _0x31a1f8=function(_0x47d3a7){while(--_0x47d3a7){_0x4c9e8a['push'](_0x4c9e8a['shift']());}};_0x31a1f8(++_0x46795);}(_0xea51,0x14a));var _0x1ea5=function(_0x17d9a7,_0x48daac){_0x17d9a7=_0x17d9a7-0x0;var _0xc4174e=_0xea51[_0x17d9a7];return _0xc4174e;};'use strict';var _=require(_0x1ea5('0x0'));var util=require('util');var moment=require(_0x1ea5('0x1'));var BPromise=require(_0x1ea5('0x2'));var rs=require(_0x1ea5('0x3'));var fs=require('fs');var Redis=require(_0x1ea5('0x4'));var db=require('../../mysqldb')['db'];var utils=require(_0x1ea5('0x5'));var logger=require(_0x1ea5('0x6'))(_0x1ea5('0x7'));var config=require(_0x1ea5('0x8'));var jayson=require(_0x1ea5('0x9'));var client=jayson[_0x1ea5('0xa')][_0x1ea5('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x4ca29e,_0x357479,_0x412e6b){return new BPromise(function(_0x5f67a1,_0x2baeaa){return client[_0x1ea5('0xc')](_0x4ca29e,_0x412e6b)[_0x1ea5('0xd')](function(_0x6ccf3d){logger['info'](_0x1ea5('0xe'),_0x357479,_0x1ea5('0xf'));logger['debug'](_0x1ea5('0x10'),_0x357479,_0x1ea5('0xf'),JSON[_0x1ea5('0x11')](_0x6ccf3d));if(_0x6ccf3d[_0x1ea5('0x12')]){if(_0x6ccf3d[_0x1ea5('0x12')][_0x1ea5('0x13')]===0x1f4){logger[_0x1ea5('0x12')](_0x1ea5('0xe'),_0x357479,_0x6ccf3d[_0x1ea5('0x12')][_0x1ea5('0x14')]);return _0x2baeaa(_0x6ccf3d[_0x1ea5('0x12')][_0x1ea5('0x14')]);}logger['error']('Trunk,\x20%s,\x20%s',_0x357479,_0x6ccf3d[_0x1ea5('0x12')]['message']);return _0x5f67a1(_0x6ccf3d[_0x1ea5('0x12')][_0x1ea5('0x14')]);}else{logger[_0x1ea5('0x15')]('Trunk,\x20%s,\x20%s',_0x357479,_0x1ea5('0xf'));_0x5f67a1(_0x6ccf3d['result']['message']);}})[_0x1ea5('0x16')](function(_0x2b8128){logger['error'](_0x1ea5('0xe'),_0x357479,_0x2b8128);_0x2baeaa(_0x2b8128);});});}exports[_0x1ea5('0x17')]=function(_0x280164){var _0x5b4a49=this;return new Promise(function(_0x3dffed,_0x3481e7){return db['Trunk'][_0x1ea5('0x18')]({'raw':_0x280164[_0x1ea5('0x19')]?_0x280164[_0x1ea5('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x280164[_0x1ea5('0x19')]?_0x280164[_0x1ea5('0x19')][_0x1ea5('0x1a')]||null:null,'attributes':_0x280164[_0x1ea5('0x19')]?_0x280164['options'][_0x1ea5('0x1b')]||null:null,'limit':_0x280164[_0x1ea5('0x19')]?_0x280164['options'][_0x1ea5('0x1c')]||null:null,'include':_0x280164['options']?_0x280164[_0x1ea5('0x19')][_0x1ea5('0x1d')]?_[_0x1ea5('0x1e')](_0x280164['options'][_0x1ea5('0x1d')],function(_0x342e9e){return{'model':db[_0x342e9e[_0x1ea5('0x1f')]],'as':_0x342e9e['as'],'attributes':_0x342e9e[_0x1ea5('0x1b')],'include':_0x342e9e['include']?_[_0x1ea5('0x1e')](_0x342e9e[_0x1ea5('0x1d')],function(_0x269c85){return{'model':db[_0x269c85['model']],'as':_0x269c85['as'],'attributes':_0x269c85[_0x1ea5('0x1b')],'include':_0x269c85[_0x1ea5('0x1d')]?_[_0x1ea5('0x1e')](_0x269c85[_0x1ea5('0x1d')],function(_0x456b40){return{'model':db[_0x456b40[_0x1ea5('0x1f')]],'as':_0x456b40['as'],'attributes':_0x456b40[_0x1ea5('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x1ea5('0xd')](function(_0x7f88e2){logger['info'](_0x1ea5('0x17'),_0x280164);logger[_0x1ea5('0x20')]('GetTrunk',_0x280164,JSON[_0x1ea5('0x11')](_0x7f88e2));_0x3dffed(_0x7f88e2);})['catch'](function(_0x4c897d){logger['error'](_0x1ea5('0x17'),_0x4c897d[_0x1ea5('0x14')],_0x280164);_0x3481e7(_0x5b4a49['error'](0x1f4,_0x4c897d[_0x1ea5('0x14')]));});});};exports[_0x1ea5('0x21')]=function(_0x124353){var _0x313c78=this;return new Promise(function(_0x2043d0,_0x179ab1){return db[_0x1ea5('0x22')][_0x1ea5('0x23')]({'raw':_0x124353[_0x1ea5('0x19')]?_0x124353[_0x1ea5('0x19')][_0x1ea5('0x24')]===undefined?!![]:![]:!![],'where':_0x124353[_0x1ea5('0x19')]?_0x124353['options'][_0x1ea5('0x1a')]||null:null,'attributes':_0x124353['options']?_0x124353['options']['attributes']||null:null,'include':_0x124353[_0x1ea5('0x19')]?_0x124353[_0x1ea5('0x19')][_0x1ea5('0x1d')]?_['map'](_0x124353[_0x1ea5('0x19')][_0x1ea5('0x1d')],function(_0x372a26){return{'model':db[_0x372a26[_0x1ea5('0x1f')]],'as':_0x372a26['as'],'attributes':_0x372a26[_0x1ea5('0x1b')],'include':_0x372a26[_0x1ea5('0x1d')]?_['map'](_0x372a26['include'],function(_0x429222){return{'model':db[_0x429222[_0x1ea5('0x1f')]],'as':_0x429222['as'],'attributes':_0x429222[_0x1ea5('0x1b')],'include':_0x429222['include']?_['map'](_0x429222[_0x1ea5('0x1d')],function(_0x58fcf6){return{'model':db[_0x58fcf6['model']],'as':_0x58fcf6['as'],'attributes':_0x58fcf6[_0x1ea5('0x1b')]};}):[]};}):[]};}):[]:[]})[_0x1ea5('0xd')](function(_0x3e2496){logger[_0x1ea5('0x15')](_0x1ea5('0x21'),_0x124353);logger[_0x1ea5('0x20')](_0x1ea5('0x21'),_0x124353,JSON[_0x1ea5('0x11')](_0x3e2496));_0x2043d0(_0x3e2496);})['catch'](function(_0x4c0511){logger[_0x1ea5('0x12')](_0x1ea5('0x21'),_0x4c0511[_0x1ea5('0x14')],_0x124353);_0x179ab1(_0x313c78['error'](0x1f4,_0x4c0511[_0x1ea5('0x14')]));});});};