13c3b6760fb89f685119af526129d1b336596078
[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 _0xe592=['VoiceChanSpy','voice_chanspy','catch','VoiceExtension','destroy','bulkCreate','lodash','bluebird','./voiceChanSpy.attributes','from-sip','format','%s%s','system','CDR(type)=%s','chanspy','record','push','${UNIQUEID}.%s,a','auth','Authenticate','password','merge','SIP/%s,%s','options','StopMixMonitor','length','concat','internal','name','User','findAll','agent','then','models','define'];(function(_0x1589dd,_0x2b9d22){var _0x1bddd1=function(_0x3687f8){while(--_0x3687f8){_0x1589dd['push'](_0x1589dd['shift']());}};_0x1bddd1(++_0x2b9d22);}(_0xe592,0xfb));var _0x2e59=function(_0x2c7618,_0x26be9c){_0x2c7618=_0x2c7618-0x0;var _0x5ce3f0=_0xe592[_0x2c7618];return _0x5ce3f0;};'use strict';var _=require(_0x2e59('0x0'));var util=require('util');var BPromise=require(_0x2e59('0x1'));var attributes=require(_0x2e59('0x2'));var getUserApplications=function(_0x524ba8,_0x1d0e5d,_0x6937e6){var _0x2e6273=0x1;var _0x3f18c1=[];var _0x4a3cb1={'context':_0x1d0e5d['context']||_0x2e59('0x3'),'exten':util[_0x2e59('0x4')](_0x2e59('0x5'),_0x524ba8['prefix'],_0x6937e6),'type':_0x2e59('0x6'),'isApp':![],'ChanSpyId':_0x524ba8['id'],'UserId':_0x1d0e5d['id']};_0x3f18c1['push'](_['merge']({'app':'Set','appdata':util['format'](_0x2e59('0x7'),_0x2e59('0x8')),'priority':_0x2e6273++},_0x4a3cb1));if(_0x524ba8[_0x2e59('0x9')]){_0x3f18c1[_0x2e59('0xa')](_['merge']({'app':'MixMonitor','appdata':util[_0x2e59('0x4')](_0x2e59('0xb'),_0x524ba8['recordingFormat']),'priority':_0x2e6273++},_0x4a3cb1));}if(_0x524ba8[_0x2e59('0xc')]){_0x3f18c1[_0x2e59('0xa')](_['merge']({'app':_0x2e59('0xd'),'appdata':_0x524ba8[_0x2e59('0xe')],'priority':_0x2e6273++},_0x4a3cb1));}_0x3f18c1[_0x2e59('0xa')](_[_0x2e59('0xf')]({'app':'ChanSpy','appdata':util['format'](_0x2e59('0x10'),_0x1d0e5d['name'],_0x524ba8[_0x2e59('0x11')]?_0x524ba8['options']['join'](''):''),'priority':_0x2e6273++},_0x4a3cb1));if(_0x524ba8[_0x2e59('0x9')]){_0x3f18c1[_0x2e59('0xa')](_[_0x2e59('0xf')]({'app':_0x2e59('0x12'),'priority':_0x2e6273++},_0x4a3cb1));}return _0x3f18c1;};var getChanSpyApplications=function(_0x1d301a,_0x1100b0){var _0x3f1a76=[];for(var _0x1ddd82=0x0,_0x40009a=0x1;_0x1ddd82<_0x1100b0[_0x2e59('0x13')];_0x1ddd82++,_0x40009a=0x1){_0x3f1a76=_0x3f1a76[_0x2e59('0x14')](getUserApplications(_0x1d301a,_0x1100b0[_0x1ddd82],_0x1100b0[_0x1ddd82][_0x2e59('0x15')]));if(_0x1100b0[_0x1ddd82][_0x2e59('0x15')]!=_0x1100b0[_0x1ddd82][_0x2e59('0x16')]){_0x3f1a76=_0x3f1a76[_0x2e59('0x14')](getUserApplications(_0x1d301a,_0x1100b0[_0x1ddd82],_0x1100b0[_0x1ddd82]['name']));}}return _0x3f1a76;};var getChanSpyPromise=function(_0x7bd9dd,_0x39681d){return new BPromise(function(_0x1d7ed8,_0x42eaaf){return _0x7bd9dd[_0x2e59('0x17')][_0x2e59('0x18')]({'attributes':['id',_0x2e59('0x16'),_0x2e59('0x15')],'where':{'role':_0x2e59('0x19'),'chanspy':!![]},'raw':!![]})[_0x2e59('0x1a')](function(_0x5d5d38){if(_0x5d5d38){return _0x1d7ed8(getChanSpyApplications(_0x39681d,_0x5d5d38));}return _0x1d7ed8([]);})['catch'](function(_0x35003f){_0x42eaaf(_0x35003f);});});};module['exports']=function(_0xda871,_0x40d247){var _0x5afa97=_0xda871[_0x2e59('0x1b')];return _0xda871[_0x2e59('0x1c')](_0x2e59('0x1d'),attributes,{'tableName':_0x2e59('0x1e'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0xddeeae,_0x2d24e2,_0x369bf3){return getChanSpyPromise(_0x5afa97,_0xddeeae)[_0x2e59('0x1a')](function(_0x35b8f8){if(_0x35b8f8&&_0x35b8f8['length']){return _0x5afa97['VoiceExtension']['bulkCreate'](_0x35b8f8);}})[_0x2e59('0x1a')](function(){_0x369bf3();})[_0x2e59('0x1f')](function(_0x194d73){_0x369bf3(_0x194d73);});},'afterUpdate':function(_0x4b26b0,_0x496f5b,_0xcfe418){return _0x5afa97[_0x2e59('0x20')][_0x2e59('0x21')]({'where':{'ChanSpyId':_0x4b26b0['id']}})['then'](function(){return getChanSpyPromise(_0x5afa97,_0x4b26b0);})[_0x2e59('0x1a')](function(_0x5954d3){if(_0x5954d3&&_0x5954d3[_0x2e59('0x13')]){return _0x5afa97['VoiceExtension'][_0x2e59('0x22')](_0x5954d3);}})[_0x2e59('0x1a')](function(){_0xcfe418();})[_0x2e59('0x1f')](function(_0x3995fb){_0xcfe418(_0x3995fb);});},'afterDestroy':function(_0x3a317d,_0x177139,_0x4a5ba7){return _0x5afa97['VoiceExtension'][_0x2e59('0x21')]({'where':{'ChanSpyId':_0x3a317d['id']}})[_0x2e59('0x1a')](function(){_0x4a5ba7();})['catch'](function(_0x195dc5){_0x4a5ba7(_0x195dc5);});}}});};