Built motion from commit 13c3002c.|2.6.9
[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 _0x68cf=['fast-json-patch','request-promise','moment','bluebird','mustache','util','path','squel','crypto','jsforce','to-csv','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','offset','limit','set','Content-Range','reject','save','then','destroy','error','stack','name','index','map','UserProfileSection','rawAttributes','type','key','model','query','keys','filters','intersection','fields','attributes','length','order','sort','where','pick','filter','merge','VIRTUAL','options','count','include','rows','show','params','includeAll','find','catch','create','body','update','describe','eml-format','rimraf','zip-dir'];(function(_0x5794dd,_0x37af14){var _0x1a32a7=function(_0x3637dd){while(--_0x3637dd){_0x5794dd['push'](_0x5794dd['shift']());}};_0x1a32a7(++_0x37af14);}(_0x68cf,0x111));var _0xf68c=function(_0x3b3432,_0x168fda){_0x3b3432=_0x3b3432-0x0;var _0x5b0a79=_0x68cf[_0x3b3432];return _0x5b0a79;};'use strict';var emlformat=require(_0xf68c('0x0'));var rimraf=require(_0xf68c('0x1'));var zipdir=require(_0xf68c('0x2'));var jsonpatch=require(_0xf68c('0x3'));var rp=require(_0xf68c('0x4'));var moment=require(_0xf68c('0x5'));var BPromise=require(_0xf68c('0x6'));var Mustache=require(_0xf68c('0x7'));var util=require(_0xf68c('0x8'));var path=require(_0xf68c('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xf68c('0xa'));var crypto=require(_0xf68c('0xb'));var jsforce=require(_0xf68c('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xf68c('0xd'));var querystring=require(_0xf68c('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xf68c('0xf'));var as=require(_0xf68c('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf68c('0x11'))('api');var utils=require(_0xf68c('0x12'));var config=require(_0xf68c('0x13'));var licenseUtil=require(_0xf68c('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5dad8a,_0x1bc986){_0x1bc986=_0x1bc986||0xcc;return function(_0x553f38){if(_0x553f38){return _0x5dad8a[_0xf68c('0x15')](_0x1bc986);}return _0x5dad8a['status'](_0x1bc986)[_0xf68c('0x16')]();};}function respondWithResult(_0x4cd786,_0x33b6c1){_0x33b6c1=_0x33b6c1||0xc8;return function(_0x29652d){if(_0x29652d){return _0x4cd786[_0xf68c('0x17')](_0x33b6c1)['json'](_0x29652d);}};}function respondWithFilteredResult(_0x349edf,_0x2c6d1a){return function(_0x1c13f0){if(_0x1c13f0){var _0x3db937=typeof _0x2c6d1a[_0xf68c('0x18')]==='undefined'&&typeof _0x2c6d1a['limit']==='undefined';var _0x554e3f=_0x1c13f0['count'];var _0x4f64fc=_0x3db937?0x0:_0x2c6d1a[_0xf68c('0x18')];var _0x1aff8=_0x3db937?_0x1c13f0['count']:_0x2c6d1a[_0xf68c('0x18')]+_0x2c6d1a[_0xf68c('0x19')];var _0x3ac623;if(_0x1aff8>=_0x554e3f){_0x1aff8=_0x554e3f;_0x3ac623=0xc8;}else{_0x3ac623=0xce;}_0x349edf['status'](_0x3ac623);return _0x349edf[_0xf68c('0x1a')](_0xf68c('0x1b'),_0x4f64fc+'-'+_0x1aff8+'/'+_0x554e3f)['json'](_0x1c13f0);}return null;};}function patchUpdates(_0x3aec89){return function(_0x4870d3){try{jsonpatch['apply'](_0x4870d3,_0x3aec89,!![]);}catch(_0x14cdd1){return BPromise[_0xf68c('0x1c')](_0x14cdd1);}return _0x4870d3[_0xf68c('0x1d')]();};}function saveUpdates(_0x5285dd,_0x3b5b35){return function(_0x1c88b8){if(_0x1c88b8){return _0x1c88b8['update'](_0x5285dd)[_0xf68c('0x1e')](function(_0x317932){return _0x317932;});}return null;};}function removeEntity(_0x4b202c,_0x4c8437){return function(_0x44ca78){if(_0x44ca78){return _0x44ca78[_0xf68c('0x1f')]()[_0xf68c('0x1e')](function(){_0x4b202c[_0xf68c('0x17')](0xcc)[_0xf68c('0x16')]();});}};}function handleEntityNotFound(_0x25c0f4,_0xa64b48){return function(_0x4f8b5d){if(!_0x4f8b5d){_0x25c0f4[_0xf68c('0x15')](0x194);}return _0x4f8b5d;};}function handleError(_0x56b9f4,_0xeb5b98){_0xeb5b98=_0xeb5b98||0x1f4;return function(_0x550d08){logger[_0xf68c('0x20')](_0x550d08[_0xf68c('0x21')]);if(_0x550d08[_0xf68c('0x22')]){delete _0x550d08['name'];}_0x56b9f4[_0xf68c('0x17')](_0xeb5b98)['send'](_0x550d08);};}exports[_0xf68c('0x23')]=function(_0x421a5c,_0x39a11d){var _0x933725={},_0xdcf1ef={},_0x976578={'count':0x0,'rows':[]};var _0x4808a8=_[_0xf68c('0x24')](db[_0xf68c('0x25')][_0xf68c('0x26')],function(_0x5dbc9c){return{'name':_0x5dbc9c['fieldName'],'type':_0x5dbc9c[_0xf68c('0x27')][_0xf68c('0x28')]};});_0xdcf1ef[_0xf68c('0x29')]=_[_0xf68c('0x24')](_0x4808a8,'name');_0xdcf1ef[_0xf68c('0x2a')]=_[_0xf68c('0x2b')](_0x421a5c[_0xf68c('0x2a')]);_0xdcf1ef[_0xf68c('0x2c')]=_[_0xf68c('0x2d')](_0xdcf1ef[_0xf68c('0x29')],_0xdcf1ef[_0xf68c('0x2a')]);_0x933725['attributes']=_[_0xf68c('0x2d')](_0xdcf1ef['model'],qs[_0xf68c('0x2e')](_0x421a5c[_0xf68c('0x2a')][_0xf68c('0x2e')]));_0x933725[_0xf68c('0x2f')]=_0x933725['attributes'][_0xf68c('0x30')]?_0x933725['attributes']:_0xdcf1ef['model'];if(!_0x421a5c[_0xf68c('0x2a')]['hasOwnProperty']('nolimit')){_0x933725['limit']=qs[_0xf68c('0x19')](_0x421a5c[_0xf68c('0x2a')]['limit']);_0x933725['offset']=qs['offset'](_0x421a5c[_0xf68c('0x2a')][_0xf68c('0x18')]);}_0x933725[_0xf68c('0x31')]=qs[_0xf68c('0x32')](_0x421a5c['query']['sort']);_0x933725[_0xf68c('0x33')]=qs[_0xf68c('0x2c')](_[_0xf68c('0x34')](_0x421a5c['query'],_0xdcf1ef[_0xf68c('0x2c')]),_0x4808a8);if(_0x421a5c[_0xf68c('0x2a')][_0xf68c('0x35')]){_0x933725['where']=_[_0xf68c('0x36')](_0x933725[_0xf68c('0x33')],{'$or':_[_0xf68c('0x24')](_0x4808a8,function(_0x166b07){if(_0x166b07[_0xf68c('0x27')]!==_0xf68c('0x37')){var _0xd0c9ca={};_0xd0c9ca[_0x166b07['name']]={'$like':'%'+_0x421a5c[_0xf68c('0x2a')]['filter']+'%'};return _0xd0c9ca;}})});}_0x933725=_[_0xf68c('0x36')]({},_0x933725,_0x421a5c[_0xf68c('0x38')]);var _0x2ee305={'where':_0x933725[_0xf68c('0x33')]};return db[_0xf68c('0x25')][_0xf68c('0x39')](_0x2ee305)[_0xf68c('0x1e')](function(_0x56d2c3){_0x976578['count']=_0x56d2c3;if(_0x421a5c[_0xf68c('0x2a')]['includeAll']){_0x933725[_0xf68c('0x3a')]=[{'all':!![]}];}return db['UserProfileSection']['findAll'](_0x933725);})[_0xf68c('0x1e')](function(_0x3b8bf4){_0x976578[_0xf68c('0x3b')]=_0x3b8bf4;return _0x976578;})[_0xf68c('0x1e')](respondWithFilteredResult(_0x39a11d,_0x933725))['catch'](handleError(_0x39a11d,null));};exports[_0xf68c('0x3c')]=function(_0x424075,_0x4c5ce7){var _0x467f7b={'raw':![],'where':{'id':_0x424075[_0xf68c('0x3d')]['id']}},_0xd93267={};_0xd93267[_0xf68c('0x29')]=_[_0xf68c('0x2b')](db[_0xf68c('0x25')][_0xf68c('0x26')]);_0xd93267[_0xf68c('0x2a')]=_['keys'](_0x424075[_0xf68c('0x2a')]);_0xd93267[_0xf68c('0x2c')]=_[_0xf68c('0x2d')](_0xd93267['model'],_0xd93267[_0xf68c('0x2a')]);_0x467f7b[_0xf68c('0x2f')]=_[_0xf68c('0x2d')](_0xd93267[_0xf68c('0x29')],qs[_0xf68c('0x2e')](_0x424075[_0xf68c('0x2a')][_0xf68c('0x2e')]));_0x467f7b[_0xf68c('0x2f')]=_0x467f7b[_0xf68c('0x2f')][_0xf68c('0x30')]?_0x467f7b[_0xf68c('0x2f')]:_0xd93267['model'];if(_0x424075[_0xf68c('0x2a')][_0xf68c('0x3e')]){_0x467f7b['include']=[{'all':!![]}];}_0x467f7b=_[_0xf68c('0x36')]({},_0x467f7b,_0x424075[_0xf68c('0x38')]);return db['UserProfileSection'][_0xf68c('0x3f')](_0x467f7b)['then'](handleEntityNotFound(_0x4c5ce7,null))[_0xf68c('0x1e')](respondWithResult(_0x4c5ce7,null))[_0xf68c('0x40')](handleError(_0x4c5ce7,null));};exports[_0xf68c('0x41')]=function(_0x240153,_0x4ede97){return db[_0xf68c('0x25')][_0xf68c('0x41')](_0x240153[_0xf68c('0x42')],{})[_0xf68c('0x1e')](respondWithResult(_0x4ede97,0xc9))[_0xf68c('0x40')](handleError(_0x4ede97,null));};exports[_0xf68c('0x43')]=function(_0x186dd1,_0x1cde4e){if(_0x186dd1[_0xf68c('0x42')]['id']){delete _0x186dd1[_0xf68c('0x42')]['id'];}return db[_0xf68c('0x25')][_0xf68c('0x3f')]({'where':{'id':_0x186dd1['params']['id']}})['then'](handleEntityNotFound(_0x1cde4e,null))[_0xf68c('0x1e')](saveUpdates(_0x186dd1[_0xf68c('0x42')],null))[_0xf68c('0x1e')](respondWithResult(_0x1cde4e,null))['catch'](handleError(_0x1cde4e,null));};exports[_0xf68c('0x1f')]=function(_0x4b4688,_0x17dad1){return db['UserProfileSection'][_0xf68c('0x3f')]({'where':{'id':_0x4b4688[_0xf68c('0x3d')]['id']}})[_0xf68c('0x1e')](handleEntityNotFound(_0x17dad1,null))[_0xf68c('0x1e')](removeEntity(_0x17dad1,null))[_0xf68c('0x40')](handleError(_0x17dad1,null));};exports[_0xf68c('0x44')]=function(_0x25dd0a,_0x2c6071){return db[_0xf68c('0x25')][_0xf68c('0x44')]()[_0xf68c('0x1e')](respondWithResult(_0x2c6071,null))[_0xf68c('0x40')](handleError(_0x2c6071,null));};