Built motion from commit 20b39a97.|2.6.29
[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 _0x0fc7=['system','push','Set','CDR(type)=%s','chanspy','record','merge','MixMonitor','recordingFormat','auth','Authenticate','password','name','join','StopMixMonitor','length','concat','User','internal','then','catch','exports','models','define','VoiceChanSpy','VoiceExtension','destroy','lodash','util','context','from-sip','format','%s%s','prefix'];(function(_0x30a5cf,_0x4e90b2){var _0x5a7245=function(_0x3605b0){while(--_0x3605b0){_0x30a5cf['push'](_0x30a5cf['shift']());}};_0x5a7245(++_0x4e90b2);}(_0x0fc7,0x12b));var _0x70fc=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x0fc7[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x70fc('0x0'));var util=require(_0x70fc('0x1'));var BPromise=require('bluebird');var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0xae5939,_0x57aea9,_0x65f20e){var _0x55432c=0x1;var _0x311fc3=[];var _0x5a8e96={'context':_0x57aea9[_0x70fc('0x2')]||_0x70fc('0x3'),'exten':util[_0x70fc('0x4')](_0x70fc('0x5'),_0xae5939[_0x70fc('0x6')],_0x65f20e),'type':_0x70fc('0x7'),'isApp':![],'ChanSpyId':_0xae5939['id'],'UserId':_0x57aea9['id']};_0x311fc3[_0x70fc('0x8')](_['merge']({'app':_0x70fc('0x9'),'appdata':util[_0x70fc('0x4')](_0x70fc('0xa'),_0x70fc('0xb')),'priority':_0x55432c++},_0x5a8e96));if(_0xae5939[_0x70fc('0xc')]){_0x311fc3[_0x70fc('0x8')](_[_0x70fc('0xd')]({'app':_0x70fc('0xe'),'appdata':util[_0x70fc('0x4')]('${UNIQUEID}.%s,a',_0xae5939[_0x70fc('0xf')]),'priority':_0x55432c++},_0x5a8e96));}if(_0xae5939[_0x70fc('0x10')]){_0x311fc3['push'](_[_0x70fc('0xd')]({'app':_0x70fc('0x11'),'appdata':_0xae5939[_0x70fc('0x12')],'priority':_0x55432c++},_0x5a8e96));}_0x311fc3[_0x70fc('0x8')](_['merge']({'app':'ChanSpy','appdata':util[_0x70fc('0x4')]('SIP/%s,%s',_0x57aea9[_0x70fc('0x13')],_0xae5939['options']?_0xae5939['options'][_0x70fc('0x14')](''):''),'priority':_0x55432c++},_0x5a8e96));if(_0xae5939[_0x70fc('0xc')]){_0x311fc3[_0x70fc('0x8')](_[_0x70fc('0xd')]({'app':_0x70fc('0x15'),'priority':_0x55432c++},_0x5a8e96));}return _0x311fc3;};var getChanSpyApplications=function(_0x416544,_0x19eef8){var _0x3e62a5=[];for(var _0x20b999=0x0,_0xf3f9d1=0x1;_0x20b999<_0x19eef8[_0x70fc('0x16')];_0x20b999++,_0xf3f9d1=0x1){_0x3e62a5=_0x3e62a5[_0x70fc('0x17')](getUserApplications(_0x416544,_0x19eef8[_0x20b999],_0x19eef8[_0x20b999]['internal']));if(_0x19eef8[_0x20b999]['internal']!=_0x19eef8[_0x20b999]['name']){_0x3e62a5=_0x3e62a5[_0x70fc('0x17')](getUserApplications(_0x416544,_0x19eef8[_0x20b999],_0x19eef8[_0x20b999][_0x70fc('0x13')]));}}return _0x3e62a5;};var getChanSpyPromise=function(_0x30fd3c,_0x2a8256){return new BPromise(function(_0x5b38a4,_0x19675b){return _0x30fd3c[_0x70fc('0x18')]['findAll']({'attributes':['id',_0x70fc('0x13'),_0x70fc('0x19')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0x70fc('0x1a')](function(_0x2e71ca){if(_0x2e71ca){return _0x5b38a4(getChanSpyApplications(_0x2a8256,_0x2e71ca));}return _0x5b38a4([]);})[_0x70fc('0x1b')](function(_0x30ee52){_0x19675b(_0x30ee52);});});};module[_0x70fc('0x1c')]=function(_0x2c06a4,_0x5a186e){var _0x43e26f=_0x2c06a4[_0x70fc('0x1d')];return _0x2c06a4[_0x70fc('0x1e')](_0x70fc('0x1f'),attributes,{'tableName':'voice_chanspy','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0xdcc414,_0x460743,_0x4361e6){return getChanSpyPromise(_0x43e26f,_0xdcc414)[_0x70fc('0x1a')](function(_0x4a660e){if(_0x4a660e&&_0x4a660e[_0x70fc('0x16')]){return _0x43e26f[_0x70fc('0x20')]['bulkCreate'](_0x4a660e);}})[_0x70fc('0x1a')](function(){_0x4361e6();})[_0x70fc('0x1b')](function(_0x3420d1){_0x4361e6(_0x3420d1);});},'afterUpdate':function(_0x18c94c,_0xf3904a,_0x362b4a){return _0x43e26f['VoiceExtension'][_0x70fc('0x21')]({'where':{'ChanSpyId':_0x18c94c['id']}})[_0x70fc('0x1a')](function(){return getChanSpyPromise(_0x43e26f,_0x18c94c);})[_0x70fc('0x1a')](function(_0x43616f){if(_0x43616f&&_0x43616f[_0x70fc('0x16')]){return _0x43e26f[_0x70fc('0x20')]['bulkCreate'](_0x43616f);}})[_0x70fc('0x1a')](function(){_0x362b4a();})[_0x70fc('0x1b')](function(_0x10881e){_0x362b4a(_0x10881e);});},'afterDestroy':function(_0x4ae848,_0x5df30d,_0x47bb31){return _0x43e26f[_0x70fc('0x20')][_0x70fc('0x21')]({'where':{'ChanSpyId':_0x4ae848['id']}})[_0x70fc('0x1a')](function(){_0x47bb31();})[_0x70fc('0x1b')](function(_0x310886){_0x47bb31(_0x310886);});}}});};