Built motion from commit (unavailable).|2.5.19
[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 _0xe256=['findAll','rows','catch','show','params','rawAttributes','includeAll','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','to-csv','lodash','crypto','desk.js','querystring','papaparse','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','sendStatus','error','name','send','UserProfileSection','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','include'];(function(_0x3cf307,_0x4646ac){var _0x139bc9=function(_0x177353){while(--_0x177353){_0x3cf307['push'](_0x3cf307['shift']());}};_0x139bc9(++_0x4646ac);}(_0xe256,0x16e));var _0x6e25=function(_0x1e8f74,_0x311362){_0x1e8f74=_0x1e8f74-0x0;var _0x5935d7=_0xe256[_0x1e8f74];return _0x5935d7;};'use strict';var pdf=require(_0x6e25('0x0'));var emlformat=require(_0x6e25('0x1'));var rimraf=require(_0x6e25('0x2'));var zipdir=require(_0x6e25('0x3'));var jsonpatch=require(_0x6e25('0x4'));var rp=require(_0x6e25('0x5'));var moment=require(_0x6e25('0x6'));var BPromise=require(_0x6e25('0x7'));var Mustache=require('mustache');var util=require('util');var path=require(_0x6e25('0x8'));var sox=require('sox');var csv=require(_0x6e25('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x6e25('0xa'));var squel=require('squel');var crypto=require(_0x6e25('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x6e25('0xc'));var toCsv=require(_0x6e25('0x9'));var querystring=require(_0x6e25('0xd'));var Papa=require(_0x6e25('0xe'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x6e25('0xf'));var utils=require(_0x6e25('0x10'));var config=require(_0x6e25('0x11'));var licenseUtil=require(_0x6e25('0x12'));var db=require(_0x6e25('0x13'))['db'];function respondWithStatusCode(_0x5acbc2,_0x15b0e6){_0x15b0e6=_0x15b0e6||0xcc;return function(_0x5a004){if(_0x5a004){return _0x5acbc2['sendStatus'](_0x15b0e6);}return _0x5acbc2[_0x6e25('0x14')](_0x15b0e6)[_0x6e25('0x15')]();};}function respondWithResult(_0x2507e4,_0x4d8b28){_0x4d8b28=_0x4d8b28||0xc8;return function(_0x1bb391){if(_0x1bb391){return _0x2507e4[_0x6e25('0x14')](_0x4d8b28)[_0x6e25('0x16')](_0x1bb391);}};}function respondWithFilteredResult(_0x368883,_0x117104){return function(_0x3817bb){if(_0x3817bb){var _0x4fa00b=_0x3817bb[_0x6e25('0x17')],_0x144b79=_0x117104[_0x6e25('0x18')],_0x50ed2c=_0x117104[_0x6e25('0x18')]+_0x117104[_0x6e25('0x19')],_0x2cafa4;if(_0x50ed2c>=_0x4fa00b){_0x50ed2c=_0x4fa00b;_0x2cafa4=0xc8;}else{_0x2cafa4=0xce;}_0x368883['status'](_0x2cafa4);return _0x368883[_0x6e25('0x1a')](_0x6e25('0x1b'),_0x144b79+'-'+_0x50ed2c+'/'+_0x4fa00b)['json'](_0x3817bb);}return null;};}function patchUpdates(_0x15b940){return function(_0x157142){try{jsonpatch[_0x6e25('0x1c')](_0x157142,_0x15b940,!![]);}catch(_0x17bea4){return BPromise['reject'](_0x17bea4);}return _0x157142[_0x6e25('0x1d')]();};}function saveUpdates(_0x5ed492,_0x3180d4){return function(_0x4ea049){if(_0x4ea049){return _0x4ea049[_0x6e25('0x1e')](_0x5ed492)[_0x6e25('0x1f')](function(_0x42a335){return _0x42a335;});}return null;};}function removeEntity(_0x498faf,_0x25718c){return function(_0x26169f){if(_0x26169f){return _0x26169f[_0x6e25('0x20')]()[_0x6e25('0x1f')](function(){_0x498faf[_0x6e25('0x14')](0xcc)[_0x6e25('0x15')]();});}};}function handleEntityNotFound(_0x2dda0f,_0x24a3ab){return function(_0x44d8e5){if(!_0x44d8e5){_0x2dda0f[_0x6e25('0x21')](0x194);}return _0x44d8e5;};}function handleError(_0x492163,_0x62ef2){_0x62ef2=_0x62ef2||0x1f4;return function(_0x46bf24){logger[_0x6e25('0x22')](_0x46bf24['stack']);if(_0x46bf24[_0x6e25('0x23')]){delete _0x46bf24['name'];}_0x492163[_0x6e25('0x14')](_0x62ef2)[_0x6e25('0x24')](_0x46bf24);};}exports['index']=function(_0x548e23,_0x233531){var _0x5f03d6={},_0x25a58e={},_0x51ce8e={'count':0x0,'rows':[]};var _0x515e84=_['map'](db[_0x6e25('0x25')]['rawAttributes'],function(_0x2d147f){return{'name':_0x2d147f[_0x6e25('0x26')],'type':_0x2d147f[_0x6e25('0x27')][_0x6e25('0x28')]};});_0x25a58e[_0x6e25('0x29')]=_[_0x6e25('0x2a')](_0x515e84,_0x6e25('0x23'));_0x25a58e[_0x6e25('0x2b')]=_[_0x6e25('0x2c')](_0x548e23[_0x6e25('0x2b')]);_0x25a58e[_0x6e25('0x2d')]=_[_0x6e25('0x2e')](_0x25a58e['model'],_0x25a58e['query']);_0x5f03d6[_0x6e25('0x2f')]=_[_0x6e25('0x2e')](_0x25a58e[_0x6e25('0x29')],qs[_0x6e25('0x30')](_0x548e23[_0x6e25('0x2b')][_0x6e25('0x30')]));_0x5f03d6[_0x6e25('0x2f')]=_0x5f03d6[_0x6e25('0x2f')][_0x6e25('0x31')]?_0x5f03d6['attributes']:_0x25a58e[_0x6e25('0x29')];if(!_0x548e23[_0x6e25('0x2b')][_0x6e25('0x32')](_0x6e25('0x33'))){_0x5f03d6[_0x6e25('0x19')]=qs[_0x6e25('0x19')](_0x548e23['query']['limit']);_0x5f03d6[_0x6e25('0x18')]=qs[_0x6e25('0x18')](_0x548e23[_0x6e25('0x2b')]['offset']);}_0x5f03d6[_0x6e25('0x34')]=qs[_0x6e25('0x35')](_0x548e23[_0x6e25('0x2b')]['sort']);_0x5f03d6[_0x6e25('0x36')]=qs[_0x6e25('0x2d')](_[_0x6e25('0x37')](_0x548e23[_0x6e25('0x2b')],_0x25a58e[_0x6e25('0x2d')]),_0x515e84);if(_0x548e23[_0x6e25('0x2b')][_0x6e25('0x38')]){_0x5f03d6[_0x6e25('0x36')]=_['merge'](_0x5f03d6[_0x6e25('0x36')],{'$or':_['map'](_0x515e84,function(_0x59a6dc){if(_0x59a6dc['type']!==_0x6e25('0x39')){var _0x32c093={};_0x32c093[_0x59a6dc[_0x6e25('0x23')]]={'$like':'%'+_0x548e23[_0x6e25('0x2b')][_0x6e25('0x38')]+'%'};return _0x32c093;}})});}_0x5f03d6=_[_0x6e25('0x3a')]({},_0x5f03d6,_0x548e23['options']);var _0x3d953e={'where':_0x5f03d6['where']};return db['UserProfileSection']['count'](_0x3d953e)[_0x6e25('0x1f')](function(_0x377dc5){_0x51ce8e[_0x6e25('0x17')]=_0x377dc5;if(_0x548e23[_0x6e25('0x2b')]['includeAll']){_0x5f03d6[_0x6e25('0x3b')]=[{'all':!![]}];}return db[_0x6e25('0x25')][_0x6e25('0x3c')](_0x5f03d6);})['then'](function(_0x253e1d){_0x51ce8e[_0x6e25('0x3d')]=_0x253e1d;return _0x51ce8e;})[_0x6e25('0x1f')](respondWithFilteredResult(_0x233531,_0x5f03d6))[_0x6e25('0x3e')](handleError(_0x233531,null));};exports[_0x6e25('0x3f')]=function(_0x341d2f,_0xc02e9b){var _0x19ae99={'raw':![],'where':{'id':_0x341d2f[_0x6e25('0x40')]['id']}},_0xc9807d={};_0xc9807d[_0x6e25('0x29')]=_['keys'](db['UserProfileSection'][_0x6e25('0x41')]);_0xc9807d['query']=_['keys'](_0x341d2f[_0x6e25('0x2b')]);_0xc9807d['filters']=_[_0x6e25('0x2e')](_0xc9807d[_0x6e25('0x29')],_0xc9807d[_0x6e25('0x2b')]);_0x19ae99[_0x6e25('0x2f')]=_['intersection'](_0xc9807d['model'],qs[_0x6e25('0x30')](_0x341d2f[_0x6e25('0x2b')][_0x6e25('0x30')]));_0x19ae99[_0x6e25('0x2f')]=_0x19ae99[_0x6e25('0x2f')][_0x6e25('0x31')]?_0x19ae99[_0x6e25('0x2f')]:_0xc9807d['model'];if(_0x341d2f[_0x6e25('0x2b')][_0x6e25('0x42')]){_0x19ae99[_0x6e25('0x3b')]=[{'all':!![]}];}_0x19ae99=_[_0x6e25('0x3a')]({},_0x19ae99,_0x341d2f['options']);return db['UserProfileSection'][_0x6e25('0x43')](_0x19ae99)['then'](handleEntityNotFound(_0xc02e9b,null))[_0x6e25('0x1f')](respondWithResult(_0xc02e9b,null))['catch'](handleError(_0xc02e9b,null));};exports['create']=function(_0x35b726,_0x8d674a){return db[_0x6e25('0x25')][_0x6e25('0x44')](_0x35b726[_0x6e25('0x45')],{})['then'](respondWithResult(_0x8d674a,0xc9))[_0x6e25('0x3e')](handleError(_0x8d674a,null));};exports['update']=function(_0x3e9cd9,_0x37f7fc){if(_0x3e9cd9[_0x6e25('0x45')]['id']){delete _0x3e9cd9['body']['id'];}return db[_0x6e25('0x25')][_0x6e25('0x43')]({'where':{'id':_0x3e9cd9[_0x6e25('0x40')]['id']}})[_0x6e25('0x1f')](handleEntityNotFound(_0x37f7fc,null))[_0x6e25('0x1f')](saveUpdates(_0x3e9cd9[_0x6e25('0x45')],null))[_0x6e25('0x1f')](respondWithResult(_0x37f7fc,null))[_0x6e25('0x3e')](handleError(_0x37f7fc,null));};exports[_0x6e25('0x20')]=function(_0x36e2ef,_0x544de5){return db['UserProfileSection']['find']({'where':{'id':_0x36e2ef[_0x6e25('0x40')]['id']}})[_0x6e25('0x1f')](handleEntityNotFound(_0x544de5,null))[_0x6e25('0x1f')](removeEntity(_0x544de5,null))[_0x6e25('0x3e')](handleError(_0x544de5,null));};exports[_0x6e25('0x46')]=function(_0x200eb9,_0x1bbc26){return db[_0x6e25('0x25')][_0x6e25('0x46')]()['then'](respondWithResult(_0x1bbc26,null))[_0x6e25('0x3e')](handleError(_0x1bbc26,null));};