Built motion from commit (unavailable).|2.2.0
[motion2.git] / server / api / voiceChanSpy / voiceChanSpy.model.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 _0x4ce5=['then','catch','exports','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','util','bluebird','../../config/logger','api','./voiceChanSpy.attributes','%s%s','prefix','push','format','chanspy','record','merge','MixMonitor','${UNIQUEID}.%s,ab','recordingFormat','auth','password','ChanSpy','SIP/%s,%s','options','join','StopMixMonitor','length','internal','name','concat','User','findAll'];(function(_0x402c78,_0x4484c9){var _0x593215=function(_0x45d47c){while(--_0x45d47c){_0x402c78['push'](_0x402c78['shift']());}};_0x593215(++_0x4484c9);}(_0x4ce5,0x1d1));var _0x54ce=function(_0x93c8c3,_0x254c5e){_0x93c8c3=_0x93c8c3-0x0;var _0xc91013=_0x4ce5[_0x93c8c3];return _0xc91013;};'use strict';var _=require(_0x54ce('0x0'));var util=require(_0x54ce('0x1'));var BPromise=require(_0x54ce('0x2'));var logger=require(_0x54ce('0x3'))(_0x54ce('0x4'));var attributes=require(_0x54ce('0x5'));var getUserApplications=function(_0x806403,_0x40c3b5,_0x1b050f){var _0x113817=0x1;var _0xa0ecc3=[];var _0x2ccb17={'context':'from-sip','type':'system','isApp':![]};var _0x291728={'exten':util['format'](_0x54ce('0x6'),_0x806403[_0x54ce('0x7')],_0x1b050f),'ChanSpyId':_0x806403['id'],'UserId':_0x40c3b5['id']};_0xa0ecc3[_0x54ce('0x8')](_['merge']({'app':'Set','appdata':util[_0x54ce('0x9')]('CDR(type)=%s',_0x54ce('0xa')),'priority':_0x113817++},_0x2ccb17,_0x291728));if(_0x806403[_0x54ce('0xb')]){_0xa0ecc3[_0x54ce('0x8')](_[_0x54ce('0xc')]({'app':_0x54ce('0xd'),'appdata':util[_0x54ce('0x9')](_0x54ce('0xe'),_0x806403[_0x54ce('0xf')]),'priority':_0x113817++},_0x2ccb17,_0x291728));}if(_0x806403[_0x54ce('0x10')]){_0xa0ecc3[_0x54ce('0x8')](_[_0x54ce('0xc')]({'app':'Authenticate','appdata':_0x806403[_0x54ce('0x11')],'priority':_0x113817++},_0x2ccb17,_0x291728));}_0xa0ecc3['push'](_['merge']({'app':_0x54ce('0x12'),'appdata':util[_0x54ce('0x9')](_0x54ce('0x13'),_0x40c3b5['name'],_0x806403[_0x54ce('0x14')]?_0x806403[_0x54ce('0x14')][_0x54ce('0x15')](''):''),'priority':_0x113817++},_0x2ccb17,_0x291728));if(_0x806403['record']){_0xa0ecc3['push'](_['merge']({'app':_0x54ce('0x16'),'priority':_0x113817++},_0x2ccb17,_0x291728));}return _0xa0ecc3;};var getChanSpyApplications=function(_0x42aa2a,_0x2304bf){var _0x2db70b=[];for(var _0x354c5f=0x0,_0x38d0c2=0x1;_0x354c5f<_0x2304bf[_0x54ce('0x17')];_0x354c5f++,_0x38d0c2=0x1){var _0x15b471=getUserApplications(_0x42aa2a,_0x2304bf[_0x354c5f],_0x2304bf[_0x354c5f][_0x54ce('0x18')]);var _0xcfe22a=getUserApplications(_0x42aa2a,_0x2304bf[_0x354c5f],_0x2304bf[_0x354c5f][_0x54ce('0x19')]);_0x2db70b=_0x2db70b[_0x54ce('0x1a')](_0x15b471,_0xcfe22a);}return _0x2db70b;};var getChanSpyPromise=function(_0x23b684,_0x23fffa){return new BPromise(function(_0x282e9c,_0x5616c4){return _0x23b684[_0x54ce('0x1b')][_0x54ce('0x1c')]({'attributes':['id',_0x54ce('0x19'),_0x54ce('0x18')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0x54ce('0x1d')](function(_0x3b52ff){if(_0x3b52ff){return _0x282e9c(getChanSpyApplications(_0x23fffa,_0x3b52ff));}return _0x282e9c([]);})[_0x54ce('0x1e')](function(_0x356a9c){_0x5616c4(_0x356a9c);});});};module[_0x54ce('0x1f')]=function(_0x2b683b,_0x4a8fde){var _0x32ac72=_0x2b683b['models'];return _0x2b683b[_0x54ce('0x20')](_0x54ce('0x21'),attributes,{'tableName':_0x54ce('0x22'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x522f2e,_0x5d4a8f,_0x568015){return getChanSpyPromise(_0x32ac72,_0x522f2e)['then'](function(_0xbdeb1b){if(_0xbdeb1b&&_0xbdeb1b[_0x54ce('0x17')]){return _0x32ac72[_0x54ce('0x23')][_0x54ce('0x24')](_0xbdeb1b);}})['then'](function(){_0x568015();})[_0x54ce('0x1e')](function(_0x47ea93){_0x568015(_0x47ea93);});},'afterUpdate':function(_0x4422b6,_0x3fa1dc,_0x11a5cb){return _0x32ac72[_0x54ce('0x23')][_0x54ce('0x25')]({'where':{'ChanSpyId':_0x4422b6['id']}})[_0x54ce('0x1d')](function(){return getChanSpyPromise(_0x32ac72,_0x4422b6);})[_0x54ce('0x1d')](function(_0x54cc88){if(_0x54cc88&&_0x54cc88[_0x54ce('0x17')]){return _0x32ac72[_0x54ce('0x23')][_0x54ce('0x24')](_0x54cc88);}})[_0x54ce('0x1d')](function(){_0x11a5cb();})[_0x54ce('0x1e')](function(_0x266b05){_0x11a5cb(_0x266b05);});},'afterDestroy':function(_0x11b492,_0x21e267,_0x35801d){return _0x32ac72[_0x54ce('0x23')]['destroy']({'where':{'ChanSpyId':_0x11b492['id']}})[_0x54ce('0x1d')](function(){_0x35801d();})[_0x54ce('0x1e')](function(_0x26c153){_0x35801d(_0x26c153);});}}});};