Built motion from commit (unavailable).|2.5.13
[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 _0xdafb=['error','name','send','map','UserProfileSection','rawAttributes','fieldName','type','key','keys','model','query','fields','attributes','nolimit','order','sort','filters','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','intersection','length','create','body','find','params','destroy','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','to-csv','ejs','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','end'];(function(_0x122096,_0x60c295){var _0x3d1966=function(_0x3d569e){while(--_0x3d569e){_0x122096['push'](_0x122096['shift']());}};_0x3d1966(++_0x60c295);}(_0xdafb,0x10a));var _0xbdaf=function(_0x1ef6d0,_0x516bac){_0x1ef6d0=_0x1ef6d0-0x0;var _0x2a87e3=_0xdafb[_0x1ef6d0];return _0x2a87e3;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xbdaf('0x0'));var rimraf=require(_0xbdaf('0x1'));var zipdir=require(_0xbdaf('0x2'));var jsonpatch=require(_0xbdaf('0x3'));var rp=require(_0xbdaf('0x4'));var moment=require(_0xbdaf('0x5'));var BPromise=require(_0xbdaf('0x6'));var Mustache=require('mustache');var util=require(_0xbdaf('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0xbdaf('0x8'));var ejs=require(_0xbdaf('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xbdaf('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xbdaf('0xb'));var toCsv=require(_0xbdaf('0x8'));var querystring=require(_0xbdaf('0xc'));var Papa=require(_0xbdaf('0xd'));var Redis=require(_0xbdaf('0xe'));var authService=require(_0xbdaf('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xbdaf('0x10'));var hardwareService=require(_0xbdaf('0x11'));var logger=require(_0xbdaf('0x12'))(_0xbdaf('0x13'));var utils=require(_0xbdaf('0x14'));var config=require(_0xbdaf('0x15'));var licenseUtil=require(_0xbdaf('0x16'));var db=require(_0xbdaf('0x17'))['db'];function respondWithStatusCode(_0x23a1ee,_0x5733a0){_0x5733a0=_0x5733a0||0xcc;return function(_0x595aea){if(_0x595aea){return _0x23a1ee[_0xbdaf('0x18')](_0x5733a0);}return _0x23a1ee[_0xbdaf('0x19')](_0x5733a0)['end']();};}function respondWithResult(_0x2be207,_0x4f5d77){_0x4f5d77=_0x4f5d77||0xc8;return function(_0xacff2b){if(_0xacff2b){return _0x2be207[_0xbdaf('0x19')](_0x4f5d77)[_0xbdaf('0x1a')](_0xacff2b);}};}function respondWithFilteredResult(_0x19f919,_0x4231ae){return function(_0x56c281){if(_0x56c281){var _0x27f28c=_0x56c281[_0xbdaf('0x1b')],_0x23e927=_0x4231ae[_0xbdaf('0x1c')],_0x598587=_0x4231ae[_0xbdaf('0x1c')]+_0x4231ae[_0xbdaf('0x1d')],_0x47b8a8;if(_0x598587>=_0x27f28c){_0x598587=_0x27f28c;_0x47b8a8=0xc8;}else{_0x47b8a8=0xce;}_0x19f919['status'](_0x47b8a8);return _0x19f919[_0xbdaf('0x1e')](_0xbdaf('0x1f'),_0x23e927+'-'+_0x598587+'/'+_0x27f28c)[_0xbdaf('0x1a')](_0x56c281);}return null;};}function patchUpdates(_0x190109){return function(_0x533b3b){try{jsonpatch[_0xbdaf('0x20')](_0x533b3b,_0x190109,!![]);}catch(_0x1a0319){return BPromise[_0xbdaf('0x21')](_0x1a0319);}return _0x533b3b[_0xbdaf('0x22')]();};}function saveUpdates(_0x2e324a,_0x2a89b5){return function(_0x11cb19){if(_0x11cb19){return _0x11cb19[_0xbdaf('0x23')](_0x2e324a)[_0xbdaf('0x24')](function(_0x2d07ef){return _0x2d07ef;});}return null;};}function removeEntity(_0x160d2b,_0x3fd8ff){return function(_0x508a26){if(_0x508a26){return _0x508a26['destroy']()[_0xbdaf('0x24')](function(){_0x160d2b[_0xbdaf('0x19')](0xcc)[_0xbdaf('0x25')]();});}};}function handleEntityNotFound(_0xb11169,_0x4757ee){return function(_0x1fcc46){if(!_0x1fcc46){_0xb11169[_0xbdaf('0x18')](0x194);}return _0x1fcc46;};}function handleError(_0x31af57,_0x493506){_0x493506=_0x493506||0x1f4;return function(_0x3d88ec){logger[_0xbdaf('0x26')](_0x3d88ec['stack']);if(_0x3d88ec['name']){delete _0x3d88ec[_0xbdaf('0x27')];}_0x31af57[_0xbdaf('0x19')](_0x493506)[_0xbdaf('0x28')](_0x3d88ec);};}exports['index']=function(_0x31018e,_0x40391a){var _0x495d76={},_0x363353={},_0x57676c={'count':0x0,'rows':[]};var _0x55ddab=_[_0xbdaf('0x29')](db[_0xbdaf('0x2a')][_0xbdaf('0x2b')],function(_0x255047){return{'name':_0x255047[_0xbdaf('0x2c')],'type':_0x255047[_0xbdaf('0x2d')][_0xbdaf('0x2e')]};});_0x363353['model']=_['map'](_0x55ddab,'name');_0x363353['query']=_[_0xbdaf('0x2f')](_0x31018e['query']);_0x363353['filters']=_['intersection'](_0x363353[_0xbdaf('0x30')],_0x363353[_0xbdaf('0x31')]);_0x495d76['attributes']=_['intersection'](_0x363353[_0xbdaf('0x30')],qs['fields'](_0x31018e[_0xbdaf('0x31')][_0xbdaf('0x32')]));_0x495d76[_0xbdaf('0x33')]=_0x495d76[_0xbdaf('0x33')]['length']?_0x495d76[_0xbdaf('0x33')]:_0x363353['model'];if(!_0x31018e[_0xbdaf('0x31')]['hasOwnProperty'](_0xbdaf('0x34'))){_0x495d76[_0xbdaf('0x1d')]=qs[_0xbdaf('0x1d')](_0x31018e['query']['limit']);_0x495d76[_0xbdaf('0x1c')]=qs[_0xbdaf('0x1c')](_0x31018e[_0xbdaf('0x31')][_0xbdaf('0x1c')]);}_0x495d76[_0xbdaf('0x35')]=qs[_0xbdaf('0x36')](_0x31018e[_0xbdaf('0x31')]['sort']);_0x495d76['where']=qs[_0xbdaf('0x37')](_[_0xbdaf('0x38')](_0x31018e[_0xbdaf('0x31')],_0x363353[_0xbdaf('0x37')]),_0x55ddab);if(_0x31018e[_0xbdaf('0x31')][_0xbdaf('0x39')]){_0x495d76[_0xbdaf('0x3a')]=_[_0xbdaf('0x3b')](_0x495d76[_0xbdaf('0x3a')],{'$or':_['map'](_0x55ddab,function(_0x3d7be4){if(_0x3d7be4[_0xbdaf('0x2d')]!==_0xbdaf('0x3c')){var _0x52584e={};_0x52584e[_0x3d7be4[_0xbdaf('0x27')]]={'$like':'%'+_0x31018e[_0xbdaf('0x31')][_0xbdaf('0x39')]+'%'};return _0x52584e;}})});}_0x495d76=_[_0xbdaf('0x3b')]({},_0x495d76,_0x31018e[_0xbdaf('0x3d')]);var _0x39ccdd={'where':_0x495d76[_0xbdaf('0x3a')]};return db[_0xbdaf('0x2a')][_0xbdaf('0x1b')](_0x39ccdd)[_0xbdaf('0x24')](function(_0x3d4d9b){_0x57676c['count']=_0x3d4d9b;if(_0x31018e['query'][_0xbdaf('0x3e')]){_0x495d76[_0xbdaf('0x3f')]=[{'all':!![]}];}return db[_0xbdaf('0x2a')][_0xbdaf('0x40')](_0x495d76);})[_0xbdaf('0x24')](function(_0x293fd1){_0x57676c[_0xbdaf('0x41')]=_0x293fd1;return _0x57676c;})['then'](respondWithFilteredResult(_0x40391a,_0x495d76))[_0xbdaf('0x42')](handleError(_0x40391a,null));};exports[_0xbdaf('0x43')]=function(_0x13d09a,_0x3f361a){var _0xfb6d72={'raw':![],'where':{'id':_0x13d09a['params']['id']}},_0x4ac904={};_0x4ac904[_0xbdaf('0x30')]=_['keys'](db['UserProfileSection']['rawAttributes']);_0x4ac904[_0xbdaf('0x31')]=_['keys'](_0x13d09a['query']);_0x4ac904[_0xbdaf('0x37')]=_[_0xbdaf('0x44')](_0x4ac904[_0xbdaf('0x30')],_0x4ac904['query']);_0xfb6d72['attributes']=_[_0xbdaf('0x44')](_0x4ac904[_0xbdaf('0x30')],qs[_0xbdaf('0x32')](_0x13d09a[_0xbdaf('0x31')]['fields']));_0xfb6d72['attributes']=_0xfb6d72['attributes'][_0xbdaf('0x45')]?_0xfb6d72[_0xbdaf('0x33')]:_0x4ac904[_0xbdaf('0x30')];if(_0x13d09a[_0xbdaf('0x31')][_0xbdaf('0x3e')]){_0xfb6d72[_0xbdaf('0x3f')]=[{'all':!![]}];}_0xfb6d72=_[_0xbdaf('0x3b')]({},_0xfb6d72,_0x13d09a[_0xbdaf('0x3d')]);return db[_0xbdaf('0x2a')]['find'](_0xfb6d72)[_0xbdaf('0x24')](handleEntityNotFound(_0x3f361a,null))['then'](respondWithResult(_0x3f361a,null))[_0xbdaf('0x42')](handleError(_0x3f361a,null));};exports['create']=function(_0x563eed,_0x5a31d3){return db['UserProfileSection'][_0xbdaf('0x46')](_0x563eed[_0xbdaf('0x47')],{})['then'](respondWithResult(_0x5a31d3,0xc9))[_0xbdaf('0x42')](handleError(_0x5a31d3,null));};exports['update']=function(_0x36a0b9,_0x348bad){if(_0x36a0b9[_0xbdaf('0x47')]['id']){delete _0x36a0b9[_0xbdaf('0x47')]['id'];}return db['UserProfileSection'][_0xbdaf('0x48')]({'where':{'id':_0x36a0b9[_0xbdaf('0x49')]['id']}})['then'](handleEntityNotFound(_0x348bad,null))['then'](saveUpdates(_0x36a0b9[_0xbdaf('0x47')],null))['then'](respondWithResult(_0x348bad,null))[_0xbdaf('0x42')](handleError(_0x348bad,null));};exports[_0xbdaf('0x4a')]=function(_0x4bc26e,_0x6199dd){return db[_0xbdaf('0x2a')][_0xbdaf('0x48')]({'where':{'id':_0x4bc26e[_0xbdaf('0x49')]['id']}})[_0xbdaf('0x24')](handleEntityNotFound(_0x6199dd,null))['then'](removeEntity(_0x6199dd,null))[_0xbdaf('0x42')](handleError(_0x6199dd,null));};exports[_0xbdaf('0x4b')]=function(_0x1fa8a7,_0x1138c2){return db['UserProfileSection'][_0xbdaf('0x4b')]()[_0xbdaf('0x24')](respondWithResult(_0x1138c2,null))['catch'](handleError(_0x1138c2,null));};