Built motion from commit 598073ad.|2.5.44
[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 _0x0ff7=['intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','then','includeAll','include','rows','catch','show','params','keys','create','body','update','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','to-csv','ejs','fs-extra','lodash','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','save','error','name','send','UserProfileSection','rawAttributes','fieldName','type','key','map','query','filters'];(function(_0x23e5fd,_0x2c6da6){var _0xab592b=function(_0x75559a){while(--_0x75559a){_0x23e5fd['push'](_0x23e5fd['shift']());}};_0xab592b(++_0x2c6da6);}(_0x0ff7,0x68));var _0x70ff=function(_0x3070dc,_0x40cf11){_0x3070dc=_0x3070dc-0x0;var _0x431489=_0x0ff7[_0x3070dc];return _0x431489;};'use strict';var emlformat=require(_0x70ff('0x0'));var rimraf=require(_0x70ff('0x1'));var zipdir=require(_0x70ff('0x2'));var jsonpatch=require(_0x70ff('0x3'));var rp=require(_0x70ff('0x4'));var moment=require(_0x70ff('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x70ff('0x6'));var util=require(_0x70ff('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x70ff('0x8'));var ejs=require(_0x70ff('0x9'));var fs=require('fs');var fs_extra=require(_0x70ff('0xa'));var _=require(_0x70ff('0xb'));var squel=require('squel');var crypto=require(_0x70ff('0xc'));var jsforce=require(_0x70ff('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x70ff('0x8'));var querystring=require('querystring');var Papa=require(_0x70ff('0xe'));var Redis=require(_0x70ff('0xf'));var authService=require(_0x70ff('0x10'));var qs=require(_0x70ff('0x11'));var as=require(_0x70ff('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x70ff('0x13'))(_0x70ff('0x14'));var utils=require(_0x70ff('0x15'));var config=require(_0x70ff('0x16'));var licenseUtil=require(_0x70ff('0x17'));var db=require(_0x70ff('0x18'))['db'];function respondWithStatusCode(_0x236e32,_0x22cece){_0x22cece=_0x22cece||0xcc;return function(_0x1523d7){if(_0x1523d7){return _0x236e32[_0x70ff('0x19')](_0x22cece);}return _0x236e32[_0x70ff('0x1a')](_0x22cece)[_0x70ff('0x1b')]();};}function respondWithResult(_0x413b9f,_0x26251d){_0x26251d=_0x26251d||0xc8;return function(_0x24db0f){if(_0x24db0f){return _0x413b9f[_0x70ff('0x1a')](_0x26251d)[_0x70ff('0x1c')](_0x24db0f);}};}function respondWithFilteredResult(_0x228c2c,_0x425fad){return function(_0x59ecf6){if(_0x59ecf6){var _0x268ae1=typeof _0x425fad[_0x70ff('0x1d')]===_0x70ff('0x1e')&&typeof _0x425fad[_0x70ff('0x1f')]===_0x70ff('0x1e');var _0x59bde9=_0x59ecf6[_0x70ff('0x20')];var _0x3e0232=_0x268ae1?0x0:_0x425fad[_0x70ff('0x1d')];var _0x533add=_0x268ae1?_0x59ecf6['count']:_0x425fad[_0x70ff('0x1d')]+_0x425fad['limit'];var _0x542ad3;if(_0x533add>=_0x59bde9){_0x533add=_0x59bde9;_0x542ad3=0xc8;}else{_0x542ad3=0xce;}_0x228c2c[_0x70ff('0x1a')](_0x542ad3);return _0x228c2c[_0x70ff('0x21')](_0x70ff('0x22'),_0x3e0232+'-'+_0x533add+'/'+_0x59bde9)[_0x70ff('0x1c')](_0x59ecf6);}return null;};}function patchUpdates(_0x56ad12){return function(_0x262db3){try{jsonpatch[_0x70ff('0x23')](_0x262db3,_0x56ad12,!![]);}catch(_0x3ce4e8){return BPromise['reject'](_0x3ce4e8);}return _0x262db3[_0x70ff('0x24')]();};}function saveUpdates(_0x31e699,_0xfd7143){return function(_0x571823){if(_0x571823){return _0x571823['update'](_0x31e699)['then'](function(_0x56f82c){return _0x56f82c;});}return null;};}function removeEntity(_0x417a32,_0x25a1dc){return function(_0x334bbc){if(_0x334bbc){return _0x334bbc['destroy']()['then'](function(){_0x417a32[_0x70ff('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x214614,_0x1c97a7){return function(_0x2226f4){if(!_0x2226f4){_0x214614[_0x70ff('0x19')](0x194);}return _0x2226f4;};}function handleError(_0x2cecc7,_0x210a4d){_0x210a4d=_0x210a4d||0x1f4;return function(_0x3e310d){logger[_0x70ff('0x25')](_0x3e310d['stack']);if(_0x3e310d[_0x70ff('0x26')]){delete _0x3e310d[_0x70ff('0x26')];}_0x2cecc7[_0x70ff('0x1a')](_0x210a4d)[_0x70ff('0x27')](_0x3e310d);};}exports['index']=function(_0x481a79,_0x4798fb){var _0x242897={},_0x56b58d={},_0x130248={'count':0x0,'rows':[]};var _0x9e7235=_['map'](db[_0x70ff('0x28')][_0x70ff('0x29')],function(_0x21fe92){return{'name':_0x21fe92[_0x70ff('0x2a')],'type':_0x21fe92[_0x70ff('0x2b')][_0x70ff('0x2c')]};});_0x56b58d['model']=_[_0x70ff('0x2d')](_0x9e7235,_0x70ff('0x26'));_0x56b58d[_0x70ff('0x2e')]=_['keys'](_0x481a79['query']);_0x56b58d[_0x70ff('0x2f')]=_[_0x70ff('0x30')](_0x56b58d[_0x70ff('0x31')],_0x56b58d['query']);_0x242897[_0x70ff('0x32')]=_[_0x70ff('0x30')](_0x56b58d[_0x70ff('0x31')],qs[_0x70ff('0x33')](_0x481a79[_0x70ff('0x2e')][_0x70ff('0x33')]));_0x242897[_0x70ff('0x32')]=_0x242897[_0x70ff('0x32')][_0x70ff('0x34')]?_0x242897['attributes']:_0x56b58d[_0x70ff('0x31')];if(!_0x481a79[_0x70ff('0x2e')][_0x70ff('0x35')](_0x70ff('0x36'))){_0x242897[_0x70ff('0x1f')]=qs[_0x70ff('0x1f')](_0x481a79[_0x70ff('0x2e')]['limit']);_0x242897['offset']=qs[_0x70ff('0x1d')](_0x481a79[_0x70ff('0x2e')][_0x70ff('0x1d')]);}_0x242897[_0x70ff('0x37')]=qs[_0x70ff('0x38')](_0x481a79[_0x70ff('0x2e')][_0x70ff('0x38')]);_0x242897[_0x70ff('0x39')]=qs['filters'](_[_0x70ff('0x3a')](_0x481a79[_0x70ff('0x2e')],_0x56b58d[_0x70ff('0x2f')]),_0x9e7235);if(_0x481a79[_0x70ff('0x2e')][_0x70ff('0x3b')]){_0x242897[_0x70ff('0x39')]=_['merge'](_0x242897['where'],{'$or':_[_0x70ff('0x2d')](_0x9e7235,function(_0x577322){if(_0x577322[_0x70ff('0x2b')]!==_0x70ff('0x3c')){var _0x22b137={};_0x22b137[_0x577322[_0x70ff('0x26')]]={'$like':'%'+_0x481a79[_0x70ff('0x2e')][_0x70ff('0x3b')]+'%'};return _0x22b137;}})});}_0x242897=_[_0x70ff('0x3d')]({},_0x242897,_0x481a79[_0x70ff('0x3e')]);var _0x3dd6e9={'where':_0x242897['where']};return db[_0x70ff('0x28')][_0x70ff('0x20')](_0x3dd6e9)[_0x70ff('0x3f')](function(_0x161ee0){_0x130248[_0x70ff('0x20')]=_0x161ee0;if(_0x481a79[_0x70ff('0x2e')][_0x70ff('0x40')]){_0x242897[_0x70ff('0x41')]=[{'all':!![]}];}return db[_0x70ff('0x28')]['findAll'](_0x242897);})[_0x70ff('0x3f')](function(_0x528e60){_0x130248[_0x70ff('0x42')]=_0x528e60;return _0x130248;})[_0x70ff('0x3f')](respondWithFilteredResult(_0x4798fb,_0x242897))[_0x70ff('0x43')](handleError(_0x4798fb,null));};exports[_0x70ff('0x44')]=function(_0x35bb3f,_0x35a3a5){var _0x34873d={'raw':![],'where':{'id':_0x35bb3f[_0x70ff('0x45')]['id']}},_0x579935={};_0x579935[_0x70ff('0x31')]=_[_0x70ff('0x46')](db['UserProfileSection'][_0x70ff('0x29')]);_0x579935['query']=_['keys'](_0x35bb3f[_0x70ff('0x2e')]);_0x579935[_0x70ff('0x2f')]=_[_0x70ff('0x30')](_0x579935[_0x70ff('0x31')],_0x579935[_0x70ff('0x2e')]);_0x34873d['attributes']=_['intersection'](_0x579935[_0x70ff('0x31')],qs['fields'](_0x35bb3f[_0x70ff('0x2e')]['fields']));_0x34873d[_0x70ff('0x32')]=_0x34873d[_0x70ff('0x32')][_0x70ff('0x34')]?_0x34873d['attributes']:_0x579935[_0x70ff('0x31')];if(_0x35bb3f[_0x70ff('0x2e')][_0x70ff('0x40')]){_0x34873d[_0x70ff('0x41')]=[{'all':!![]}];}_0x34873d=_['merge']({},_0x34873d,_0x35bb3f[_0x70ff('0x3e')]);return db[_0x70ff('0x28')]['find'](_0x34873d)[_0x70ff('0x3f')](handleEntityNotFound(_0x35a3a5,null))['then'](respondWithResult(_0x35a3a5,null))[_0x70ff('0x43')](handleError(_0x35a3a5,null));};exports[_0x70ff('0x47')]=function(_0x35ebbe,_0x561b28){return db['UserProfileSection'][_0x70ff('0x47')](_0x35ebbe[_0x70ff('0x48')],{})[_0x70ff('0x3f')](respondWithResult(_0x561b28,0xc9))[_0x70ff('0x43')](handleError(_0x561b28,null));};exports[_0x70ff('0x49')]=function(_0x5db3bb,_0x34c293){if(_0x5db3bb[_0x70ff('0x48')]['id']){delete _0x5db3bb['body']['id'];}return db['UserProfileSection']['find']({'where':{'id':_0x5db3bb[_0x70ff('0x45')]['id']}})[_0x70ff('0x3f')](handleEntityNotFound(_0x34c293,null))['then'](saveUpdates(_0x5db3bb[_0x70ff('0x48')],null))['then'](respondWithResult(_0x34c293,null))[_0x70ff('0x43')](handleError(_0x34c293,null));};exports['destroy']=function(_0x420848,_0x598705){return db[_0x70ff('0x28')][_0x70ff('0x4a')]({'where':{'id':_0x420848['params']['id']}})['then'](handleEntityNotFound(_0x598705,null))[_0x70ff('0x3f')](removeEntity(_0x598705,null))[_0x70ff('0x43')](handleError(_0x598705,null));};exports[_0x70ff('0x4b')]=function(_0x68abd8,_0x32da6d){return db[_0x70ff('0x28')][_0x70ff('0x4b')]()['then'](respondWithResult(_0x32da6d,null))['catch'](handleError(_0x32da6d,null));};