Built motion from commit f7863d46.|2.5.41
[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 _0x8874=['ShowTrunk','find','raw','then','util','bluebird','randomstring','ioredis','../../config/logger','rpc','jayson/promise','client','http','request','info','debug','Trunk,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','Trunk,\x20%s,\x20%s','catch','Trunk','findAll','options','where','attributes','limit','model','include','map','stringify','GetTrunk'];(function(_0x2318c9,_0x446462){var _0x33894b=function(_0x4afc00){while(--_0x4afc00){_0x2318c9['push'](_0x2318c9['shift']());}};_0x33894b(++_0x446462);}(_0x8874,0xf2));var _0x4887=function(_0x2d7884,_0x3047f8){_0x2d7884=_0x2d7884-0x0;var _0x119d42=_0x8874[_0x2d7884];return _0x119d42;};'use strict';var _=require('lodash');var util=require(_0x4887('0x0'));var moment=require('moment');var BPromise=require(_0x4887('0x1'));var rs=require(_0x4887('0x2'));var fs=require('fs');var Redis=require(_0x4887('0x3'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x4887('0x4'))(_0x4887('0x5'));var config=require('../../config/environment');var jayson=require(_0x4887('0x6'));var client=jayson[_0x4887('0x7')][_0x4887('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x426a0d,_0x92d415,_0x2f18e5){return new BPromise(function(_0x3a0b0a,_0x2bb8c6){return client[_0x4887('0x9')](_0x426a0d,_0x2f18e5)['then'](function(_0x5f50e7){logger[_0x4887('0xa')]('Trunk,\x20%s,\x20%s',_0x92d415,'request\x20sent');logger[_0x4887('0xb')](_0x4887('0xc'),_0x92d415,_0x4887('0xd'),JSON['stringify'](_0x5f50e7));if(_0x5f50e7[_0x4887('0xe')]){if(_0x5f50e7[_0x4887('0xe')][_0x4887('0xf')]===0x1f4){logger[_0x4887('0xe')]('Trunk,\x20%s,\x20%s',_0x92d415,_0x5f50e7[_0x4887('0xe')]['message']);return _0x2bb8c6(_0x5f50e7['error'][_0x4887('0x10')]);}logger[_0x4887('0xe')](_0x4887('0x11'),_0x92d415,_0x5f50e7[_0x4887('0xe')]['message']);return _0x3a0b0a(_0x5f50e7['error'][_0x4887('0x10')]);}else{logger[_0x4887('0xa')](_0x4887('0x11'),_0x92d415,'request\x20sent');_0x3a0b0a(_0x5f50e7['result'][_0x4887('0x10')]);}})[_0x4887('0x12')](function(_0xe8d9c7){logger[_0x4887('0xe')]('Trunk,\x20%s,\x20%s',_0x92d415,_0xe8d9c7);_0x2bb8c6(_0xe8d9c7);});});}exports['GetTrunk']=function(_0x2f4867){var _0xf40c73=this;return new Promise(function(_0x350333,_0x420fd1){return db[_0x4887('0x13')][_0x4887('0x14')]({'raw':_0x2f4867[_0x4887('0x15')]?_0x2f4867['options']['raw']===undefined?!![]:![]:!![],'where':_0x2f4867[_0x4887('0x15')]?_0x2f4867['options'][_0x4887('0x16')]||null:null,'attributes':_0x2f4867[_0x4887('0x15')]?_0x2f4867[_0x4887('0x15')][_0x4887('0x17')]||null:null,'limit':_0x2f4867[_0x4887('0x15')]?_0x2f4867[_0x4887('0x15')][_0x4887('0x18')]||null:null,'include':_0x2f4867[_0x4887('0x15')]?_0x2f4867[_0x4887('0x15')]['include']?_['map'](_0x2f4867[_0x4887('0x15')]['include'],function(_0x50d5ca){return{'model':db[_0x50d5ca[_0x4887('0x19')]],'as':_0x50d5ca['as'],'attributes':_0x50d5ca[_0x4887('0x17')],'include':_0x50d5ca[_0x4887('0x1a')]?_[_0x4887('0x1b')](_0x50d5ca[_0x4887('0x1a')],function(_0xef700c){return{'model':db[_0xef700c[_0x4887('0x19')]],'as':_0xef700c['as'],'attributes':_0xef700c[_0x4887('0x17')],'include':_0xef700c['include']?_[_0x4887('0x1b')](_0xef700c[_0x4887('0x1a')],function(_0x15c7e7){return{'model':db[_0x15c7e7[_0x4887('0x19')]],'as':_0x15c7e7['as'],'attributes':_0x15c7e7['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x2ada49){logger[_0x4887('0xa')]('GetTrunk',_0x2f4867);logger[_0x4887('0xb')]('GetTrunk',_0x2f4867,JSON[_0x4887('0x1c')](_0x2ada49));_0x350333(_0x2ada49);})[_0x4887('0x12')](function(_0x2b6674){logger['error'](_0x4887('0x1d'),_0x2b6674[_0x4887('0x10')],_0x2f4867);_0x420fd1(_0xf40c73['error'](0x1f4,_0x2b6674[_0x4887('0x10')]));});});};exports[_0x4887('0x1e')]=function(_0x590897){var _0x1d783b=this;return new Promise(function(_0x275503,_0x46d6bf){return db[_0x4887('0x13')][_0x4887('0x1f')]({'raw':_0x590897[_0x4887('0x15')]?_0x590897[_0x4887('0x15')][_0x4887('0x20')]===undefined?!![]:![]:!![],'where':_0x590897[_0x4887('0x15')]?_0x590897[_0x4887('0x15')][_0x4887('0x16')]||null:null,'attributes':_0x590897[_0x4887('0x15')]?_0x590897[_0x4887('0x15')][_0x4887('0x17')]||null:null,'include':_0x590897[_0x4887('0x15')]?_0x590897[_0x4887('0x15')]['include']?_[_0x4887('0x1b')](_0x590897[_0x4887('0x15')][_0x4887('0x1a')],function(_0x5d99cc){return{'model':db[_0x5d99cc[_0x4887('0x19')]],'as':_0x5d99cc['as'],'attributes':_0x5d99cc[_0x4887('0x17')],'include':_0x5d99cc[_0x4887('0x1a')]?_[_0x4887('0x1b')](_0x5d99cc['include'],function(_0x11d1c8){return{'model':db[_0x11d1c8[_0x4887('0x19')]],'as':_0x11d1c8['as'],'attributes':_0x11d1c8['attributes'],'include':_0x11d1c8[_0x4887('0x1a')]?_[_0x4887('0x1b')](_0x11d1c8[_0x4887('0x1a')],function(_0x4f179c){return{'model':db[_0x4f179c[_0x4887('0x19')]],'as':_0x4f179c['as'],'attributes':_0x4f179c['attributes']};}):[]};}):[]};}):[]:[]})[_0x4887('0x21')](function(_0x2caa62){logger[_0x4887('0xa')](_0x4887('0x1e'),_0x590897);logger[_0x4887('0xb')](_0x4887('0x1e'),_0x590897,JSON['stringify'](_0x2caa62));_0x275503(_0x2caa62);})[_0x4887('0x12')](function(_0x4c4fb5){logger[_0x4887('0xe')](_0x4887('0x1e'),_0x4c4fb5[_0x4887('0x10')],_0x590897);_0x46d6bf(_0x1d783b[_0x4887('0xe')](0x1f4,_0x4c4fb5[_0x4887('0x10')]));});});};