d1a01e42af30e2db41ca7d21b993722228609920
[motion2.git] / server / api / userProfileResource / userProfileResource.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 _0x326f=['moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/license/util','sendStatus','status','end','count','offset','limit','set','Content-Range','json','reject','then','destroy','error','stack','name','send','UserProfileResource','rawAttributes','type','key','map','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','findAll','rows','catch','params','create','body','update','find','describe','html-pdf','zip-dir','fast-json-patch','request-promise'];(function(_0x4ffc24,_0x250df8){var _0x353194=function(_0x4837c3){while(--_0x4837c3){_0x4ffc24['push'](_0x4ffc24['shift']());}};_0x353194(++_0x250df8);}(_0x326f,0xd1));var _0xf326=function(_0x13ba41,_0x4371e3){_0x13ba41=_0x13ba41-0x0;var _0x8cb40e=_0x326f[_0x13ba41];return _0x8cb40e;};'use strict';var pdf=require(_0xf326('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf326('0x1'));var jsonpatch=require(_0xf326('0x2'));var rp=require(_0xf326('0x3'));var moment=require(_0xf326('0x4'));var BPromise=require(_0xf326('0x5'));var Mustache=require(_0xf326('0x6'));var util=require(_0xf326('0x7'));var path=require(_0xf326('0x8'));var sox=require(_0xf326('0x9'));var csv=require(_0xf326('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xf326('0xb'));var squel=require(_0xf326('0xc'));var crypto=require(_0xf326('0xd'));var jsforce=require(_0xf326('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf326('0xf'));var Redis=require(_0xf326('0x10'));var authService=require(_0xf326('0x11'));var qs=require(_0xf326('0x12'));var as=require(_0xf326('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf326('0x14'))('api');var utils=require(_0xf326('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf326('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3162f9,_0x9ed463){_0x9ed463=_0x9ed463||0xcc;return function(_0x4b3966){if(_0x4b3966){return _0x3162f9[_0xf326('0x17')](_0x9ed463);}return _0x3162f9[_0xf326('0x18')](_0x9ed463)[_0xf326('0x19')]();};}function respondWithResult(_0x17a098,_0x5c8483){_0x5c8483=_0x5c8483||0xc8;return function(_0x45c1b6){if(_0x45c1b6){return _0x17a098['status'](_0x5c8483)['json'](_0x45c1b6);}};}function respondWithFilteredResult(_0xdf21d9,_0x11f6d2){return function(_0x1f2e5a){if(_0x1f2e5a){var _0xa63d1a=_0x1f2e5a[_0xf326('0x1a')],_0x292f4b=_0x11f6d2['offset'],_0x287a2a=_0x11f6d2[_0xf326('0x1b')]+_0x11f6d2[_0xf326('0x1c')],_0x34128e;if(_0x287a2a>=_0xa63d1a){_0x287a2a=_0xa63d1a;_0x34128e=0xc8;}else{_0x34128e=0xce;}_0xdf21d9[_0xf326('0x18')](_0x34128e);return _0xdf21d9[_0xf326('0x1d')](_0xf326('0x1e'),_0x292f4b+'-'+_0x287a2a+'/'+_0xa63d1a)[_0xf326('0x1f')](_0x1f2e5a);}return null;};}function patchUpdates(_0x4d3d41){return function(_0x4a5b6c){try{jsonpatch['apply'](_0x4a5b6c,_0x4d3d41,!![]);}catch(_0x16e605){return BPromise[_0xf326('0x20')](_0x16e605);}return _0x4a5b6c['save']();};}function saveUpdates(_0x4cabce,_0x128c68){return function(_0x4dfa76){if(_0x4dfa76){return _0x4dfa76['update'](_0x4cabce)[_0xf326('0x21')](function(_0x18ead3){return _0x18ead3;});}return null;};}function removeEntity(_0x549b46,_0x5aa184){return function(_0x19b8ba){if(_0x19b8ba){return _0x19b8ba[_0xf326('0x22')]()['then'](function(){_0x549b46[_0xf326('0x18')](0xcc)[_0xf326('0x19')]();});}};}function handleEntityNotFound(_0x43c53e,_0x295752){return function(_0x17c157){if(!_0x17c157){_0x43c53e[_0xf326('0x17')](0x194);}return _0x17c157;};}function handleError(_0x5ce532,_0x55b9f4){_0x55b9f4=_0x55b9f4||0x1f4;return function(_0x4f31f6){logger[_0xf326('0x23')](_0x4f31f6[_0xf326('0x24')]);if(_0x4f31f6[_0xf326('0x25')]){delete _0x4f31f6[_0xf326('0x25')];}_0x5ce532[_0xf326('0x18')](_0x55b9f4)[_0xf326('0x26')](_0x4f31f6);};}exports['index']=function(_0x201d28,_0xa3c0b){var _0x212d5d={},_0x581531={},_0x1617d2={'count':0x0,'rows':[]};var _0x55ad0f=_['map'](db[_0xf326('0x27')][_0xf326('0x28')],function(_0x2fa28e){return{'name':_0x2fa28e['fieldName'],'type':_0x2fa28e[_0xf326('0x29')][_0xf326('0x2a')]};});_0x581531['model']=_[_0xf326('0x2b')](_0x55ad0f,_0xf326('0x25'));_0x581531[_0xf326('0x2c')]=_[_0xf326('0x2d')](_0x201d28[_0xf326('0x2c')]);_0x581531[_0xf326('0x2e')]=_[_0xf326('0x2f')](_0x581531[_0xf326('0x30')],_0x581531[_0xf326('0x2c')]);_0x212d5d[_0xf326('0x31')]=_['intersection'](_0x581531[_0xf326('0x30')],qs[_0xf326('0x32')](_0x201d28[_0xf326('0x2c')]['fields']));_0x212d5d[_0xf326('0x31')]=_0x212d5d[_0xf326('0x31')][_0xf326('0x33')]?_0x212d5d['attributes']:_0x581531['model'];if(!_0x201d28[_0xf326('0x2c')][_0xf326('0x34')](_0xf326('0x35'))){_0x212d5d[_0xf326('0x1c')]=qs[_0xf326('0x1c')](_0x201d28[_0xf326('0x2c')][_0xf326('0x1c')]);_0x212d5d[_0xf326('0x1b')]=qs['offset'](_0x201d28[_0xf326('0x2c')][_0xf326('0x1b')]);}_0x212d5d['order']=qs[_0xf326('0x36')](_0x201d28['query'][_0xf326('0x36')]);_0x212d5d['where']=qs['filters'](_[_0xf326('0x37')](_0x201d28['query'],_0x581531[_0xf326('0x2e')]),_0x55ad0f);if(_0x201d28['query'][_0xf326('0x38')]){_0x212d5d[_0xf326('0x39')]=_[_0xf326('0x3a')](_0x212d5d['where'],{'$or':_[_0xf326('0x2b')](_0x55ad0f,function(_0x4095e6){if(_0x4095e6['type']!==_0xf326('0x3b')){var _0xf64dd0={};_0xf64dd0[_0x4095e6[_0xf326('0x25')]]={'$like':'%'+_0x201d28[_0xf326('0x2c')]['filter']+'%'};return _0xf64dd0;}})});}_0x212d5d=_[_0xf326('0x3a')]({},_0x212d5d,_0x201d28[_0xf326('0x3c')]);var _0x1e69b1={'where':_0x212d5d[_0xf326('0x39')]};return db[_0xf326('0x27')]['count'](_0x1e69b1)[_0xf326('0x21')](function(_0x1b7bf6){_0x1617d2['count']=_0x1b7bf6;if(_0x201d28['query'][_0xf326('0x3d')]){_0x212d5d['include']=[{'all':!![]}];}return db['UserProfileResource'][_0xf326('0x3e')](_0x212d5d);})['then'](function(_0x3e1e8c){_0x1617d2[_0xf326('0x3f')]=_0x3e1e8c;return _0x1617d2;})[_0xf326('0x21')](respondWithFilteredResult(_0xa3c0b,_0x212d5d))[_0xf326('0x40')](handleError(_0xa3c0b,null));};exports['show']=function(_0x9dda89,_0x45d344){var _0x347e7b={'raw':![],'where':{'id':_0x9dda89[_0xf326('0x41')]['id']}},_0x365627={};_0x365627[_0xf326('0x30')]=_[_0xf326('0x2d')](db[_0xf326('0x27')][_0xf326('0x28')]);_0x365627[_0xf326('0x2c')]=_[_0xf326('0x2d')](_0x9dda89[_0xf326('0x2c')]);_0x365627['filters']=_[_0xf326('0x2f')](_0x365627[_0xf326('0x30')],_0x365627[_0xf326('0x2c')]);_0x347e7b[_0xf326('0x31')]=_[_0xf326('0x2f')](_0x365627[_0xf326('0x30')],qs['fields'](_0x9dda89[_0xf326('0x2c')][_0xf326('0x32')]));_0x347e7b['attributes']=_0x347e7b[_0xf326('0x31')][_0xf326('0x33')]?_0x347e7b[_0xf326('0x31')]:_0x365627[_0xf326('0x30')];if(_0x9dda89[_0xf326('0x2c')]['includeAll']){_0x347e7b['include']=[{'all':!![]}];}_0x347e7b=_[_0xf326('0x3a')]({},_0x347e7b,_0x9dda89[_0xf326('0x3c')]);return db['UserProfileResource']['find'](_0x347e7b)[_0xf326('0x21')](handleEntityNotFound(_0x45d344,null))[_0xf326('0x21')](respondWithResult(_0x45d344,null))[_0xf326('0x40')](handleError(_0x45d344,null));};exports['create']=function(_0x301e65,_0xe96e1e){return db[_0xf326('0x27')][_0xf326('0x42')](_0x301e65[_0xf326('0x43')],{})[_0xf326('0x21')](respondWithResult(_0xe96e1e,0xc9))[_0xf326('0x40')](handleError(_0xe96e1e,null));};exports[_0xf326('0x44')]=function(_0x3df9a8,_0x27ced1){if(_0x3df9a8[_0xf326('0x43')]['id']){delete _0x3df9a8[_0xf326('0x43')]['id'];}return db[_0xf326('0x27')][_0xf326('0x45')]({'where':{'id':_0x3df9a8[_0xf326('0x41')]['id']}})['then'](handleEntityNotFound(_0x27ced1,null))[_0xf326('0x21')](saveUpdates(_0x3df9a8[_0xf326('0x43')],null))[_0xf326('0x21')](respondWithResult(_0x27ced1,null))[_0xf326('0x40')](handleError(_0x27ced1,null));};exports['destroy']=function(_0x10f437,_0x2f5511){return db[_0xf326('0x27')][_0xf326('0x45')]({'where':{'id':_0x10f437['params']['id']}})[_0xf326('0x21')](handleEntityNotFound(_0x2f5511,null))[_0xf326('0x21')](removeEntity(_0x2f5511,null))[_0xf326('0x40')](handleError(_0x2f5511,null));};exports[_0xf326('0x46')]=function(_0x39ba25,_0x4970fb){return db['UserProfileResource'][_0xf326('0x46')]()[_0xf326('0x21')](respondWithResult(_0x4970fb,null))[_0xf326('0x40')](handleError(_0x4970fb,null));};