46102bca34261d7247675ef564c7a231eb23f6c6
[motion2.git] / server / api / userProfileSection / userProfileSection.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 _0xdd67=['rows','catch','show','params','rawAttributes','find','create','body','destroy','describe','rimraf','zip-dir','fast-json-patch','request-promise','util','path','to-csv','fs-extra','lodash','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','save','update','then','stack','name','send','index','map','UserProfileSection','fieldName','type','model','keys','query','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include'];(function(_0x4f9b18,_0x2cb5ca){var _0x29f20c=function(_0x268b3d){while(--_0x268b3d){_0x4f9b18['push'](_0x4f9b18['shift']());}};_0x29f20c(++_0x2cb5ca);}(_0xdd67,0xdf));var _0x7dd6=function(_0x1aad06,_0x3cc565){_0x1aad06=_0x1aad06-0x0;var _0x484bd6=_0xdd67[_0x1aad06];return _0x484bd6;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x7dd6('0x0'));var zipdir=require(_0x7dd6('0x1'));var jsonpatch=require(_0x7dd6('0x2'));var rp=require(_0x7dd6('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x7dd6('0x4'));var path=require(_0x7dd6('0x5'));var sox=require('sox');var csv=require(_0x7dd6('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x7dd6('0x7'));var _=require(_0x7dd6('0x8'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x7dd6('0x9'));var deskjs=require('desk.js');var toCsv=require(_0x7dd6('0x6'));var querystring=require(_0x7dd6('0xa'));var Papa=require(_0x7dd6('0xb'));var Redis=require(_0x7dd6('0xc'));var authService=require(_0x7dd6('0xd'));var qs=require(_0x7dd6('0xe'));var as=require(_0x7dd6('0xf'));var hardwareService=require(_0x7dd6('0x10'));var logger=require(_0x7dd6('0x11'))(_0x7dd6('0x12'));var utils=require(_0x7dd6('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x7dd6('0x14'));var db=require(_0x7dd6('0x15'))['db'];function respondWithStatusCode(_0x3a1f96,_0x7e8fb7){_0x7e8fb7=_0x7e8fb7||0xcc;return function(_0x2b209d){if(_0x2b209d){return _0x3a1f96[_0x7dd6('0x16')](_0x7e8fb7);}return _0x3a1f96[_0x7dd6('0x17')](_0x7e8fb7)[_0x7dd6('0x18')]();};}function respondWithResult(_0x38c7d6,_0x14dc39){_0x14dc39=_0x14dc39||0xc8;return function(_0x64f84c){if(_0x64f84c){return _0x38c7d6['status'](_0x14dc39)[_0x7dd6('0x19')](_0x64f84c);}};}function respondWithFilteredResult(_0x5a7205,_0x8feb5c){return function(_0x3b8be7){if(_0x3b8be7){var _0x34eafb=typeof _0x8feb5c[_0x7dd6('0x1a')]===_0x7dd6('0x1b')&&typeof _0x8feb5c[_0x7dd6('0x1c')]==='undefined';var _0x362189=_0x3b8be7[_0x7dd6('0x1d')];var _0x238d0a=_0x34eafb?0x0:_0x8feb5c[_0x7dd6('0x1a')];var _0x44ef85=_0x34eafb?_0x3b8be7[_0x7dd6('0x1d')]:_0x8feb5c[_0x7dd6('0x1a')]+_0x8feb5c[_0x7dd6('0x1c')];var _0x4ef05b;if(_0x44ef85>=_0x362189){_0x44ef85=_0x362189;_0x4ef05b=0xc8;}else{_0x4ef05b=0xce;}_0x5a7205[_0x7dd6('0x17')](_0x4ef05b);return _0x5a7205[_0x7dd6('0x1e')]('Content-Range',_0x238d0a+'-'+_0x44ef85+'/'+_0x362189)['json'](_0x3b8be7);}return null;};}function patchUpdates(_0x2703c6){return function(_0x9509a7){try{jsonpatch[_0x7dd6('0x1f')](_0x9509a7,_0x2703c6,!![]);}catch(_0x27fc35){return BPromise['reject'](_0x27fc35);}return _0x9509a7[_0x7dd6('0x20')]();};}function saveUpdates(_0x29301d,_0x18df0b){return function(_0x471af5){if(_0x471af5){return _0x471af5[_0x7dd6('0x21')](_0x29301d)[_0x7dd6('0x22')](function(_0x375eee){return _0x375eee;});}return null;};}function removeEntity(_0x4b13fa,_0x2d09f5){return function(_0x4063a2){if(_0x4063a2){return _0x4063a2['destroy']()[_0x7dd6('0x22')](function(){_0x4b13fa[_0x7dd6('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x421481,_0x3d5e6e){return function(_0x4fb5cc){if(!_0x4fb5cc){_0x421481[_0x7dd6('0x16')](0x194);}return _0x4fb5cc;};}function handleError(_0x4b5ebd,_0x35157f){_0x35157f=_0x35157f||0x1f4;return function(_0x5d1458){logger['error'](_0x5d1458[_0x7dd6('0x23')]);if(_0x5d1458[_0x7dd6('0x24')]){delete _0x5d1458['name'];}_0x4b5ebd['status'](_0x35157f)[_0x7dd6('0x25')](_0x5d1458);};}exports[_0x7dd6('0x26')]=function(_0xc5abae,_0x34ce81){var _0x2bd5a5={},_0x52373a={},_0xec7542={'count':0x0,'rows':[]};var _0x1aff7d=_[_0x7dd6('0x27')](db[_0x7dd6('0x28')]['rawAttributes'],function(_0x4fe3b9){return{'name':_0x4fe3b9[_0x7dd6('0x29')],'type':_0x4fe3b9[_0x7dd6('0x2a')]['key']};});_0x52373a[_0x7dd6('0x2b')]=_[_0x7dd6('0x27')](_0x1aff7d,_0x7dd6('0x24'));_0x52373a['query']=_[_0x7dd6('0x2c')](_0xc5abae[_0x7dd6('0x2d')]);_0x52373a['filters']=_[_0x7dd6('0x2e')](_0x52373a['model'],_0x52373a[_0x7dd6('0x2d')]);_0x2bd5a5['attributes']=_[_0x7dd6('0x2e')](_0x52373a[_0x7dd6('0x2b')],qs[_0x7dd6('0x2f')](_0xc5abae[_0x7dd6('0x2d')][_0x7dd6('0x2f')]));_0x2bd5a5[_0x7dd6('0x30')]=_0x2bd5a5['attributes'][_0x7dd6('0x31')]?_0x2bd5a5['attributes']:_0x52373a['model'];if(!_0xc5abae[_0x7dd6('0x2d')][_0x7dd6('0x32')]('nolimit')){_0x2bd5a5[_0x7dd6('0x1c')]=qs['limit'](_0xc5abae[_0x7dd6('0x2d')][_0x7dd6('0x1c')]);_0x2bd5a5[_0x7dd6('0x1a')]=qs[_0x7dd6('0x1a')](_0xc5abae['query']['offset']);}_0x2bd5a5[_0x7dd6('0x33')]=qs[_0x7dd6('0x34')](_0xc5abae[_0x7dd6('0x2d')]['sort']);_0x2bd5a5[_0x7dd6('0x35')]=qs[_0x7dd6('0x36')](_['pick'](_0xc5abae[_0x7dd6('0x2d')],_0x52373a['filters']),_0x1aff7d);if(_0xc5abae[_0x7dd6('0x2d')][_0x7dd6('0x37')]){_0x2bd5a5[_0x7dd6('0x35')]=_[_0x7dd6('0x38')](_0x2bd5a5[_0x7dd6('0x35')],{'$or':_['map'](_0x1aff7d,function(_0x3cb2b1){if(_0x3cb2b1[_0x7dd6('0x2a')]!==_0x7dd6('0x39')){var _0x4eadbc={};_0x4eadbc[_0x3cb2b1[_0x7dd6('0x24')]]={'$like':'%'+_0xc5abae['query'][_0x7dd6('0x37')]+'%'};return _0x4eadbc;}})});}_0x2bd5a5=_[_0x7dd6('0x38')]({},_0x2bd5a5,_0xc5abae[_0x7dd6('0x3a')]);var _0x248839={'where':_0x2bd5a5['where']};return db[_0x7dd6('0x28')][_0x7dd6('0x1d')](_0x248839)[_0x7dd6('0x22')](function(_0x1c5a82){_0xec7542[_0x7dd6('0x1d')]=_0x1c5a82;if(_0xc5abae[_0x7dd6('0x2d')][_0x7dd6('0x3b')]){_0x2bd5a5[_0x7dd6('0x3c')]=[{'all':!![]}];}return db[_0x7dd6('0x28')]['findAll'](_0x2bd5a5);})[_0x7dd6('0x22')](function(_0x549cff){_0xec7542[_0x7dd6('0x3d')]=_0x549cff;return _0xec7542;})[_0x7dd6('0x22')](respondWithFilteredResult(_0x34ce81,_0x2bd5a5))[_0x7dd6('0x3e')](handleError(_0x34ce81,null));};exports[_0x7dd6('0x3f')]=function(_0x16cfa8,_0x59982b){var _0xd8233={'raw':![],'where':{'id':_0x16cfa8[_0x7dd6('0x40')]['id']}},_0x57e09a={};_0x57e09a[_0x7dd6('0x2b')]=_[_0x7dd6('0x2c')](db[_0x7dd6('0x28')][_0x7dd6('0x41')]);_0x57e09a[_0x7dd6('0x2d')]=_[_0x7dd6('0x2c')](_0x16cfa8['query']);_0x57e09a[_0x7dd6('0x36')]=_[_0x7dd6('0x2e')](_0x57e09a[_0x7dd6('0x2b')],_0x57e09a[_0x7dd6('0x2d')]);_0xd8233[_0x7dd6('0x30')]=_[_0x7dd6('0x2e')](_0x57e09a[_0x7dd6('0x2b')],qs[_0x7dd6('0x2f')](_0x16cfa8[_0x7dd6('0x2d')][_0x7dd6('0x2f')]));_0xd8233['attributes']=_0xd8233[_0x7dd6('0x30')]['length']?_0xd8233['attributes']:_0x57e09a[_0x7dd6('0x2b')];if(_0x16cfa8[_0x7dd6('0x2d')][_0x7dd6('0x3b')]){_0xd8233[_0x7dd6('0x3c')]=[{'all':!![]}];}_0xd8233=_[_0x7dd6('0x38')]({},_0xd8233,_0x16cfa8[_0x7dd6('0x3a')]);return db[_0x7dd6('0x28')][_0x7dd6('0x42')](_0xd8233)[_0x7dd6('0x22')](handleEntityNotFound(_0x59982b,null))[_0x7dd6('0x22')](respondWithResult(_0x59982b,null))['catch'](handleError(_0x59982b,null));};exports[_0x7dd6('0x43')]=function(_0x37a68b,_0x4f5ba9){return db[_0x7dd6('0x28')][_0x7dd6('0x43')](_0x37a68b[_0x7dd6('0x44')],{})['then'](respondWithResult(_0x4f5ba9,0xc9))[_0x7dd6('0x3e')](handleError(_0x4f5ba9,null));};exports[_0x7dd6('0x21')]=function(_0x4ab222,_0x163663){if(_0x4ab222[_0x7dd6('0x44')]['id']){delete _0x4ab222[_0x7dd6('0x44')]['id'];}return db[_0x7dd6('0x28')]['find']({'where':{'id':_0x4ab222[_0x7dd6('0x40')]['id']}})[_0x7dd6('0x22')](handleEntityNotFound(_0x163663,null))[_0x7dd6('0x22')](saveUpdates(_0x4ab222[_0x7dd6('0x44')],null))[_0x7dd6('0x22')](respondWithResult(_0x163663,null))[_0x7dd6('0x3e')](handleError(_0x163663,null));};exports[_0x7dd6('0x45')]=function(_0x2dbea3,_0x18864d){return db[_0x7dd6('0x28')][_0x7dd6('0x42')]({'where':{'id':_0x2dbea3['params']['id']}})[_0x7dd6('0x22')](handleEntityNotFound(_0x18864d,null))[_0x7dd6('0x22')](removeEntity(_0x18864d,null))[_0x7dd6('0x3e')](handleError(_0x18864d,null));};exports[_0x7dd6('0x46')]=function(_0x1ff9e0,_0x17da92){return db[_0x7dd6('0x28')][_0x7dd6('0x46')]()[_0x7dd6('0x22')](respondWithResult(_0x17da92,null))['catch'](handleError(_0x17da92,null));};