Built motion from commit 25580385.|2.6.2
[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 _0xf472=['filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','find','catch','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','set','Content-Range','save','update','destroy','get','CmHopperAdditionalPhones','UserProfileResource','then','error','stack','name','send','index','map','CmHopperAdditionalPhone','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','where','pick'];(function(_0x20bc10,_0x35bed9){var _0x3bd5ce=function(_0x8d1e4c){while(--_0x8d1e4c){_0x20bc10['push'](_0x20bc10['shift']());}};_0x3bd5ce(++_0x35bed9);}(_0xf472,0x6b));var _0x2f47=function(_0x42cae2,_0x284ef8){_0x42cae2=_0x42cae2-0x0;var _0x5f256f=_0xf472[_0x42cae2];return _0x5f256f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x2f47('0x0'));var zipdir=require(_0x2f47('0x1'));var jsonpatch=require(_0x2f47('0x2'));var rp=require(_0x2f47('0x3'));var moment=require('moment');var BPromise=require(_0x2f47('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x2f47('0x5'));var sox=require(_0x2f47('0x6'));var csv=require(_0x2f47('0x7'));var ejs=require(_0x2f47('0x8'));var fs=require('fs');var fs_extra=require(_0x2f47('0x9'));var _=require(_0x2f47('0xa'));var squel=require(_0x2f47('0xb'));var crypto=require(_0x2f47('0xc'));var jsforce=require(_0x2f47('0xd'));var deskjs=require(_0x2f47('0xe'));var toCsv=require(_0x2f47('0x7'));var querystring=require(_0x2f47('0xf'));var Papa=require('papaparse');var Redis=require(_0x2f47('0x10'));var authService=require(_0x2f47('0x11'));var qs=require(_0x2f47('0x12'));var as=require(_0x2f47('0x13'));var hardwareService=require(_0x2f47('0x14'));var logger=require(_0x2f47('0x15'))('api');var utils=require(_0x2f47('0x16'));var config=require(_0x2f47('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x2f47('0x18'))['db'];function respondWithStatusCode(_0x36e102,_0x390a06){_0x390a06=_0x390a06||0xcc;return function(_0x5d7d09){if(_0x5d7d09){return _0x36e102[_0x2f47('0x19')](_0x390a06);}return _0x36e102[_0x2f47('0x1a')](_0x390a06)[_0x2f47('0x1b')]();};}function respondWithResult(_0x3b5399,_0xc4128b){_0xc4128b=_0xc4128b||0xc8;return function(_0x59c0c5){if(_0x59c0c5){return _0x3b5399[_0x2f47('0x1a')](_0xc4128b)[_0x2f47('0x1c')](_0x59c0c5);}};}function respondWithFilteredResult(_0x26d341,_0x5b74b6){return function(_0x1acfb2){if(_0x1acfb2){var _0x3ba517=typeof _0x5b74b6[_0x2f47('0x1d')]==='undefined'&&typeof _0x5b74b6['limit']===_0x2f47('0x1e');var _0x5a7325=_0x1acfb2[_0x2f47('0x1f')];var _0x2153ef=_0x3ba517?0x0:_0x5b74b6[_0x2f47('0x1d')];var _0x395b7b=_0x3ba517?_0x1acfb2['count']:_0x5b74b6['offset']+_0x5b74b6['limit'];var _0x339bed;if(_0x395b7b>=_0x5a7325){_0x395b7b=_0x5a7325;_0x339bed=0xc8;}else{_0x339bed=0xce;}_0x26d341['status'](_0x339bed);return _0x26d341[_0x2f47('0x20')](_0x2f47('0x21'),_0x2153ef+'-'+_0x395b7b+'/'+_0x5a7325)[_0x2f47('0x1c')](_0x1acfb2);}return null;};}function patchUpdates(_0x5c1410){return function(_0x371f1d){try{jsonpatch['apply'](_0x371f1d,_0x5c1410,!![]);}catch(_0x1c3817){return BPromise['reject'](_0x1c3817);}return _0x371f1d[_0x2f47('0x22')]();};}function saveUpdates(_0x29f460,_0x5b8442){return function(_0x38e225){if(_0x38e225){return _0x38e225[_0x2f47('0x23')](_0x29f460)['then'](function(_0x5fed85){return _0x5fed85;});}return null;};}function removeEntity(_0x188e26,_0x356fe3){return function(_0x3c526c){if(_0x3c526c){return _0x3c526c[_0x2f47('0x24')]()['then'](function(){var _0x18e5f8=_0x3c526c[_0x2f47('0x25')]({'plain':!![]});var _0x4e794d=_0x2f47('0x26');return db[_0x2f47('0x27')]['destroy']({'where':{'type':_0x4e794d,'resourceId':_0x18e5f8['id']}})[_0x2f47('0x28')](function(){return _0x3c526c;});})[_0x2f47('0x28')](function(){_0x188e26['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x2dcb6d,_0x190d62){return function(_0x1d3b29){if(!_0x1d3b29){_0x2dcb6d['sendStatus'](0x194);}return _0x1d3b29;};}function handleError(_0x405b23,_0x4ac207){_0x4ac207=_0x4ac207||0x1f4;return function(_0x2a6fe5){logger[_0x2f47('0x29')](_0x2a6fe5[_0x2f47('0x2a')]);if(_0x2a6fe5[_0x2f47('0x2b')]){delete _0x2a6fe5[_0x2f47('0x2b')];}_0x405b23['status'](_0x4ac207)[_0x2f47('0x2c')](_0x2a6fe5);};}exports[_0x2f47('0x2d')]=function(_0x10c786,_0x11ce70){var _0x7fffb4={},_0x56c7ad={},_0x47d087={'count':0x0,'rows':[]};var _0x19a8df=_[_0x2f47('0x2e')](db[_0x2f47('0x2f')][_0x2f47('0x30')],function(_0x421794){return{'name':_0x421794[_0x2f47('0x31')],'type':_0x421794[_0x2f47('0x32')][_0x2f47('0x33')]};});_0x56c7ad[_0x2f47('0x34')]=_[_0x2f47('0x2e')](_0x19a8df,_0x2f47('0x2b'));_0x56c7ad[_0x2f47('0x35')]=_['keys'](_0x10c786[_0x2f47('0x35')]);_0x56c7ad[_0x2f47('0x36')]=_[_0x2f47('0x37')](_0x56c7ad[_0x2f47('0x34')],_0x56c7ad['query']);_0x7fffb4[_0x2f47('0x38')]=_[_0x2f47('0x37')](_0x56c7ad['model'],qs[_0x2f47('0x39')](_0x10c786[_0x2f47('0x35')][_0x2f47('0x39')]));_0x7fffb4['attributes']=_0x7fffb4[_0x2f47('0x38')][_0x2f47('0x3a')]?_0x7fffb4[_0x2f47('0x38')]:_0x56c7ad[_0x2f47('0x34')];if(!_0x10c786[_0x2f47('0x35')][_0x2f47('0x3b')]('nolimit')){_0x7fffb4[_0x2f47('0x3c')]=qs[_0x2f47('0x3c')](_0x10c786[_0x2f47('0x35')]['limit']);_0x7fffb4['offset']=qs[_0x2f47('0x1d')](_0x10c786['query'][_0x2f47('0x1d')]);}_0x7fffb4[_0x2f47('0x3d')]=qs[_0x2f47('0x3e')](_0x10c786[_0x2f47('0x35')][_0x2f47('0x3e')]);_0x7fffb4[_0x2f47('0x3f')]=qs[_0x2f47('0x36')](_[_0x2f47('0x40')](_0x10c786['query'],_0x56c7ad[_0x2f47('0x36')]),_0x19a8df);if(_0x10c786[_0x2f47('0x35')][_0x2f47('0x41')]){_0x7fffb4[_0x2f47('0x3f')]=_[_0x2f47('0x42')](_0x7fffb4[_0x2f47('0x3f')],{'$or':_[_0x2f47('0x2e')](_0x19a8df,function(_0x451898){if(_0x451898[_0x2f47('0x32')]!==_0x2f47('0x43')){var _0x548fe2={};_0x548fe2[_0x451898[_0x2f47('0x2b')]]={'$like':'%'+_0x10c786[_0x2f47('0x35')]['filter']+'%'};return _0x548fe2;}})});}_0x7fffb4=_[_0x2f47('0x42')]({},_0x7fffb4,_0x10c786[_0x2f47('0x44')]);var _0x2f7e51={'where':_0x7fffb4['where']};return db[_0x2f47('0x2f')][_0x2f47('0x1f')](_0x2f7e51)[_0x2f47('0x28')](function(_0x2116e2){_0x47d087[_0x2f47('0x1f')]=_0x2116e2;if(_0x10c786[_0x2f47('0x35')][_0x2f47('0x45')]){_0x7fffb4[_0x2f47('0x46')]=[{'all':!![]}];}return db[_0x2f47('0x2f')][_0x2f47('0x47')](_0x7fffb4);})[_0x2f47('0x28')](function(_0xb28e47){_0x47d087[_0x2f47('0x48')]=_0xb28e47;return _0x47d087;})[_0x2f47('0x28')](respondWithFilteredResult(_0x11ce70,_0x7fffb4))['catch'](handleError(_0x11ce70,null));};exports[_0x2f47('0x49')]=function(_0x2682b6,_0x106802){var _0xd671f2={'raw':!![],'where':{'id':_0x2682b6[_0x2f47('0x4a')]['id']}},_0x4e5cef={};_0x4e5cef[_0x2f47('0x34')]=_['keys'](db[_0x2f47('0x2f')][_0x2f47('0x30')]);_0x4e5cef['query']=_[_0x2f47('0x4b')](_0x2682b6[_0x2f47('0x35')]);_0x4e5cef[_0x2f47('0x36')]=_[_0x2f47('0x37')](_0x4e5cef[_0x2f47('0x34')],_0x4e5cef[_0x2f47('0x35')]);_0xd671f2[_0x2f47('0x38')]=_['intersection'](_0x4e5cef[_0x2f47('0x34')],qs[_0x2f47('0x39')](_0x2682b6[_0x2f47('0x35')][_0x2f47('0x39')]));_0xd671f2['attributes']=_0xd671f2[_0x2f47('0x38')][_0x2f47('0x3a')]?_0xd671f2['attributes']:_0x4e5cef[_0x2f47('0x34')];if(_0x2682b6[_0x2f47('0x35')][_0x2f47('0x45')]){_0xd671f2[_0x2f47('0x46')]=[{'all':!![]}];}_0xd671f2=_[_0x2f47('0x42')]({},_0xd671f2,_0x2682b6['options']);return db['CmHopperAdditionalPhone'][_0x2f47('0x4c')](_0xd671f2)[_0x2f47('0x28')](handleEntityNotFound(_0x106802,null))[_0x2f47('0x28')](respondWithResult(_0x106802,null))[_0x2f47('0x4d')](handleError(_0x106802,null));};exports[_0x2f47('0x4e')]=function(_0x51d366,_0x271e59){return db[_0x2f47('0x2f')][_0x2f47('0x4e')](_0x51d366[_0x2f47('0x4f')],{})['then'](function(_0x43ea6c){var _0x7eaffe=_0x51d366['user']['get']({'plain':!![]});if(!_0x7eaffe)throw new Error(_0x2f47('0x50'));if(_0x7eaffe['role']===_0x2f47('0x51')){var _0x2488ef=_0x43ea6c[_0x2f47('0x25')]({'plain':!![]});var _0x5cdc79=_0x2f47('0x26');return db[_0x2f47('0x52')][_0x2f47('0x4c')]({'where':{'name':_0x5cdc79,'userProfileId':_0x7eaffe[_0x2f47('0x53')]},'raw':!![]})[_0x2f47('0x28')](function(_0x14f5ca){if(_0x14f5ca&&_0x14f5ca[_0x2f47('0x54')]===0x0){return db[_0x2f47('0x27')][_0x2f47('0x4e')]({'name':_0x2488ef[_0x2f47('0x2b')],'resourceId':_0x2488ef['id'],'type':_0x14f5ca['name'],'sectionId':_0x14f5ca['id']},{})[_0x2f47('0x28')](function(){return _0x43ea6c;});}else{return _0x43ea6c;}})[_0x2f47('0x4d')](function(_0x5f3e9d){logger['error'](_0x2f47('0x55'),_0x5f3e9d);throw _0x5f3e9d;});}return _0x43ea6c;})[_0x2f47('0x28')](respondWithResult(_0x271e59,0xc9))['catch'](handleError(_0x271e59,null));};exports[_0x2f47('0x23')]=function(_0x33b176,_0x167529){if(_0x33b176[_0x2f47('0x4f')]['id']){delete _0x33b176[_0x2f47('0x4f')]['id'];}return db['CmHopperAdditionalPhone']['find']({'where':{'id':_0x33b176['params']['id']}})[_0x2f47('0x28')](handleEntityNotFound(_0x167529,null))[_0x2f47('0x28')](saveUpdates(_0x33b176[_0x2f47('0x4f')],null))[_0x2f47('0x28')](respondWithResult(_0x167529,null))['catch'](handleError(_0x167529,null));};exports[_0x2f47('0x24')]=function(_0x5e7978,_0x4fcad0){return db[_0x2f47('0x2f')][_0x2f47('0x4c')]({'where':{'id':_0x5e7978[_0x2f47('0x4a')]['id']}})['then'](handleEntityNotFound(_0x4fcad0,null))[_0x2f47('0x28')](removeEntity(_0x4fcad0,null))[_0x2f47('0x4d')](handleError(_0x4fcad0,null));};