39f51ad056d4e9287a9f9f2cbbc70d9e120688a6
[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 _0x32b2=['push','Set','format','chanspy','record','merge','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','password','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','concat','User','internal','agent','then','models','define','VoiceChanSpy','voice_chanspy','length','VoiceExtension','bulkCreate','catch','destroy','./voiceChanSpy.attributes','context','from-sip','%s%s','prefix','system'];(function(_0x5783f4,_0x4a9e0a){var _0x28e380=function(_0x1ffc49){while(--_0x1ffc49){_0x5783f4['push'](_0x5783f4['shift']());}};_0x28e380(++_0x4a9e0a);}(_0x32b2,0x66));var _0x232b=function(_0x64b6e,_0x391478){_0x64b6e=_0x64b6e-0x0;var _0x5d4448=_0x32b2[_0x64b6e];return _0x5d4448;};'use strict';var _=require('lodash');var util=require('util');var BPromise=require('bluebird');var attributes=require(_0x232b('0x0'));var getUserApplications=function(_0x487fb1,_0x53e524,_0x2ac63b){var _0x2dcca8=0x1;var _0x4d90b3=[];var _0x231503={'context':_0x53e524[_0x232b('0x1')]||_0x232b('0x2'),'exten':util['format'](_0x232b('0x3'),_0x487fb1[_0x232b('0x4')],_0x2ac63b),'type':_0x232b('0x5'),'isApp':![],'ChanSpyId':_0x487fb1['id'],'UserId':_0x53e524['id']};_0x4d90b3[_0x232b('0x6')](_['merge']({'app':_0x232b('0x7'),'appdata':util[_0x232b('0x8')]('CDR(type)=%s',_0x232b('0x9')),'priority':_0x2dcca8++},_0x231503));if(_0x487fb1[_0x232b('0xa')]){_0x4d90b3['push'](_[_0x232b('0xb')]({'app':_0x232b('0xc'),'appdata':util[_0x232b('0x8')](_0x232b('0xd'),_0x487fb1[_0x232b('0xe')]),'priority':_0x2dcca8++},_0x231503));}if(_0x487fb1['auth']){_0x4d90b3[_0x232b('0x6')](_['merge']({'app':'Authenticate','appdata':_0x487fb1[_0x232b('0xf')],'priority':_0x2dcca8++},_0x231503));}_0x4d90b3[_0x232b('0x6')](_['merge']({'app':_0x232b('0x10'),'appdata':util[_0x232b('0x8')](_0x232b('0x11'),_0x53e524[_0x232b('0x12')],_0x487fb1[_0x232b('0x13')]?_0x487fb1[_0x232b('0x13')][_0x232b('0x14')](''):''),'priority':_0x2dcca8++},_0x231503));if(_0x487fb1[_0x232b('0xa')]){_0x4d90b3[_0x232b('0x6')](_[_0x232b('0xb')]({'app':_0x232b('0x15'),'priority':_0x2dcca8++},_0x231503));}return _0x4d90b3;};var getChanSpyApplications=function(_0x35f1eb,_0x56b28f){var _0xc5f5d7=[];for(var _0x2e8a51=0x0,_0x436530=0x1;_0x2e8a51<_0x56b28f['length'];_0x2e8a51++,_0x436530=0x1){_0xc5f5d7=_0xc5f5d7[_0x232b('0x16')](getUserApplications(_0x35f1eb,_0x56b28f[_0x2e8a51],_0x56b28f[_0x2e8a51]['internal']));if(_0x56b28f[_0x2e8a51]['internal']!=_0x56b28f[_0x2e8a51][_0x232b('0x12')]){_0xc5f5d7=_0xc5f5d7[_0x232b('0x16')](getUserApplications(_0x35f1eb,_0x56b28f[_0x2e8a51],_0x56b28f[_0x2e8a51][_0x232b('0x12')]));}}return _0xc5f5d7;};var getChanSpyPromise=function(_0x113be5,_0x15384e){return new BPromise(function(_0x50baa5,_0x10b93f){return _0x113be5[_0x232b('0x17')]['findAll']({'attributes':['id',_0x232b('0x12'),_0x232b('0x18')],'where':{'role':_0x232b('0x19'),'chanspy':!![]},'raw':!![]})[_0x232b('0x1a')](function(_0x200dc2){if(_0x200dc2){return _0x50baa5(getChanSpyApplications(_0x15384e,_0x200dc2));}return _0x50baa5([]);})['catch'](function(_0x3f1f44){_0x10b93f(_0x3f1f44);});});};module['exports']=function(_0x2d50f6,_0x418ced){var _0x61c55f=_0x2d50f6[_0x232b('0x1b')];return _0x2d50f6[_0x232b('0x1c')](_0x232b('0x1d'),attributes,{'tableName':_0x232b('0x1e'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x2e908f,_0x12298f,_0x394bb4){return getChanSpyPromise(_0x61c55f,_0x2e908f)[_0x232b('0x1a')](function(_0x51bf41){if(_0x51bf41&&_0x51bf41[_0x232b('0x1f')]){return _0x61c55f[_0x232b('0x20')][_0x232b('0x21')](_0x51bf41);}})['then'](function(){_0x394bb4();})[_0x232b('0x22')](function(_0x396ca8){_0x394bb4(_0x396ca8);});},'afterUpdate':function(_0x2ad70f,_0x50bb91,_0x34bb9c){return _0x61c55f[_0x232b('0x20')][_0x232b('0x23')]({'where':{'ChanSpyId':_0x2ad70f['id']}})[_0x232b('0x1a')](function(){return getChanSpyPromise(_0x61c55f,_0x2ad70f);})['then'](function(_0x40ec67){if(_0x40ec67&&_0x40ec67[_0x232b('0x1f')]){return _0x61c55f[_0x232b('0x20')][_0x232b('0x21')](_0x40ec67);}})['then'](function(){_0x34bb9c();})[_0x232b('0x22')](function(_0x3da8d9){_0x34bb9c(_0x3da8d9);});},'afterDestroy':function(_0x40776b,_0x120d18,_0x1be76f){return _0x61c55f[_0x232b('0x20')]['destroy']({'where':{'ChanSpyId':_0x40776b['id']}})[_0x232b('0x1a')](function(){_0x1be76f();})['catch'](function(_0x403f75){_0x1be76f(_0x403f75);});}}});};