Built motion from commit c116dc8b.|2.6.30
[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 _0xaece=['catch','destroy','util','bluebird','context','from-sip','format','%s%s','prefix','push','merge','CDR(type)=%s','chanspy','record','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','name','options','join','concat','internal','User','findAll','then','exports','VoiceChanSpy','voice_chanspy','length','VoiceExtension','bulkCreate'];(function(_0x19e35c,_0x29cd1e){var _0x3e1fe8=function(_0x17258b){while(--_0x17258b){_0x19e35c['push'](_0x19e35c['shift']());}};_0x3e1fe8(++_0x29cd1e);}(_0xaece,0x1bc));var _0xeaec=function(_0x17c84b,_0x214ee7){_0x17c84b=_0x17c84b-0x0;var _0x4870f5=_0xaece[_0x17c84b];return _0x4870f5;};'use strict';var _=require('lodash');var util=require(_0xeaec('0x0'));var BPromise=require(_0xeaec('0x1'));var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x2a9813,_0x4e04be,_0x447c06){var _0x25e4b0=0x1;var _0x2d1a41=[];var _0x23d100={'context':_0x4e04be[_0xeaec('0x2')]||_0xeaec('0x3'),'exten':util[_0xeaec('0x4')](_0xeaec('0x5'),_0x2a9813[_0xeaec('0x6')],_0x447c06),'type':'system','isApp':![],'ChanSpyId':_0x2a9813['id'],'UserId':_0x4e04be['id']};_0x2d1a41[_0xeaec('0x7')](_[_0xeaec('0x8')]({'app':'Set','appdata':util['format'](_0xeaec('0x9'),_0xeaec('0xa')),'priority':_0x25e4b0++},_0x23d100));if(_0x2a9813[_0xeaec('0xb')]){_0x2d1a41[_0xeaec('0x7')](_[_0xeaec('0x8')]({'app':'MixMonitor','appdata':util['format'](_0xeaec('0xc'),_0x2a9813[_0xeaec('0xd')]),'priority':_0x25e4b0++},_0x23d100));}if(_0x2a9813[_0xeaec('0xe')]){_0x2d1a41['push'](_[_0xeaec('0x8')]({'app':_0xeaec('0xf'),'appdata':_0x2a9813[_0xeaec('0x10')],'priority':_0x25e4b0++},_0x23d100));}_0x2d1a41[_0xeaec('0x7')](_[_0xeaec('0x8')]({'app':_0xeaec('0x11'),'appdata':util[_0xeaec('0x4')]('SIP/%s,%s',_0x4e04be[_0xeaec('0x12')],_0x2a9813[_0xeaec('0x13')]?_0x2a9813[_0xeaec('0x13')][_0xeaec('0x14')](''):''),'priority':_0x25e4b0++},_0x23d100));if(_0x2a9813[_0xeaec('0xb')]){_0x2d1a41[_0xeaec('0x7')](_[_0xeaec('0x8')]({'app':'StopMixMonitor','priority':_0x25e4b0++},_0x23d100));}return _0x2d1a41;};var getChanSpyApplications=function(_0x39cb80,_0x423267){var _0xa62d4e=[];for(var _0x51a618=0x0,_0x4b1a18=0x1;_0x51a618<_0x423267['length'];_0x51a618++,_0x4b1a18=0x1){_0xa62d4e=_0xa62d4e[_0xeaec('0x15')](getUserApplications(_0x39cb80,_0x423267[_0x51a618],_0x423267[_0x51a618][_0xeaec('0x16')]));if(_0x423267[_0x51a618]['internal']!=_0x423267[_0x51a618][_0xeaec('0x12')]){_0xa62d4e=_0xa62d4e[_0xeaec('0x15')](getUserApplications(_0x39cb80,_0x423267[_0x51a618],_0x423267[_0x51a618][_0xeaec('0x12')]));}}return _0xa62d4e;};var getChanSpyPromise=function(_0x591625,_0x984b05){return new BPromise(function(_0x1d733e,_0x170176){return _0x591625[_0xeaec('0x17')][_0xeaec('0x18')]({'attributes':['id',_0xeaec('0x12'),_0xeaec('0x16')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0xeaec('0x19')](function(_0x3f3980){if(_0x3f3980){return _0x1d733e(getChanSpyApplications(_0x984b05,_0x3f3980));}return _0x1d733e([]);})['catch'](function(_0x104f4c){_0x170176(_0x104f4c);});});};module[_0xeaec('0x1a')]=function(_0x333be2,_0x576869){var _0x2d7853=_0x333be2['models'];return _0x333be2['define'](_0xeaec('0x1b'),attributes,{'tableName':_0xeaec('0x1c'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x122c6f,_0x1ce650,_0xf098e){return getChanSpyPromise(_0x2d7853,_0x122c6f)[_0xeaec('0x19')](function(_0x26953b){if(_0x26953b&&_0x26953b[_0xeaec('0x1d')]){return _0x2d7853[_0xeaec('0x1e')][_0xeaec('0x1f')](_0x26953b);}})[_0xeaec('0x19')](function(){_0xf098e();})[_0xeaec('0x20')](function(_0x40cd8b){_0xf098e(_0x40cd8b);});},'afterUpdate':function(_0x23449d,_0x3d849c,_0x35bde2){return _0x2d7853[_0xeaec('0x1e')]['destroy']({'where':{'ChanSpyId':_0x23449d['id']}})[_0xeaec('0x19')](function(){return getChanSpyPromise(_0x2d7853,_0x23449d);})[_0xeaec('0x19')](function(_0xa1cc25){if(_0xa1cc25&&_0xa1cc25[_0xeaec('0x1d')]){return _0x2d7853[_0xeaec('0x1e')][_0xeaec('0x1f')](_0xa1cc25);}})[_0xeaec('0x19')](function(){_0x35bde2();})[_0xeaec('0x20')](function(_0x135bff){_0x35bde2(_0x135bff);});},'afterDestroy':function(_0x9804ad,_0x4c5629,_0x49cea8){return _0x2d7853[_0xeaec('0x1e')][_0xeaec('0x21')]({'where':{'ChanSpyId':_0x9804ad['id']}})[_0xeaec('0x19')](function(){_0x49cea8();})[_0xeaec('0x20')](function(_0x3d1966){_0x49cea8(_0x3d1966);});}}});};