604e42e6d77dff77d9a8534843ec62c01f49f5aa
[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 _0x53b8=['models','define','voice_chanspy','then','VoiceExtension','catch','destroy','bluebird','./voiceChanSpy.attributes','from-sip','%s%s','prefix','push','merge','Set','format','CDR(type)=%s','record','MixMonitor','${UNIQUEID}.%s,a','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','internal','User','exports'];(function(_0x147392,_0xd07058){var _0x412995=function(_0x214443){while(--_0x214443){_0x147392['push'](_0x147392['shift']());}};_0x412995(++_0xd07058);}(_0x53b8,0xf5));var _0x853b=function(_0x4b369d,_0x265eb8){_0x4b369d=_0x4b369d-0x0;var _0x571a98=_0x53b8[_0x4b369d];return _0x571a98;};'use strict';var _=require('lodash');var util=require('util');var BPromise=require(_0x853b('0x0'));var attributes=require(_0x853b('0x1'));var getUserApplications=function(_0x5c2513,_0x3d701d,_0x5a5a3a){var _0x75557e=0x1;var _0xcde032=[];var _0x1cfe2d={'context':_0x3d701d['context']||_0x853b('0x2'),'exten':util['format'](_0x853b('0x3'),_0x5c2513[_0x853b('0x4')],_0x5a5a3a),'type':'system','isApp':![],'ChanSpyId':_0x5c2513['id'],'UserId':_0x3d701d['id']};_0xcde032[_0x853b('0x5')](_[_0x853b('0x6')]({'app':_0x853b('0x7'),'appdata':util[_0x853b('0x8')](_0x853b('0x9'),'chanspy'),'priority':_0x75557e++},_0x1cfe2d));if(_0x5c2513[_0x853b('0xa')]){_0xcde032['push'](_['merge']({'app':_0x853b('0xb'),'appdata':util['format'](_0x853b('0xc'),_0x5c2513['recordingFormat']),'priority':_0x75557e++},_0x1cfe2d));}if(_0x5c2513[_0x853b('0xd')]){_0xcde032[_0x853b('0x5')](_[_0x853b('0x6')]({'app':_0x853b('0xe'),'appdata':_0x5c2513[_0x853b('0xf')],'priority':_0x75557e++},_0x1cfe2d));}_0xcde032[_0x853b('0x5')](_[_0x853b('0x6')]({'app':_0x853b('0x10'),'appdata':util['format'](_0x853b('0x11'),_0x3d701d[_0x853b('0x12')],_0x5c2513[_0x853b('0x13')]?_0x5c2513['options'][_0x853b('0x14')](''):''),'priority':_0x75557e++},_0x1cfe2d));if(_0x5c2513['record']){_0xcde032[_0x853b('0x5')](_['merge']({'app':_0x853b('0x15'),'priority':_0x75557e++},_0x1cfe2d));}return _0xcde032;};var getChanSpyApplications=function(_0x5182c0,_0x4e3271){var _0x86f460=[];for(var _0x19fe67=0x0,_0x9da70c=0x1;_0x19fe67<_0x4e3271[_0x853b('0x16')];_0x19fe67++,_0x9da70c=0x1){_0x86f460=_0x86f460[_0x853b('0x17')](getUserApplications(_0x5182c0,_0x4e3271[_0x19fe67],_0x4e3271[_0x19fe67][_0x853b('0x18')]));if(_0x4e3271[_0x19fe67]['internal']!=_0x4e3271[_0x19fe67]['name']){_0x86f460=_0x86f460[_0x853b('0x17')](getUserApplications(_0x5182c0,_0x4e3271[_0x19fe67],_0x4e3271[_0x19fe67][_0x853b('0x12')]));}}return _0x86f460;};var getChanSpyPromise=function(_0x3ae471,_0x4a2836){return new BPromise(function(_0x333db5,_0x4a0c4d){return _0x3ae471[_0x853b('0x19')]['findAll']({'attributes':['id',_0x853b('0x12'),'internal'],'where':{'role':'agent','chanspy':!![]},'raw':!![]})['then'](function(_0x3149e8){if(_0x3149e8){return _0x333db5(getChanSpyApplications(_0x4a2836,_0x3149e8));}return _0x333db5([]);})['catch'](function(_0x1da5c1){_0x4a0c4d(_0x1da5c1);});});};module[_0x853b('0x1a')]=function(_0x1d18fa,_0x2d491e){var _0x5391c2=_0x1d18fa[_0x853b('0x1b')];return _0x1d18fa[_0x853b('0x1c')]('VoiceChanSpy',attributes,{'tableName':_0x853b('0x1d'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x485a3c,_0x913a07,_0x548b3c){return getChanSpyPromise(_0x5391c2,_0x485a3c)[_0x853b('0x1e')](function(_0x37f350){if(_0x37f350&&_0x37f350[_0x853b('0x16')]){return _0x5391c2[_0x853b('0x1f')]['bulkCreate'](_0x37f350);}})[_0x853b('0x1e')](function(){_0x548b3c();})[_0x853b('0x20')](function(_0x3e1224){_0x548b3c(_0x3e1224);});},'afterUpdate':function(_0xcb38c3,_0x4298eb,_0x2d46b0){return _0x5391c2['VoiceExtension'][_0x853b('0x21')]({'where':{'ChanSpyId':_0xcb38c3['id']}})[_0x853b('0x1e')](function(){return getChanSpyPromise(_0x5391c2,_0xcb38c3);})[_0x853b('0x1e')](function(_0x310c7f){if(_0x310c7f&&_0x310c7f[_0x853b('0x16')]){return _0x5391c2[_0x853b('0x1f')]['bulkCreate'](_0x310c7f);}})[_0x853b('0x1e')](function(){_0x2d46b0();})['catch'](function(_0x50db21){_0x2d46b0(_0x50db21);});},'afterDestroy':function(_0x5cd046,_0x2e9a9e,_0x452adf){return _0x5391c2[_0x853b('0x1f')][_0x853b('0x21')]({'where':{'ChanSpyId':_0x5cd046['id']}})[_0x853b('0x1e')](function(){_0x452adf();})[_0x853b('0x20')](function(_0xe6facf){_0x452adf(_0xe6facf);});}}});};