ba8106b7ecb8a8896535cc940ac9e27ff587f6b1
[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 _0x581f=['CDR(type)=%s','chanspy','record','push','merge','MixMonitor','recordingFormat','auth','password','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','internal','User','then','catch','exports','define','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','util','./voiceChanSpy.attributes','context','format','%s%s','prefix'];(function(_0x2fc01b,_0xb41dec){var _0x29cf32=function(_0x568e27){while(--_0x568e27){_0x2fc01b['push'](_0x2fc01b['shift']());}};_0x29cf32(++_0xb41dec);}(_0x581f,0x109));var _0xf581=function(_0x26537e,_0x3f58f1){_0x26537e=_0x26537e-0x0;var _0x386f53=_0x581f[_0x26537e];return _0x386f53;};'use strict';var _=require(_0xf581('0x0'));var util=require(_0xf581('0x1'));var BPromise=require('bluebird');var attributes=require(_0xf581('0x2'));var getUserApplications=function(_0x24913c,_0x2c6b49,_0x5df2e1){var _0x715b58=0x1;var _0x4969b2=[];var _0x45ba63={'context':_0x2c6b49[_0xf581('0x3')]||'from-sip','exten':util[_0xf581('0x4')](_0xf581('0x5'),_0x24913c[_0xf581('0x6')],_0x5df2e1),'type':'system','isApp':![],'ChanSpyId':_0x24913c['id'],'UserId':_0x2c6b49['id']};_0x4969b2['push'](_['merge']({'app':'Set','appdata':util[_0xf581('0x4')](_0xf581('0x7'),_0xf581('0x8')),'priority':_0x715b58++},_0x45ba63));if(_0x24913c[_0xf581('0x9')]){_0x4969b2[_0xf581('0xa')](_[_0xf581('0xb')]({'app':_0xf581('0xc'),'appdata':util['format']('${UNIQUEID}.%s,a',_0x24913c[_0xf581('0xd')]),'priority':_0x715b58++},_0x45ba63));}if(_0x24913c[_0xf581('0xe')]){_0x4969b2['push'](_[_0xf581('0xb')]({'app':'Authenticate','appdata':_0x24913c[_0xf581('0xf')],'priority':_0x715b58++},_0x45ba63));}_0x4969b2[_0xf581('0xa')](_['merge']({'app':_0xf581('0x10'),'appdata':util[_0xf581('0x4')](_0xf581('0x11'),_0x2c6b49[_0xf581('0x12')],_0x24913c[_0xf581('0x13')]?_0x24913c[_0xf581('0x13')][_0xf581('0x14')](''):''),'priority':_0x715b58++},_0x45ba63));if(_0x24913c[_0xf581('0x9')]){_0x4969b2[_0xf581('0xa')](_[_0xf581('0xb')]({'app':_0xf581('0x15'),'priority':_0x715b58++},_0x45ba63));}return _0x4969b2;};var getChanSpyApplications=function(_0x3da0de,_0x3d0a39){var _0x98da16=[];for(var _0x1b5621=0x0,_0x7852f=0x1;_0x1b5621<_0x3d0a39[_0xf581('0x16')];_0x1b5621++,_0x7852f=0x1){_0x98da16=_0x98da16[_0xf581('0x17')](getUserApplications(_0x3da0de,_0x3d0a39[_0x1b5621],_0x3d0a39[_0x1b5621][_0xf581('0x18')]));if(_0x3d0a39[_0x1b5621][_0xf581('0x18')]!=_0x3d0a39[_0x1b5621][_0xf581('0x12')]){_0x98da16=_0x98da16[_0xf581('0x17')](getUserApplications(_0x3da0de,_0x3d0a39[_0x1b5621],_0x3d0a39[_0x1b5621][_0xf581('0x12')]));}}return _0x98da16;};var getChanSpyPromise=function(_0x5f1147,_0x568511){return new BPromise(function(_0x56b319,_0x5fc166){return _0x5f1147[_0xf581('0x19')]['findAll']({'attributes':['id',_0xf581('0x12'),'internal'],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0xf581('0x1a')](function(_0x2198ae){if(_0x2198ae){return _0x56b319(getChanSpyApplications(_0x568511,_0x2198ae));}return _0x56b319([]);})[_0xf581('0x1b')](function(_0x81fc4d){_0x5fc166(_0x81fc4d);});});};module[_0xf581('0x1c')]=function(_0xb918cc,_0x135435){var _0x55fd5c=_0xb918cc['models'];return _0xb918cc[_0xf581('0x1d')]('VoiceChanSpy',attributes,{'tableName':_0xf581('0x1e'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x3e00b1,_0x334331,_0x7a1fe1){return getChanSpyPromise(_0x55fd5c,_0x3e00b1)[_0xf581('0x1a')](function(_0x58661c){if(_0x58661c&&_0x58661c[_0xf581('0x16')]){return _0x55fd5c[_0xf581('0x1f')][_0xf581('0x20')](_0x58661c);}})[_0xf581('0x1a')](function(){_0x7a1fe1();})[_0xf581('0x1b')](function(_0x2462ea){_0x7a1fe1(_0x2462ea);});},'afterUpdate':function(_0x540747,_0x570569,_0x17e025){return _0x55fd5c[_0xf581('0x1f')][_0xf581('0x21')]({'where':{'ChanSpyId':_0x540747['id']}})[_0xf581('0x1a')](function(){return getChanSpyPromise(_0x55fd5c,_0x540747);})['then'](function(_0x41421f){if(_0x41421f&&_0x41421f[_0xf581('0x16')]){return _0x55fd5c['VoiceExtension'][_0xf581('0x20')](_0x41421f);}})[_0xf581('0x1a')](function(){_0x17e025();})[_0xf581('0x1b')](function(_0xb7fd28){_0x17e025(_0xb7fd28);});},'afterDestroy':function(_0x817c29,_0x27723d,_0x2c2ace){return _0x55fd5c['VoiceExtension'][_0xf581('0x21')]({'where':{'ChanSpyId':_0x817c29['id']}})[_0xf581('0x1a')](function(){_0x2c2ace();})['catch'](function(_0x359d06){_0x2c2ace(_0x359d06);});}}});};