Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / cmHopperAdditionalPhone / cmHopperAdditionalPhone.controller.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 _0x83f4=['../../mysqldb','status','offset','limit','undefined','count','set','Content-Range','json','apply','reject','update','then','destroy','CmHopperAdditionalPhones','UserProfileResource','end','sendStatus','error','stack','name','send','map','CmHopperAdditionalPhone','rawAttributes','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','order','pick','filter','merge','where','VIRTUAL','options','includeAll','findAll','rows','show','keys','include','catch','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','rimraf','fast-json-patch','request-promise','moment','util','path','to-csv','ejs','fs-extra','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x83f4,0x134));var _0x483f=function(_0x37c003,_0x190644){_0x37c003=_0x37c003-0x0;var _0x1449f6=_0x83f4[_0x37c003];return _0x1449f6;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x483f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x483f('0x1'));var rp=require(_0x483f('0x2'));var moment=require(_0x483f('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x483f('0x4'));var path=require(_0x483f('0x5'));var sox=require('sox');var csv=require(_0x483f('0x6'));var ejs=require(_0x483f('0x7'));var fs=require('fs');var fs_extra=require(_0x483f('0x8'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x483f('0x9'));var jsforce=require('jsforce');var deskjs=require(_0x483f('0xa'));var toCsv=require(_0x483f('0x6'));var querystring=require('querystring');var Papa=require(_0x483f('0xb'));var Redis=require(_0x483f('0xc'));var authService=require(_0x483f('0xd'));var qs=require('../../components/parsers/qs');var as=require(_0x483f('0xe'));var hardwareService=require(_0x483f('0xf'));var logger=require(_0x483f('0x10'))(_0x483f('0x11'));var utils=require('../../config/utils');var config=require(_0x483f('0x12'));var licenseUtil=require(_0x483f('0x13'));var db=require(_0x483f('0x14'))['db'];function respondWithStatusCode(_0x32878f,_0x5d24b4){_0x5d24b4=_0x5d24b4||0xcc;return function(_0x3a6477){if(_0x3a6477){return _0x32878f['sendStatus'](_0x5d24b4);}return _0x32878f[_0x483f('0x15')](_0x5d24b4)['end']();};}function respondWithResult(_0x2c6b31,_0x2e2c20){_0x2e2c20=_0x2e2c20||0xc8;return function(_0x2b0d1f){if(_0x2b0d1f){return _0x2c6b31['status'](_0x2e2c20)['json'](_0x2b0d1f);}};}function respondWithFilteredResult(_0x269fe9,_0xd3a755){return function(_0x17c545){if(_0x17c545){var _0x292de1=typeof _0xd3a755[_0x483f('0x16')]==='undefined'&&typeof _0xd3a755[_0x483f('0x17')]===_0x483f('0x18');var _0x47995e=_0x17c545[_0x483f('0x19')];var _0x5494f5=_0x292de1?0x0:_0xd3a755[_0x483f('0x16')];var _0x3887d5=_0x292de1?_0x17c545['count']:_0xd3a755['offset']+_0xd3a755[_0x483f('0x17')];var _0x3daa2b;if(_0x3887d5>=_0x47995e){_0x3887d5=_0x47995e;_0x3daa2b=0xc8;}else{_0x3daa2b=0xce;}_0x269fe9[_0x483f('0x15')](_0x3daa2b);return _0x269fe9[_0x483f('0x1a')](_0x483f('0x1b'),_0x5494f5+'-'+_0x3887d5+'/'+_0x47995e)[_0x483f('0x1c')](_0x17c545);}return null;};}function patchUpdates(_0x273a45){return function(_0x13772f){try{jsonpatch[_0x483f('0x1d')](_0x13772f,_0x273a45,!![]);}catch(_0x1fc85c){return BPromise[_0x483f('0x1e')](_0x1fc85c);}return _0x13772f['save']();};}function saveUpdates(_0x59747f,_0x201874){return function(_0x1790dd){if(_0x1790dd){return _0x1790dd[_0x483f('0x1f')](_0x59747f)[_0x483f('0x20')](function(_0x15ce3b){return _0x15ce3b;});}return null;};}function removeEntity(_0x312880,_0x48f71d){return function(_0x2502fe){if(_0x2502fe){return _0x2502fe[_0x483f('0x21')]()[_0x483f('0x20')](function(){var _0x1f09de=_0x2502fe['get']({'plain':!![]});var _0x9622c1=_0x483f('0x22');return db[_0x483f('0x23')][_0x483f('0x21')]({'where':{'type':_0x9622c1,'resourceId':_0x1f09de['id']}})[_0x483f('0x20')](function(){return _0x2502fe;});})[_0x483f('0x20')](function(){_0x312880['status'](0xcc)[_0x483f('0x24')]();});}};}function handleEntityNotFound(_0x3933ae,_0x60339a){return function(_0x4f3b28){if(!_0x4f3b28){_0x3933ae[_0x483f('0x25')](0x194);}return _0x4f3b28;};}function handleError(_0x2bf59f,_0x5a3121){_0x5a3121=_0x5a3121||0x1f4;return function(_0x60327d){logger[_0x483f('0x26')](_0x60327d[_0x483f('0x27')]);if(_0x60327d[_0x483f('0x28')]){delete _0x60327d[_0x483f('0x28')];}_0x2bf59f[_0x483f('0x15')](_0x5a3121)[_0x483f('0x29')](_0x60327d);};}exports['index']=function(_0x421eb7,_0x1269f1){var _0x3a06e2={},_0x5436a6={},_0x1fddc6={'count':0x0,'rows':[]};var _0x2999a7=_[_0x483f('0x2a')](db[_0x483f('0x2b')][_0x483f('0x2c')],function(_0x18ddec){return{'name':_0x18ddec[_0x483f('0x2d')],'type':_0x18ddec[_0x483f('0x2e')][_0x483f('0x2f')]};});_0x5436a6[_0x483f('0x30')]=_[_0x483f('0x2a')](_0x2999a7,_0x483f('0x28'));_0x5436a6[_0x483f('0x31')]=_['keys'](_0x421eb7[_0x483f('0x31')]);_0x5436a6[_0x483f('0x32')]=_[_0x483f('0x33')](_0x5436a6[_0x483f('0x30')],_0x5436a6['query']);_0x3a06e2['attributes']=_[_0x483f('0x33')](_0x5436a6[_0x483f('0x30')],qs['fields'](_0x421eb7[_0x483f('0x31')][_0x483f('0x34')]));_0x3a06e2['attributes']=_0x3a06e2[_0x483f('0x35')][_0x483f('0x36')]?_0x3a06e2[_0x483f('0x35')]:_0x5436a6[_0x483f('0x30')];if(!_0x421eb7['query'][_0x483f('0x37')]('nolimit')){_0x3a06e2[_0x483f('0x17')]=qs[_0x483f('0x17')](_0x421eb7[_0x483f('0x31')][_0x483f('0x17')]);_0x3a06e2[_0x483f('0x16')]=qs[_0x483f('0x16')](_0x421eb7[_0x483f('0x31')][_0x483f('0x16')]);}_0x3a06e2[_0x483f('0x38')]=qs['sort'](_0x421eb7[_0x483f('0x31')]['sort']);_0x3a06e2['where']=qs[_0x483f('0x32')](_[_0x483f('0x39')](_0x421eb7[_0x483f('0x31')],_0x5436a6[_0x483f('0x32')]),_0x2999a7);if(_0x421eb7[_0x483f('0x31')][_0x483f('0x3a')]){_0x3a06e2['where']=_[_0x483f('0x3b')](_0x3a06e2[_0x483f('0x3c')],{'$or':_[_0x483f('0x2a')](_0x2999a7,function(_0x894b0a){if(_0x894b0a[_0x483f('0x2e')]!==_0x483f('0x3d')){var _0x3f4e7e={};_0x3f4e7e[_0x894b0a['name']]={'$like':'%'+_0x421eb7[_0x483f('0x31')][_0x483f('0x3a')]+'%'};return _0x3f4e7e;}})});}_0x3a06e2=_[_0x483f('0x3b')]({},_0x3a06e2,_0x421eb7[_0x483f('0x3e')]);var _0x3541f5={'where':_0x3a06e2['where']};return db[_0x483f('0x2b')]['count'](_0x3541f5)[_0x483f('0x20')](function(_0x311670){_0x1fddc6[_0x483f('0x19')]=_0x311670;if(_0x421eb7['query'][_0x483f('0x3f')]){_0x3a06e2['include']=[{'all':!![]}];}return db[_0x483f('0x2b')][_0x483f('0x40')](_0x3a06e2);})[_0x483f('0x20')](function(_0x36aaa5){_0x1fddc6[_0x483f('0x41')]=_0x36aaa5;return _0x1fddc6;})[_0x483f('0x20')](respondWithFilteredResult(_0x1269f1,_0x3a06e2))['catch'](handleError(_0x1269f1,null));};exports[_0x483f('0x42')]=function(_0x36ae0b,_0x2cedbe){var _0x4ad2b2={'raw':!![],'where':{'id':_0x36ae0b['params']['id']}},_0x219c2b={};_0x219c2b[_0x483f('0x30')]=_[_0x483f('0x43')](db[_0x483f('0x2b')][_0x483f('0x2c')]);_0x219c2b[_0x483f('0x31')]=_['keys'](_0x36ae0b[_0x483f('0x31')]);_0x219c2b[_0x483f('0x32')]=_[_0x483f('0x33')](_0x219c2b[_0x483f('0x30')],_0x219c2b[_0x483f('0x31')]);_0x4ad2b2[_0x483f('0x35')]=_['intersection'](_0x219c2b[_0x483f('0x30')],qs[_0x483f('0x34')](_0x36ae0b[_0x483f('0x31')][_0x483f('0x34')]));_0x4ad2b2['attributes']=_0x4ad2b2[_0x483f('0x35')][_0x483f('0x36')]?_0x4ad2b2[_0x483f('0x35')]:_0x219c2b['model'];if(_0x36ae0b['query'][_0x483f('0x3f')]){_0x4ad2b2[_0x483f('0x44')]=[{'all':!![]}];}_0x4ad2b2=_['merge']({},_0x4ad2b2,_0x36ae0b['options']);return db['CmHopperAdditionalPhone']['find'](_0x4ad2b2)[_0x483f('0x20')](handleEntityNotFound(_0x2cedbe,null))[_0x483f('0x20')](respondWithResult(_0x2cedbe,null))[_0x483f('0x45')](handleError(_0x2cedbe,null));};exports[_0x483f('0x46')]=function(_0x5e7b78,_0x32d77a){return db[_0x483f('0x2b')][_0x483f('0x46')](_0x5e7b78[_0x483f('0x47')],{})[_0x483f('0x20')](function(_0x27fd5e){var _0x4b58ce=_0x5e7b78[_0x483f('0x48')][_0x483f('0x49')]({'plain':!![]});if(!_0x4b58ce)throw new Error(_0x483f('0x4a'));if(_0x4b58ce[_0x483f('0x4b')]===_0x483f('0x48')){var _0x2fc217=_0x27fd5e[_0x483f('0x49')]({'plain':!![]});var _0x5b1ecd=_0x483f('0x22');return db[_0x483f('0x4c')][_0x483f('0x4d')]({'where':{'name':_0x5b1ecd,'userProfileId':_0x4b58ce[_0x483f('0x4e')]},'raw':!![]})[_0x483f('0x20')](function(_0x2a8739){if(_0x2a8739&&_0x2a8739[_0x483f('0x4f')]===0x0){return db[_0x483f('0x23')][_0x483f('0x46')]({'name':_0x2fc217[_0x483f('0x28')],'resourceId':_0x2fc217['id'],'type':_0x2a8739[_0x483f('0x28')],'sectionId':_0x2a8739['id']},{})[_0x483f('0x20')](function(){return _0x27fd5e;});}else{return _0x27fd5e;}})[_0x483f('0x45')](function(_0x3f967f){logger[_0x483f('0x26')](_0x483f('0x50'),_0x3f967f);throw _0x3f967f;});}return _0x27fd5e;})[_0x483f('0x20')](respondWithResult(_0x32d77a,0xc9))[_0x483f('0x45')](handleError(_0x32d77a,null));};exports[_0x483f('0x1f')]=function(_0x4e8f5b,_0x561cc1){if(_0x4e8f5b[_0x483f('0x47')]['id']){delete _0x4e8f5b[_0x483f('0x47')]['id'];}return db[_0x483f('0x2b')][_0x483f('0x4d')]({'where':{'id':_0x4e8f5b[_0x483f('0x51')]['id']}})['then'](handleEntityNotFound(_0x561cc1,null))[_0x483f('0x20')](saveUpdates(_0x4e8f5b['body'],null))['then'](respondWithResult(_0x561cc1,null))[_0x483f('0x45')](handleError(_0x561cc1,null));};exports[_0x483f('0x21')]=function(_0x152fd3,_0x3274f7){return db[_0x483f('0x2b')][_0x483f('0x4d')]({'where':{'id':_0x152fd3[_0x483f('0x51')]['id']}})['then'](handleEntityNotFound(_0x3274f7,null))[_0x483f('0x20')](removeEntity(_0x3274f7,null))['catch'](handleError(_0x3274f7,null));};