b35530ff898c639c1fcc757b27a2db3ad2587e98
[motion2.git] / server / api / voiceExtension / voiceExtension.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 _0xbfe8=['request','then','info','request\x20sent','debug','VoiceExtension,\x20%s,\x20%s,\x20%s','error','code','VoiceExtension,\x20%s,\x20%s','message','result','catch','VoiceExtension','options','attributes','limit','include','model','map','GetVoiceExtension','stringify','util','bluebird','randomstring','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','redis','defaults','localhost','socket.io-emitter','./voiceExtension.socket','register'];(function(_0x30ae5e,_0x391fc4){var _0x1f2e93=function(_0x60307d){while(--_0x60307d){_0x30ae5e['push'](_0x30ae5e['shift']());}};_0x1f2e93(++_0x391fc4);}(_0xbfe8,0x1b9));var _0x8bfe=function(_0x224f61,_0x4c881d){_0x224f61=_0x224f61-0x0;var _0x51caa3=_0xbfe8[_0x224f61];return _0x51caa3;};'use strict';var _=require('lodash');var util=require(_0x8bfe('0x0'));var moment=require('moment');var BPromise=require(_0x8bfe('0x1'));var rs=require(_0x8bfe('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x8bfe('0x3'));var logger=require(_0x8bfe('0x4'))('rpc');var config=require(_0x8bfe('0x5'));var jayson=require(_0x8bfe('0x6'));var client=jayson[_0x8bfe('0x7')]['http']({'port':0x232a});config[_0x8bfe('0x8')]=_[_0x8bfe('0x9')](config[_0x8bfe('0x8')],{'host':_0x8bfe('0xa'),'port':0x18eb});var socket=require(_0x8bfe('0xb'))(new Redis(config[_0x8bfe('0x8')]));require(_0x8bfe('0xc'))[_0x8bfe('0xd')](socket);function respondWithRpcPromise(_0x243a11,_0xc1f3c3,_0x1f19ee){return new BPromise(function(_0x18cc30,_0x3a07cf){return client[_0x8bfe('0xe')](_0x243a11,_0x1f19ee)[_0x8bfe('0xf')](function(_0x4dd881){logger[_0x8bfe('0x10')]('VoiceExtension,\x20%s,\x20%s',_0xc1f3c3,_0x8bfe('0x11'));logger[_0x8bfe('0x12')](_0x8bfe('0x13'),_0xc1f3c3,'request\x20sent',JSON['stringify'](_0x4dd881));if(_0x4dd881[_0x8bfe('0x14')]){if(_0x4dd881[_0x8bfe('0x14')][_0x8bfe('0x15')]===0x1f4){logger[_0x8bfe('0x14')](_0x8bfe('0x16'),_0xc1f3c3,_0x4dd881['error'][_0x8bfe('0x17')]);return _0x3a07cf(_0x4dd881[_0x8bfe('0x14')]['message']);}logger[_0x8bfe('0x14')](_0x8bfe('0x16'),_0xc1f3c3,_0x4dd881[_0x8bfe('0x14')]['message']);return _0x18cc30(_0x4dd881['error'][_0x8bfe('0x17')]);}else{logger['info']('VoiceExtension,\x20%s,\x20%s',_0xc1f3c3,_0x8bfe('0x11'));_0x18cc30(_0x4dd881[_0x8bfe('0x18')][_0x8bfe('0x17')]);}})[_0x8bfe('0x19')](function(_0xfd4a2a){logger[_0x8bfe('0x14')](_0x8bfe('0x16'),_0xc1f3c3,_0xfd4a2a);_0x3a07cf(_0xfd4a2a);});});}exports['GetVoiceExtension']=function(_0xbc7fa2){var _0x5442e1=this;return new Promise(function(_0x2e64ee,_0x3f8050){return db[_0x8bfe('0x1a')]['findAll']({'raw':_0xbc7fa2['options']?_0xbc7fa2[_0x8bfe('0x1b')]['raw']===undefined?!![]:![]:!![],'where':_0xbc7fa2['options']?_0xbc7fa2[_0x8bfe('0x1b')]['where']||null:null,'attributes':_0xbc7fa2[_0x8bfe('0x1b')]?_0xbc7fa2['options'][_0x8bfe('0x1c')]||null:null,'limit':_0xbc7fa2[_0x8bfe('0x1b')]?_0xbc7fa2[_0x8bfe('0x1b')][_0x8bfe('0x1d')]||null:null,'include':_0xbc7fa2['options']?_0xbc7fa2[_0x8bfe('0x1b')][_0x8bfe('0x1e')]?_['map'](_0xbc7fa2[_0x8bfe('0x1b')][_0x8bfe('0x1e')],function(_0x46526f){return{'model':db[_0x46526f[_0x8bfe('0x1f')]],'as':_0x46526f['as'],'attributes':_0x46526f[_0x8bfe('0x1c')],'include':_0x46526f[_0x8bfe('0x1e')]?_['map'](_0x46526f[_0x8bfe('0x1e')],function(_0x458888){return{'model':db[_0x458888[_0x8bfe('0x1f')]],'as':_0x458888['as'],'attributes':_0x458888[_0x8bfe('0x1c')],'include':_0x458888[_0x8bfe('0x1e')]?_[_0x8bfe('0x20')](_0x458888[_0x8bfe('0x1e')],function(_0x2cbfb3){return{'model':db[_0x2cbfb3[_0x8bfe('0x1f')]],'as':_0x2cbfb3['as'],'attributes':_0x2cbfb3[_0x8bfe('0x1c')]};}):[]};}):[]};}):[]:[]})[_0x8bfe('0xf')](function(_0x597651){logger[_0x8bfe('0x10')](_0x8bfe('0x21'),_0xbc7fa2);logger['debug'](_0x8bfe('0x21'),_0xbc7fa2,JSON[_0x8bfe('0x22')](_0x597651));_0x2e64ee(_0x597651);})[_0x8bfe('0x19')](function(_0x5259ec){logger[_0x8bfe('0x14')](_0x8bfe('0x21'),_0x5259ec['message'],_0xbc7fa2);_0x3f8050(_0x5442e1['error'](0x1f4,_0x5259ec[_0x8bfe('0x17')]));});});};