0bb11417f64e026fbd040fc1a6dac693769d0f85
[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 _0xc4ff=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','then','destroy','error','stack','name','index','UserProfileSection','rawAttributes','fieldName','type','key','map','query','keys','filters','intersection','attributes','model','fields','hasOwnProperty','order','sort','pick','where','merge','VIRTUAL','filter','include','findAll','rows','catch','show','params','length','options','create','body','find','describe','eml-format','rimraf','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring'];(function(_0x355aed,_0x33647e){var _0x122f31=function(_0x349636){while(--_0x349636){_0x355aed['push'](_0x355aed['shift']());}};_0x122f31(++_0x33647e);}(_0xc4ff,0x15f));var _0xfc4f=function(_0x9a470b,_0x2e81dc){_0x9a470b=_0x9a470b-0x0;var _0x884638=_0xc4ff[_0x9a470b];return _0x884638;};'use strict';var emlformat=require(_0xfc4f('0x0'));var rimraf=require(_0xfc4f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xfc4f('0x2'));var rp=require('request-promise');var moment=require(_0xfc4f('0x3'));var BPromise=require(_0xfc4f('0x4'));var Mustache=require(_0xfc4f('0x5'));var util=require('util');var path=require(_0xfc4f('0x6'));var sox=require(_0xfc4f('0x7'));var csv=require(_0xfc4f('0x8'));var ejs=require(_0xfc4f('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xfc4f('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xfc4f('0xb'));var deskjs=require(_0xfc4f('0xc'));var toCsv=require(_0xfc4f('0x8'));var querystring=require(_0xfc4f('0xd'));var Papa=require('papaparse');var Redis=require(_0xfc4f('0xe'));var authService=require(_0xfc4f('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xfc4f('0x10'));var hardwareService=require(_0xfc4f('0x11'));var logger=require(_0xfc4f('0x12'))('api');var utils=require('../../config/utils');var config=require(_0xfc4f('0x13'));var licenseUtil=require(_0xfc4f('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x163953,_0xaf6ec3){_0xaf6ec3=_0xaf6ec3||0xcc;return function(_0x58f6b7){if(_0x58f6b7){return _0x163953[_0xfc4f('0x15')](_0xaf6ec3);}return _0x163953[_0xfc4f('0x16')](_0xaf6ec3)[_0xfc4f('0x17')]();};}function respondWithResult(_0x4c36a1,_0x387e52){_0x387e52=_0x387e52||0xc8;return function(_0x21fc2a){if(_0x21fc2a){return _0x4c36a1[_0xfc4f('0x16')](_0x387e52)[_0xfc4f('0x18')](_0x21fc2a);}};}function respondWithFilteredResult(_0x1366ae,_0x1e6227){return function(_0x40386f){if(_0x40386f){var _0x6d827c=typeof _0x1e6227[_0xfc4f('0x19')]===_0xfc4f('0x1a')&&typeof _0x1e6227[_0xfc4f('0x1b')]===_0xfc4f('0x1a');var _0x9a5cdc=_0x40386f[_0xfc4f('0x1c')];var _0x241f36=_0x6d827c?0x0:_0x1e6227[_0xfc4f('0x19')];var _0xe9baa0=_0x6d827c?_0x40386f[_0xfc4f('0x1c')]:_0x1e6227[_0xfc4f('0x19')]+_0x1e6227[_0xfc4f('0x1b')];var _0x52df78;if(_0xe9baa0>=_0x9a5cdc){_0xe9baa0=_0x9a5cdc;_0x52df78=0xc8;}else{_0x52df78=0xce;}_0x1366ae[_0xfc4f('0x16')](_0x52df78);return _0x1366ae[_0xfc4f('0x1d')](_0xfc4f('0x1e'),_0x241f36+'-'+_0xe9baa0+'/'+_0x9a5cdc)[_0xfc4f('0x18')](_0x40386f);}return null;};}function patchUpdates(_0xab72c0){return function(_0x3cea55){try{jsonpatch[_0xfc4f('0x1f')](_0x3cea55,_0xab72c0,!![]);}catch(_0x2b5dbc){return BPromise[_0xfc4f('0x20')](_0x2b5dbc);}return _0x3cea55['save']();};}function saveUpdates(_0x5aa1e0,_0x41dac8){return function(_0x59825a){if(_0x59825a){return _0x59825a[_0xfc4f('0x21')](_0x5aa1e0)[_0xfc4f('0x22')](function(_0x1deed7){return _0x1deed7;});}return null;};}function removeEntity(_0x4d1b36,_0xf7dd2f){return function(_0x430ce8){if(_0x430ce8){return _0x430ce8[_0xfc4f('0x23')]()[_0xfc4f('0x22')](function(){_0x4d1b36['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x58e27e,_0x2cee2b){return function(_0x127885){if(!_0x127885){_0x58e27e[_0xfc4f('0x15')](0x194);}return _0x127885;};}function handleError(_0x23e3db,_0x430f14){_0x430f14=_0x430f14||0x1f4;return function(_0x57907f){logger[_0xfc4f('0x24')](_0x57907f[_0xfc4f('0x25')]);if(_0x57907f[_0xfc4f('0x26')]){delete _0x57907f[_0xfc4f('0x26')];}_0x23e3db[_0xfc4f('0x16')](_0x430f14)['send'](_0x57907f);};}exports[_0xfc4f('0x27')]=function(_0x159535,_0x98dfd2){var _0x3dfccd={},_0x218398={},_0xcd34d3={'count':0x0,'rows':[]};var _0x5b701e=_['map'](db[_0xfc4f('0x28')][_0xfc4f('0x29')],function(_0x54a167){return{'name':_0x54a167[_0xfc4f('0x2a')],'type':_0x54a167[_0xfc4f('0x2b')][_0xfc4f('0x2c')]};});_0x218398['model']=_[_0xfc4f('0x2d')](_0x5b701e,_0xfc4f('0x26'));_0x218398[_0xfc4f('0x2e')]=_[_0xfc4f('0x2f')](_0x159535[_0xfc4f('0x2e')]);_0x218398[_0xfc4f('0x30')]=_[_0xfc4f('0x31')](_0x218398['model'],_0x218398[_0xfc4f('0x2e')]);_0x3dfccd[_0xfc4f('0x32')]=_[_0xfc4f('0x31')](_0x218398[_0xfc4f('0x33')],qs[_0xfc4f('0x34')](_0x159535[_0xfc4f('0x2e')][_0xfc4f('0x34')]));_0x3dfccd[_0xfc4f('0x32')]=_0x3dfccd['attributes']['length']?_0x3dfccd[_0xfc4f('0x32')]:_0x218398[_0xfc4f('0x33')];if(!_0x159535[_0xfc4f('0x2e')][_0xfc4f('0x35')]('nolimit')){_0x3dfccd[_0xfc4f('0x1b')]=qs[_0xfc4f('0x1b')](_0x159535[_0xfc4f('0x2e')][_0xfc4f('0x1b')]);_0x3dfccd[_0xfc4f('0x19')]=qs[_0xfc4f('0x19')](_0x159535['query'][_0xfc4f('0x19')]);}_0x3dfccd[_0xfc4f('0x36')]=qs[_0xfc4f('0x37')](_0x159535['query'][_0xfc4f('0x37')]);_0x3dfccd['where']=qs['filters'](_[_0xfc4f('0x38')](_0x159535[_0xfc4f('0x2e')],_0x218398[_0xfc4f('0x30')]),_0x5b701e);if(_0x159535[_0xfc4f('0x2e')]['filter']){_0x3dfccd[_0xfc4f('0x39')]=_[_0xfc4f('0x3a')](_0x3dfccd[_0xfc4f('0x39')],{'$or':_[_0xfc4f('0x2d')](_0x5b701e,function(_0x19fb79){if(_0x19fb79['type']!==_0xfc4f('0x3b')){var _0x6fcd8d={};_0x6fcd8d[_0x19fb79[_0xfc4f('0x26')]]={'$like':'%'+_0x159535[_0xfc4f('0x2e')][_0xfc4f('0x3c')]+'%'};return _0x6fcd8d;}})});}_0x3dfccd=_[_0xfc4f('0x3a')]({},_0x3dfccd,_0x159535['options']);var _0x302a75={'where':_0x3dfccd[_0xfc4f('0x39')]};return db[_0xfc4f('0x28')][_0xfc4f('0x1c')](_0x302a75)[_0xfc4f('0x22')](function(_0x3d9450){_0xcd34d3[_0xfc4f('0x1c')]=_0x3d9450;if(_0x159535[_0xfc4f('0x2e')]['includeAll']){_0x3dfccd[_0xfc4f('0x3d')]=[{'all':!![]}];}return db[_0xfc4f('0x28')][_0xfc4f('0x3e')](_0x3dfccd);})[_0xfc4f('0x22')](function(_0x597b83){_0xcd34d3[_0xfc4f('0x3f')]=_0x597b83;return _0xcd34d3;})[_0xfc4f('0x22')](respondWithFilteredResult(_0x98dfd2,_0x3dfccd))[_0xfc4f('0x40')](handleError(_0x98dfd2,null));};exports[_0xfc4f('0x41')]=function(_0x28557a,_0x27b96d){var _0x1d144f={'raw':![],'where':{'id':_0x28557a[_0xfc4f('0x42')]['id']}},_0x4f1d1c={};_0x4f1d1c['model']=_[_0xfc4f('0x2f')](db[_0xfc4f('0x28')][_0xfc4f('0x29')]);_0x4f1d1c['query']=_[_0xfc4f('0x2f')](_0x28557a[_0xfc4f('0x2e')]);_0x4f1d1c[_0xfc4f('0x30')]=_[_0xfc4f('0x31')](_0x4f1d1c['model'],_0x4f1d1c[_0xfc4f('0x2e')]);_0x1d144f[_0xfc4f('0x32')]=_[_0xfc4f('0x31')](_0x4f1d1c[_0xfc4f('0x33')],qs['fields'](_0x28557a[_0xfc4f('0x2e')][_0xfc4f('0x34')]));_0x1d144f[_0xfc4f('0x32')]=_0x1d144f['attributes'][_0xfc4f('0x43')]?_0x1d144f[_0xfc4f('0x32')]:_0x4f1d1c[_0xfc4f('0x33')];if(_0x28557a[_0xfc4f('0x2e')]['includeAll']){_0x1d144f[_0xfc4f('0x3d')]=[{'all':!![]}];}_0x1d144f=_['merge']({},_0x1d144f,_0x28557a[_0xfc4f('0x44')]);return db[_0xfc4f('0x28')]['find'](_0x1d144f)[_0xfc4f('0x22')](handleEntityNotFound(_0x27b96d,null))[_0xfc4f('0x22')](respondWithResult(_0x27b96d,null))[_0xfc4f('0x40')](handleError(_0x27b96d,null));};exports['create']=function(_0x1fbdd5,_0x13f6fc){return db[_0xfc4f('0x28')][_0xfc4f('0x45')](_0x1fbdd5[_0xfc4f('0x46')],{})[_0xfc4f('0x22')](respondWithResult(_0x13f6fc,0xc9))['catch'](handleError(_0x13f6fc,null));};exports[_0xfc4f('0x21')]=function(_0x3bacca,_0x481115){if(_0x3bacca[_0xfc4f('0x46')]['id']){delete _0x3bacca[_0xfc4f('0x46')]['id'];}return db['UserProfileSection'][_0xfc4f('0x47')]({'where':{'id':_0x3bacca[_0xfc4f('0x42')]['id']}})[_0xfc4f('0x22')](handleEntityNotFound(_0x481115,null))['then'](saveUpdates(_0x3bacca['body'],null))[_0xfc4f('0x22')](respondWithResult(_0x481115,null))[_0xfc4f('0x40')](handleError(_0x481115,null));};exports['destroy']=function(_0x184dcd,_0x46d478){return db[_0xfc4f('0x28')][_0xfc4f('0x47')]({'where':{'id':_0x184dcd[_0xfc4f('0x42')]['id']}})['then'](handleEntityNotFound(_0x46d478,null))[_0xfc4f('0x22')](removeEntity(_0x46d478,null))['catch'](handleError(_0x46d478,null));};exports['describe']=function(_0x1f6120,_0xc811f8){return db[_0xfc4f('0x28')][_0xfc4f('0x48')]()[_0xfc4f('0x22')](respondWithResult(_0xc811f8,null))['catch'](handleError(_0xc811f8,null));};