ec5dfb4ae6fda5fec373cec7fe4ad216d223daa6
[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 _0x7fcc=['pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','keys','options','find','create','body','params','describe','eml-format','rimraf','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','destroy','then','end','error','stack','name','map','UserProfileSection','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','where'];(function(_0xd68f5f,_0x2b068b){var _0x535998=function(_0x4d00df){while(--_0x4d00df){_0xd68f5f['push'](_0xd68f5f['shift']());}};_0x535998(++_0x2b068b);}(_0x7fcc,0xad));var _0xc7fc=function(_0x2a606c,_0x158454){_0x2a606c=_0x2a606c-0x0;var _0x8f28fa=_0x7fcc[_0x2a606c];return _0x8f28fa;};'use strict';var emlformat=require(_0xc7fc('0x0'));var rimraf=require(_0xc7fc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xc7fc('0x2'));var moment=require(_0xc7fc('0x3'));var BPromise=require(_0xc7fc('0x4'));var Mustache=require(_0xc7fc('0x5'));var util=require('util');var path=require(_0xc7fc('0x6'));var sox=require(_0xc7fc('0x7'));var csv=require(_0xc7fc('0x8'));var ejs=require(_0xc7fc('0x9'));var fs=require('fs');var fs_extra=require(_0xc7fc('0xa'));var _=require(_0xc7fc('0xb'));var squel=require(_0xc7fc('0xc'));var crypto=require(_0xc7fc('0xd'));var jsforce=require(_0xc7fc('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xc7fc('0x8'));var querystring=require(_0xc7fc('0xf'));var Papa=require(_0xc7fc('0x10'));var Redis=require(_0xc7fc('0x11'));var authService=require(_0xc7fc('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xc7fc('0x13'));var hardwareService=require(_0xc7fc('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0xc7fc('0x15'));var config=require(_0xc7fc('0x16'));var licenseUtil=require(_0xc7fc('0x17'));var db=require(_0xc7fc('0x18'))['db'];function respondWithStatusCode(_0x3dd7d8,_0x564f03){_0x564f03=_0x564f03||0xcc;return function(_0x25d971){if(_0x25d971){return _0x3dd7d8[_0xc7fc('0x19')](_0x564f03);}return _0x3dd7d8[_0xc7fc('0x1a')](_0x564f03)['end']();};}function respondWithResult(_0x38b588,_0x51a4ae){_0x51a4ae=_0x51a4ae||0xc8;return function(_0x2b9f60){if(_0x2b9f60){return _0x38b588[_0xc7fc('0x1a')](_0x51a4ae)[_0xc7fc('0x1b')](_0x2b9f60);}};}function respondWithFilteredResult(_0x3cf77d,_0x46d7e4){return function(_0x53b6fb){if(_0x53b6fb){var _0x51cc64=typeof _0x46d7e4['offset']===_0xc7fc('0x1c')&&typeof _0x46d7e4[_0xc7fc('0x1d')]===_0xc7fc('0x1c');var _0x7073c5=_0x53b6fb[_0xc7fc('0x1e')];var _0x20cbd9=_0x51cc64?0x0:_0x46d7e4[_0xc7fc('0x1f')];var _0x20d618=_0x51cc64?_0x53b6fb[_0xc7fc('0x1e')]:_0x46d7e4[_0xc7fc('0x1f')]+_0x46d7e4['limit'];var _0x2cccc9;if(_0x20d618>=_0x7073c5){_0x20d618=_0x7073c5;_0x2cccc9=0xc8;}else{_0x2cccc9=0xce;}_0x3cf77d[_0xc7fc('0x1a')](_0x2cccc9);return _0x3cf77d[_0xc7fc('0x20')](_0xc7fc('0x21'),_0x20cbd9+'-'+_0x20d618+'/'+_0x7073c5)['json'](_0x53b6fb);}return null;};}function patchUpdates(_0xc3d470){return function(_0x52c89c){try{jsonpatch[_0xc7fc('0x22')](_0x52c89c,_0xc3d470,!![]);}catch(_0x111ec7){return BPromise[_0xc7fc('0x23')](_0x111ec7);}return _0x52c89c[_0xc7fc('0x24')]();};}function saveUpdates(_0xaa6036,_0x2d729c){return function(_0x2b4edf){if(_0x2b4edf){return _0x2b4edf[_0xc7fc('0x25')](_0xaa6036)['then'](function(_0x24e856){return _0x24e856;});}return null;};}function removeEntity(_0x3e62e8,_0x5b7ab0){return function(_0xb69fd3){if(_0xb69fd3){return _0xb69fd3[_0xc7fc('0x26')]()[_0xc7fc('0x27')](function(){_0x3e62e8[_0xc7fc('0x1a')](0xcc)[_0xc7fc('0x28')]();});}};}function handleEntityNotFound(_0x135d71,_0x42231f){return function(_0x2366ed){if(!_0x2366ed){_0x135d71['sendStatus'](0x194);}return _0x2366ed;};}function handleError(_0x16d852,_0x3e568f){_0x3e568f=_0x3e568f||0x1f4;return function(_0x535671){logger[_0xc7fc('0x29')](_0x535671[_0xc7fc('0x2a')]);if(_0x535671['name']){delete _0x535671[_0xc7fc('0x2b')];}_0x16d852[_0xc7fc('0x1a')](_0x3e568f)['send'](_0x535671);};}exports['index']=function(_0x599be0,_0x552a1f){var _0x1f65f0={},_0x3032cc={},_0x265b68={'count':0x0,'rows':[]};var _0x319215=_[_0xc7fc('0x2c')](db[_0xc7fc('0x2d')][_0xc7fc('0x2e')],function(_0x5c954d){return{'name':_0x5c954d[_0xc7fc('0x2f')],'type':_0x5c954d[_0xc7fc('0x30')][_0xc7fc('0x31')]};});_0x3032cc['model']=_[_0xc7fc('0x2c')](_0x319215,_0xc7fc('0x2b'));_0x3032cc[_0xc7fc('0x32')]=_['keys'](_0x599be0['query']);_0x3032cc[_0xc7fc('0x33')]=_[_0xc7fc('0x34')](_0x3032cc[_0xc7fc('0x35')],_0x3032cc[_0xc7fc('0x32')]);_0x1f65f0[_0xc7fc('0x36')]=_[_0xc7fc('0x34')](_0x3032cc[_0xc7fc('0x35')],qs['fields'](_0x599be0[_0xc7fc('0x32')][_0xc7fc('0x37')]));_0x1f65f0['attributes']=_0x1f65f0[_0xc7fc('0x36')][_0xc7fc('0x38')]?_0x1f65f0[_0xc7fc('0x36')]:_0x3032cc[_0xc7fc('0x35')];if(!_0x599be0['query'][_0xc7fc('0x39')](_0xc7fc('0x3a'))){_0x1f65f0[_0xc7fc('0x1d')]=qs[_0xc7fc('0x1d')](_0x599be0[_0xc7fc('0x32')][_0xc7fc('0x1d')]);_0x1f65f0['offset']=qs[_0xc7fc('0x1f')](_0x599be0[_0xc7fc('0x32')][_0xc7fc('0x1f')]);}_0x1f65f0['order']=qs[_0xc7fc('0x3b')](_0x599be0[_0xc7fc('0x32')]['sort']);_0x1f65f0[_0xc7fc('0x3c')]=qs['filters'](_[_0xc7fc('0x3d')](_0x599be0[_0xc7fc('0x32')],_0x3032cc['filters']),_0x319215);if(_0x599be0[_0xc7fc('0x32')][_0xc7fc('0x3e')]){_0x1f65f0[_0xc7fc('0x3c')]=_[_0xc7fc('0x3f')](_0x1f65f0['where'],{'$or':_['map'](_0x319215,function(_0xbdf74b){if(_0xbdf74b[_0xc7fc('0x30')]!==_0xc7fc('0x40')){var _0x572eec={};_0x572eec[_0xbdf74b[_0xc7fc('0x2b')]]={'$like':'%'+_0x599be0[_0xc7fc('0x32')][_0xc7fc('0x3e')]+'%'};return _0x572eec;}})});}_0x1f65f0=_[_0xc7fc('0x3f')]({},_0x1f65f0,_0x599be0['options']);var _0x40bf9a={'where':_0x1f65f0['where']};return db[_0xc7fc('0x2d')][_0xc7fc('0x1e')](_0x40bf9a)[_0xc7fc('0x27')](function(_0x395b71){_0x265b68['count']=_0x395b71;if(_0x599be0['query'][_0xc7fc('0x41')]){_0x1f65f0[_0xc7fc('0x42')]=[{'all':!![]}];}return db['UserProfileSection'][_0xc7fc('0x43')](_0x1f65f0);})[_0xc7fc('0x27')](function(_0x2aec30){_0x265b68[_0xc7fc('0x44')]=_0x2aec30;return _0x265b68;})[_0xc7fc('0x27')](respondWithFilteredResult(_0x552a1f,_0x1f65f0))[_0xc7fc('0x45')](handleError(_0x552a1f,null));};exports[_0xc7fc('0x46')]=function(_0x1acd6f,_0xcab320){var _0x627d3f={'raw':![],'where':{'id':_0x1acd6f['params']['id']}},_0x4ec4fd={};_0x4ec4fd[_0xc7fc('0x35')]=_[_0xc7fc('0x47')](db[_0xc7fc('0x2d')][_0xc7fc('0x2e')]);_0x4ec4fd['query']=_['keys'](_0x1acd6f['query']);_0x4ec4fd[_0xc7fc('0x33')]=_[_0xc7fc('0x34')](_0x4ec4fd[_0xc7fc('0x35')],_0x4ec4fd['query']);_0x627d3f[_0xc7fc('0x36')]=_['intersection'](_0x4ec4fd[_0xc7fc('0x35')],qs[_0xc7fc('0x37')](_0x1acd6f[_0xc7fc('0x32')]['fields']));_0x627d3f['attributes']=_0x627d3f['attributes']['length']?_0x627d3f[_0xc7fc('0x36')]:_0x4ec4fd[_0xc7fc('0x35')];if(_0x1acd6f[_0xc7fc('0x32')][_0xc7fc('0x41')]){_0x627d3f[_0xc7fc('0x42')]=[{'all':!![]}];}_0x627d3f=_['merge']({},_0x627d3f,_0x1acd6f[_0xc7fc('0x48')]);return db['UserProfileSection'][_0xc7fc('0x49')](_0x627d3f)['then'](handleEntityNotFound(_0xcab320,null))[_0xc7fc('0x27')](respondWithResult(_0xcab320,null))[_0xc7fc('0x45')](handleError(_0xcab320,null));};exports[_0xc7fc('0x4a')]=function(_0x1dd1fe,_0x4718be){return db[_0xc7fc('0x2d')][_0xc7fc('0x4a')](_0x1dd1fe[_0xc7fc('0x4b')],{})[_0xc7fc('0x27')](respondWithResult(_0x4718be,0xc9))[_0xc7fc('0x45')](handleError(_0x4718be,null));};exports[_0xc7fc('0x25')]=function(_0x481900,_0x4d67a7){if(_0x481900[_0xc7fc('0x4b')]['id']){delete _0x481900['body']['id'];}return db[_0xc7fc('0x2d')][_0xc7fc('0x49')]({'where':{'id':_0x481900[_0xc7fc('0x4c')]['id']}})['then'](handleEntityNotFound(_0x4d67a7,null))['then'](saveUpdates(_0x481900[_0xc7fc('0x4b')],null))[_0xc7fc('0x27')](respondWithResult(_0x4d67a7,null))[_0xc7fc('0x45')](handleError(_0x4d67a7,null));};exports[_0xc7fc('0x26')]=function(_0x30efd5,_0xc77fb5){return db[_0xc7fc('0x2d')]['find']({'where':{'id':_0x30efd5[_0xc7fc('0x4c')]['id']}})['then'](handleEntityNotFound(_0xc77fb5,null))[_0xc7fc('0x27')](removeEntity(_0xc77fb5,null))[_0xc7fc('0x45')](handleError(_0xc77fb5,null));};exports[_0xc7fc('0x4d')]=function(_0x503797,_0x3f54f7){return db['UserProfileSection']['describe']()[_0xc7fc('0x27')](respondWithResult(_0x3f54f7,null))['catch'](handleError(_0x3f54f7,null));};