Built motion from commit b5996064.|2.6.21
[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 _0x02cb=['querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','index','map','UserProfileSection','fieldName','key','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','options','includeAll','findAll','show','params','rawAttributes','include','merge','create','body','catch','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js'];(function(_0x14ed86,_0x2ad5f6){var _0x2d86d2=function(_0x2b843e){while(--_0x2b843e){_0x14ed86['push'](_0x14ed86['shift']());}};_0x2d86d2(++_0x2ad5f6);}(_0x02cb,0x172));var _0xb02c=function(_0x1adb5d,_0x1e36cc){_0x1adb5d=_0x1adb5d-0x0;var _0x3acc58=_0x02cb[_0x1adb5d];return _0x3acc58;};'use strict';var emlformat=require(_0xb02c('0x0'));var rimraf=require(_0xb02c('0x1'));var zipdir=require(_0xb02c('0x2'));var jsonpatch=require(_0xb02c('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xb02c('0x4'));var Mustache=require(_0xb02c('0x5'));var util=require(_0xb02c('0x6'));var path=require(_0xb02c('0x7'));var sox=require(_0xb02c('0x8'));var csv=require(_0xb02c('0x9'));var ejs=require(_0xb02c('0xa'));var fs=require('fs');var fs_extra=require(_0xb02c('0xb'));var _=require(_0xb02c('0xc'));var squel=require(_0xb02c('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xb02c('0xe'));var toCsv=require(_0xb02c('0x9'));var querystring=require(_0xb02c('0xf'));var Papa=require(_0xb02c('0x10'));var Redis=require(_0xb02c('0x11'));var authService=require(_0xb02c('0x12'));var qs=require(_0xb02c('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb02c('0x14'));var logger=require(_0xb02c('0x15'))(_0xb02c('0x16'));var utils=require(_0xb02c('0x17'));var config=require(_0xb02c('0x18'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2a9dff,_0x516353){_0x516353=_0x516353||0xcc;return function(_0x557d97){if(_0x557d97){return _0x2a9dff['sendStatus'](_0x516353);}return _0x2a9dff[_0xb02c('0x19')](_0x516353)[_0xb02c('0x1a')]();};}function respondWithResult(_0x2acc71,_0x1f35f5){_0x1f35f5=_0x1f35f5||0xc8;return function(_0xbe94dc){if(_0xbe94dc){return _0x2acc71[_0xb02c('0x19')](_0x1f35f5)['json'](_0xbe94dc);}};}function respondWithFilteredResult(_0x39f141,_0x1e7331){return function(_0x4e3510){if(_0x4e3510){var _0x4e99dd=typeof _0x1e7331[_0xb02c('0x1b')]===_0xb02c('0x1c')&&typeof _0x1e7331[_0xb02c('0x1d')]===_0xb02c('0x1c');var _0x4c5552=_0x4e3510['count'];var _0x46a290=_0x4e99dd?0x0:_0x1e7331['offset'];var _0x2cb0c6=_0x4e99dd?_0x4e3510[_0xb02c('0x1e')]:_0x1e7331[_0xb02c('0x1b')]+_0x1e7331['limit'];var _0xd01aee;if(_0x2cb0c6>=_0x4c5552){_0x2cb0c6=_0x4c5552;_0xd01aee=0xc8;}else{_0xd01aee=0xce;}_0x39f141[_0xb02c('0x19')](_0xd01aee);return _0x39f141[_0xb02c('0x1f')](_0xb02c('0x20'),_0x46a290+'-'+_0x2cb0c6+'/'+_0x4c5552)[_0xb02c('0x21')](_0x4e3510);}return null;};}function patchUpdates(_0x37463a){return function(_0x35764e){try{jsonpatch[_0xb02c('0x22')](_0x35764e,_0x37463a,!![]);}catch(_0x56a55a){return BPromise[_0xb02c('0x23')](_0x56a55a);}return _0x35764e[_0xb02c('0x24')]();};}function saveUpdates(_0x1c13c5,_0x4ed2ad){return function(_0x517f99){if(_0x517f99){return _0x517f99[_0xb02c('0x25')](_0x1c13c5)[_0xb02c('0x26')](function(_0x5dc08b){return _0x5dc08b;});}return null;};}function removeEntity(_0x4580a7,_0x21a212){return function(_0x2490b6){if(_0x2490b6){return _0x2490b6[_0xb02c('0x27')]()[_0xb02c('0x26')](function(){_0x4580a7['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x26d83d,_0x238843){return function(_0x105afb){if(!_0x105afb){_0x26d83d[_0xb02c('0x28')](0x194);}return _0x105afb;};}function handleError(_0x3ea4eb,_0x52899c){_0x52899c=_0x52899c||0x1f4;return function(_0x447952){logger[_0xb02c('0x29')](_0x447952[_0xb02c('0x2a')]);if(_0x447952[_0xb02c('0x2b')]){delete _0x447952[_0xb02c('0x2b')];}_0x3ea4eb[_0xb02c('0x19')](_0x52899c)['send'](_0x447952);};}exports[_0xb02c('0x2c')]=function(_0xf0fc90,_0x357053){var _0x5f23ed={},_0x168446={},_0x1b40b1={'count':0x0,'rows':[]};var _0x5b8057=_[_0xb02c('0x2d')](db[_0xb02c('0x2e')]['rawAttributes'],function(_0xebb01){return{'name':_0xebb01[_0xb02c('0x2f')],'type':_0xebb01['type'][_0xb02c('0x30')]};});_0x168446['model']=_[_0xb02c('0x2d')](_0x5b8057,_0xb02c('0x2b'));_0x168446[_0xb02c('0x31')]=_[_0xb02c('0x32')](_0xf0fc90['query']);_0x168446['filters']=_[_0xb02c('0x33')](_0x168446[_0xb02c('0x34')],_0x168446[_0xb02c('0x31')]);_0x5f23ed[_0xb02c('0x35')]=_[_0xb02c('0x33')](_0x168446[_0xb02c('0x34')],qs['fields'](_0xf0fc90[_0xb02c('0x31')][_0xb02c('0x36')]));_0x5f23ed[_0xb02c('0x35')]=_0x5f23ed[_0xb02c('0x35')][_0xb02c('0x37')]?_0x5f23ed[_0xb02c('0x35')]:_0x168446['model'];if(!_0xf0fc90[_0xb02c('0x31')][_0xb02c('0x38')](_0xb02c('0x39'))){_0x5f23ed['limit']=qs['limit'](_0xf0fc90[_0xb02c('0x31')][_0xb02c('0x1d')]);_0x5f23ed['offset']=qs[_0xb02c('0x1b')](_0xf0fc90['query'][_0xb02c('0x1b')]);}_0x5f23ed[_0xb02c('0x3a')]=qs[_0xb02c('0x3b')](_0xf0fc90['query'][_0xb02c('0x3b')]);_0x5f23ed[_0xb02c('0x3c')]=qs[_0xb02c('0x3d')](_[_0xb02c('0x3e')](_0xf0fc90[_0xb02c('0x31')],_0x168446[_0xb02c('0x3d')]),_0x5b8057);if(_0xf0fc90[_0xb02c('0x31')][_0xb02c('0x3f')]){_0x5f23ed['where']=_['merge'](_0x5f23ed[_0xb02c('0x3c')],{'$or':_['map'](_0x5b8057,function(_0x29cd94){if(_0x29cd94['type']!=='VIRTUAL'){var _0x5bea58={};_0x5bea58[_0x29cd94[_0xb02c('0x2b')]]={'$like':'%'+_0xf0fc90[_0xb02c('0x31')]['filter']+'%'};return _0x5bea58;}})});}_0x5f23ed=_['merge']({},_0x5f23ed,_0xf0fc90[_0xb02c('0x40')]);var _0x5a0a4b={'where':_0x5f23ed[_0xb02c('0x3c')]};return db[_0xb02c('0x2e')][_0xb02c('0x1e')](_0x5a0a4b)['then'](function(_0xb31305){_0x1b40b1['count']=_0xb31305;if(_0xf0fc90[_0xb02c('0x31')][_0xb02c('0x41')]){_0x5f23ed['include']=[{'all':!![]}];}return db[_0xb02c('0x2e')][_0xb02c('0x42')](_0x5f23ed);})[_0xb02c('0x26')](function(_0x5d720a){_0x1b40b1['rows']=_0x5d720a;return _0x1b40b1;})['then'](respondWithFilteredResult(_0x357053,_0x5f23ed))['catch'](handleError(_0x357053,null));};exports[_0xb02c('0x43')]=function(_0x2cb2c9,_0x51577f){var _0x42ad3f={'raw':![],'where':{'id':_0x2cb2c9[_0xb02c('0x44')]['id']}},_0x1ca848={};_0x1ca848[_0xb02c('0x34')]=_[_0xb02c('0x32')](db[_0xb02c('0x2e')][_0xb02c('0x45')]);_0x1ca848[_0xb02c('0x31')]=_[_0xb02c('0x32')](_0x2cb2c9[_0xb02c('0x31')]);_0x1ca848[_0xb02c('0x3d')]=_[_0xb02c('0x33')](_0x1ca848['model'],_0x1ca848[_0xb02c('0x31')]);_0x42ad3f[_0xb02c('0x35')]=_[_0xb02c('0x33')](_0x1ca848[_0xb02c('0x34')],qs[_0xb02c('0x36')](_0x2cb2c9[_0xb02c('0x31')][_0xb02c('0x36')]));_0x42ad3f[_0xb02c('0x35')]=_0x42ad3f[_0xb02c('0x35')]['length']?_0x42ad3f[_0xb02c('0x35')]:_0x1ca848[_0xb02c('0x34')];if(_0x2cb2c9[_0xb02c('0x31')]['includeAll']){_0x42ad3f[_0xb02c('0x46')]=[{'all':!![]}];}_0x42ad3f=_[_0xb02c('0x47')]({},_0x42ad3f,_0x2cb2c9['options']);return db['UserProfileSection']['find'](_0x42ad3f)[_0xb02c('0x26')](handleEntityNotFound(_0x51577f,null))[_0xb02c('0x26')](respondWithResult(_0x51577f,null))['catch'](handleError(_0x51577f,null));};exports[_0xb02c('0x48')]=function(_0x29907f,_0x49b304){return db[_0xb02c('0x2e')][_0xb02c('0x48')](_0x29907f[_0xb02c('0x49')],{})[_0xb02c('0x26')](respondWithResult(_0x49b304,0xc9))[_0xb02c('0x4a')](handleError(_0x49b304,null));};exports[_0xb02c('0x25')]=function(_0xdd3e6d,_0x47939e){if(_0xdd3e6d['body']['id']){delete _0xdd3e6d['body']['id'];}return db[_0xb02c('0x2e')][_0xb02c('0x4b')]({'where':{'id':_0xdd3e6d[_0xb02c('0x44')]['id']}})[_0xb02c('0x26')](handleEntityNotFound(_0x47939e,null))[_0xb02c('0x26')](saveUpdates(_0xdd3e6d[_0xb02c('0x49')],null))[_0xb02c('0x26')](respondWithResult(_0x47939e,null))[_0xb02c('0x4a')](handleError(_0x47939e,null));};exports[_0xb02c('0x27')]=function(_0x31e29d,_0x4b1cd6){return db[_0xb02c('0x2e')]['find']({'where':{'id':_0x31e29d[_0xb02c('0x44')]['id']}})['then'](handleEntityNotFound(_0x4b1cd6,null))['then'](removeEntity(_0x4b1cd6,null))['catch'](handleError(_0x4b1cd6,null));};exports[_0xb02c('0x4c')]=function(_0x3c07dd,_0x448a9a){return db['UserProfileSection'][_0xb02c('0x4c')]()[_0xb02c('0x26')](respondWithResult(_0x448a9a,null))[_0xb02c('0x4a')](handleError(_0x448a9a,null));};