Built motion from commit 10af8726.|2.6.34
[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 _0xb084=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','limit','count','offset','set','json','apply','reject','save','update','destroy','then','UserProfileResource','error','stack','name','send','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','filter','options','CmHopperAdditionalPhone','includeAll','include','findAll','catch','show','params','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','CmHopperAdditionalPhones','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','path','sox','ejs','fs-extra','lodash','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs'];(function(_0x1f35cb,_0x304577){var _0x1ce632=function(_0x5cdd2a){while(--_0x5cdd2a){_0x1f35cb['push'](_0x1f35cb['shift']());}};_0x1ce632(++_0x304577);}(_0xb084,0x1ed));var _0x4b08=function(_0x33a60a,_0x1a0165){_0x33a60a=_0x33a60a-0x0;var _0x3d186f=_0xb084[_0x33a60a];return _0x3d186f;};'use strict';var emlformat=require(_0x4b08('0x0'));var rimraf=require(_0x4b08('0x1'));var zipdir=require(_0x4b08('0x2'));var jsonpatch=require(_0x4b08('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x4b08('0x4'));var Mustache=require(_0x4b08('0x5'));var util=require('util');var path=require(_0x4b08('0x6'));var sox=require(_0x4b08('0x7'));var csv=require('to-csv');var ejs=require(_0x4b08('0x8'));var fs=require('fs');var fs_extra=require(_0x4b08('0x9'));var _=require(_0x4b08('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x4b08('0xb'));var toCsv=require('to-csv');var querystring=require(_0x4b08('0xc'));var Papa=require(_0x4b08('0xd'));var Redis=require(_0x4b08('0xe'));var authService=require(_0x4b08('0xf'));var qs=require(_0x4b08('0x10'));var as=require(_0x4b08('0x11'));var hardwareService=require(_0x4b08('0x12'));var logger=require(_0x4b08('0x13'))(_0x4b08('0x14'));var utils=require(_0x4b08('0x15'));var config=require(_0x4b08('0x16'));var licenseUtil=require(_0x4b08('0x17'));var db=require(_0x4b08('0x18'))['db'];function respondWithStatusCode(_0x5905a2,_0x392689){_0x392689=_0x392689||0xcc;return function(_0x442770){if(_0x442770){return _0x5905a2[_0x4b08('0x19')](_0x392689);}return _0x5905a2[_0x4b08('0x1a')](_0x392689)[_0x4b08('0x1b')]();};}function respondWithResult(_0xb22b9e,_0x4f664c){_0x4f664c=_0x4f664c||0xc8;return function(_0x4698bd){if(_0x4698bd){return _0xb22b9e[_0x4b08('0x1a')](_0x4f664c)['json'](_0x4698bd);}};}function respondWithFilteredResult(_0x229e02,_0x8edbeb){return function(_0x548fc5){if(_0x548fc5){var _0x3a792e=typeof _0x8edbeb['offset']==='undefined'&&typeof _0x8edbeb[_0x4b08('0x1c')]==='undefined';var _0x18dc7b=_0x548fc5[_0x4b08('0x1d')];var _0x1755eb=_0x3a792e?0x0:_0x8edbeb[_0x4b08('0x1e')];var _0x43a527=_0x3a792e?_0x548fc5[_0x4b08('0x1d')]:_0x8edbeb['offset']+_0x8edbeb[_0x4b08('0x1c')];var _0xe2f706;if(_0x43a527>=_0x18dc7b){_0x43a527=_0x18dc7b;_0xe2f706=0xc8;}else{_0xe2f706=0xce;}_0x229e02[_0x4b08('0x1a')](_0xe2f706);return _0x229e02[_0x4b08('0x1f')]('Content-Range',_0x1755eb+'-'+_0x43a527+'/'+_0x18dc7b)[_0x4b08('0x20')](_0x548fc5);}return null;};}function patchUpdates(_0x194f60){return function(_0x2fd199){try{jsonpatch[_0x4b08('0x21')](_0x2fd199,_0x194f60,!![]);}catch(_0x26b845){return BPromise[_0x4b08('0x22')](_0x26b845);}return _0x2fd199[_0x4b08('0x23')]();};}function saveUpdates(_0x4bdb84,_0x4a1274){return function(_0x243ab3){if(_0x243ab3){return _0x243ab3[_0x4b08('0x24')](_0x4bdb84)['then'](function(_0x59b98b){return _0x59b98b;});}return null;};}function removeEntity(_0x34127b,_0x4b594c){return function(_0x1e047f){if(_0x1e047f){return _0x1e047f[_0x4b08('0x25')]()[_0x4b08('0x26')](function(){var _0x1990ec=_0x1e047f['get']({'plain':!![]});var _0x3206dd='CmHopperAdditionalPhones';return db[_0x4b08('0x27')][_0x4b08('0x25')]({'where':{'type':_0x3206dd,'resourceId':_0x1990ec['id']}})['then'](function(){return _0x1e047f;});})[_0x4b08('0x26')](function(){_0x34127b['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x250eb7,_0x3b11b4){return function(_0x43b21c){if(!_0x43b21c){_0x250eb7[_0x4b08('0x19')](0x194);}return _0x43b21c;};}function handleError(_0x8c0c83,_0x3ac0ab){_0x3ac0ab=_0x3ac0ab||0x1f4;return function(_0x20e150){logger[_0x4b08('0x28')](_0x20e150[_0x4b08('0x29')]);if(_0x20e150[_0x4b08('0x2a')]){delete _0x20e150[_0x4b08('0x2a')];}_0x8c0c83['status'](_0x3ac0ab)[_0x4b08('0x2b')](_0x20e150);};}exports['index']=function(_0x5842ec,_0x2f9af2){var _0x416044={},_0x1c8674={},_0x136c75={'count':0x0,'rows':[]};var _0x1bf6f7=_[_0x4b08('0x2c')](db['CmHopperAdditionalPhone'][_0x4b08('0x2d')],function(_0x3bd3f5){return{'name':_0x3bd3f5[_0x4b08('0x2e')],'type':_0x3bd3f5[_0x4b08('0x2f')][_0x4b08('0x30')]};});_0x1c8674[_0x4b08('0x31')]=_['map'](_0x1bf6f7,_0x4b08('0x2a'));_0x1c8674[_0x4b08('0x32')]=_[_0x4b08('0x33')](_0x5842ec['query']);_0x1c8674[_0x4b08('0x34')]=_[_0x4b08('0x35')](_0x1c8674[_0x4b08('0x31')],_0x1c8674[_0x4b08('0x32')]);_0x416044[_0x4b08('0x36')]=_['intersection'](_0x1c8674[_0x4b08('0x31')],qs[_0x4b08('0x37')](_0x5842ec[_0x4b08('0x32')][_0x4b08('0x37')]));_0x416044[_0x4b08('0x36')]=_0x416044[_0x4b08('0x36')][_0x4b08('0x38')]?_0x416044[_0x4b08('0x36')]:_0x1c8674['model'];if(!_0x5842ec[_0x4b08('0x32')][_0x4b08('0x39')]('nolimit')){_0x416044['limit']=qs['limit'](_0x5842ec[_0x4b08('0x32')][_0x4b08('0x1c')]);_0x416044[_0x4b08('0x1e')]=qs['offset'](_0x5842ec['query']['offset']);}_0x416044[_0x4b08('0x3a')]=qs['sort'](_0x5842ec[_0x4b08('0x32')][_0x4b08('0x3b')]);_0x416044[_0x4b08('0x3c')]=qs[_0x4b08('0x34')](_[_0x4b08('0x3d')](_0x5842ec[_0x4b08('0x32')],_0x1c8674['filters']),_0x1bf6f7);if(_0x5842ec['query']['filter']){_0x416044[_0x4b08('0x3c')]=_[_0x4b08('0x3e')](_0x416044[_0x4b08('0x3c')],{'$or':_['map'](_0x1bf6f7,function(_0x3da2a3){if(_0x3da2a3[_0x4b08('0x2f')]!==_0x4b08('0x3f')){var _0x504f2b={};_0x504f2b[_0x3da2a3[_0x4b08('0x2a')]]={'$like':'%'+_0x5842ec[_0x4b08('0x32')][_0x4b08('0x40')]+'%'};return _0x504f2b;}})});}_0x416044=_[_0x4b08('0x3e')]({},_0x416044,_0x5842ec[_0x4b08('0x41')]);var _0x11ba23={'where':_0x416044[_0x4b08('0x3c')]};return db[_0x4b08('0x42')]['count'](_0x11ba23)[_0x4b08('0x26')](function(_0x2d1832){_0x136c75[_0x4b08('0x1d')]=_0x2d1832;if(_0x5842ec['query'][_0x4b08('0x43')]){_0x416044[_0x4b08('0x44')]=[{'all':!![]}];}return db[_0x4b08('0x42')][_0x4b08('0x45')](_0x416044);})[_0x4b08('0x26')](function(_0x85a2ad){_0x136c75['rows']=_0x85a2ad;return _0x136c75;})[_0x4b08('0x26')](respondWithFilteredResult(_0x2f9af2,_0x416044))[_0x4b08('0x46')](handleError(_0x2f9af2,null));};exports[_0x4b08('0x47')]=function(_0x478efc,_0x3f765a){var _0x42a874={'raw':!![],'where':{'id':_0x478efc[_0x4b08('0x48')]['id']}},_0x5f3dbf={};_0x5f3dbf[_0x4b08('0x31')]=_[_0x4b08('0x33')](db[_0x4b08('0x42')][_0x4b08('0x2d')]);_0x5f3dbf[_0x4b08('0x32')]=_[_0x4b08('0x33')](_0x478efc['query']);_0x5f3dbf[_0x4b08('0x34')]=_[_0x4b08('0x35')](_0x5f3dbf['model'],_0x5f3dbf['query']);_0x42a874[_0x4b08('0x36')]=_['intersection'](_0x5f3dbf[_0x4b08('0x31')],qs[_0x4b08('0x37')](_0x478efc[_0x4b08('0x32')][_0x4b08('0x37')]));_0x42a874[_0x4b08('0x36')]=_0x42a874[_0x4b08('0x36')]['length']?_0x42a874['attributes']:_0x5f3dbf['model'];if(_0x478efc[_0x4b08('0x32')]['includeAll']){_0x42a874[_0x4b08('0x44')]=[{'all':!![]}];}_0x42a874=_[_0x4b08('0x3e')]({},_0x42a874,_0x478efc['options']);return db[_0x4b08('0x42')][_0x4b08('0x49')](_0x42a874)[_0x4b08('0x26')](handleEntityNotFound(_0x3f765a,null))[_0x4b08('0x26')](respondWithResult(_0x3f765a,null))['catch'](handleError(_0x3f765a,null));};exports[_0x4b08('0x4a')]=function(_0x407e8b,_0x3a549a){return db['CmHopperAdditionalPhone'][_0x4b08('0x4a')](_0x407e8b[_0x4b08('0x4b')],{})[_0x4b08('0x26')](function(_0x3658bc){var _0x9d0298=_0x407e8b[_0x4b08('0x4c')][_0x4b08('0x4d')]({'plain':!![]});if(!_0x9d0298)throw new Error(_0x4b08('0x4e'));if(_0x9d0298[_0x4b08('0x4f')]==='user'){var _0x4ba6a7=_0x3658bc['get']({'plain':!![]});var _0x4b5aa2=_0x4b08('0x50');return db[_0x4b08('0x51')][_0x4b08('0x49')]({'where':{'name':_0x4b5aa2,'userProfileId':_0x9d0298[_0x4b08('0x52')]},'raw':!![]})[_0x4b08('0x26')](function(_0x1f812d){if(_0x1f812d&&_0x1f812d[_0x4b08('0x53')]===0x0){return db[_0x4b08('0x27')]['create']({'name':_0x4ba6a7[_0x4b08('0x2a')],'resourceId':_0x4ba6a7['id'],'type':_0x1f812d[_0x4b08('0x2a')],'sectionId':_0x1f812d['id']},{})['then'](function(){return _0x3658bc;});}else{return _0x3658bc;}})[_0x4b08('0x46')](function(_0x567923){logger[_0x4b08('0x28')](_0x4b08('0x54'),_0x567923);throw _0x567923;});}return _0x3658bc;})[_0x4b08('0x26')](respondWithResult(_0x3a549a,0xc9))[_0x4b08('0x46')](handleError(_0x3a549a,null));};exports[_0x4b08('0x24')]=function(_0x400d5a,_0x46fa3c){if(_0x400d5a[_0x4b08('0x4b')]['id']){delete _0x400d5a[_0x4b08('0x4b')]['id'];}return db[_0x4b08('0x42')][_0x4b08('0x49')]({'where':{'id':_0x400d5a[_0x4b08('0x48')]['id']}})[_0x4b08('0x26')](handleEntityNotFound(_0x46fa3c,null))['then'](saveUpdates(_0x400d5a[_0x4b08('0x4b')],null))[_0x4b08('0x26')](respondWithResult(_0x46fa3c,null))[_0x4b08('0x46')](handleError(_0x46fa3c,null));};exports[_0x4b08('0x25')]=function(_0x7b709d,_0x2e339b){return db[_0x4b08('0x42')][_0x4b08('0x49')]({'where':{'id':_0x7b709d[_0x4b08('0x48')]['id']}})[_0x4b08('0x26')](handleEntityNotFound(_0x2e339b,null))[_0x4b08('0x26')](removeEntity(_0x2e339b,null))['catch'](handleError(_0x2e339b,null));};