7d3866537f2b001b39f8637105c7eafbe68021b2
[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 _0xdbf5=['type','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','count','includeAll','include','findAll','catch','show','params','rawAttributes','length','find','create','body','describe','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/license/util','sendStatus','status','json','offset','limit','set','reject','save','update','destroy','then','end','error','stack','name','send','index','map','UserProfileResource','fieldName'];(function(_0x4af00b,_0x36c251){var _0x4e49f3=function(_0x43b354){while(--_0x43b354){_0x4af00b['push'](_0x4af00b['shift']());}};_0x4e49f3(++_0x36c251);}(_0xdbf5,0x18c));var _0x5dbf=function(_0x30f78e,_0x17d09a){_0x30f78e=_0x30f78e-0x0;var _0x4b3195=_0xdbf5[_0x30f78e];return _0x4b3195;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x5dbf('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x5dbf('0x1'));var rp=require(_0x5dbf('0x2'));var moment=require(_0x5dbf('0x3'));var BPromise=require(_0x5dbf('0x4'));var Mustache=require(_0x5dbf('0x5'));var util=require(_0x5dbf('0x6'));var path=require(_0x5dbf('0x7'));var sox=require(_0x5dbf('0x8'));var csv=require(_0x5dbf('0x9'));var ejs=require(_0x5dbf('0xa'));var fs=require('fs');var _=require(_0x5dbf('0xb'));var squel=require(_0x5dbf('0xc'));var crypto=require(_0x5dbf('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x5dbf('0xe'));var toCsv=require('to-csv');var querystring=require(_0x5dbf('0xf'));var Papa=require(_0x5dbf('0x10'));var Redis=require(_0x5dbf('0x11'));var authService=require(_0x5dbf('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x5dbf('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x5dbf('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x5dbf('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x182cec,_0x2bb7ed){_0x2bb7ed=_0x2bb7ed||0xcc;return function(_0x1453a9){if(_0x1453a9){return _0x182cec[_0x5dbf('0x16')](_0x2bb7ed);}return _0x182cec[_0x5dbf('0x17')](_0x2bb7ed)['end']();};}function respondWithResult(_0x4803ca,_0x2b4e1c){_0x2b4e1c=_0x2b4e1c||0xc8;return function(_0x3480c8){if(_0x3480c8){return _0x4803ca['status'](_0x2b4e1c)[_0x5dbf('0x18')](_0x3480c8);}};}function respondWithFilteredResult(_0x248e3c,_0x23f763){return function(_0x2dfa44){if(_0x2dfa44){var _0x181816=_0x2dfa44['count'],_0x472eb9=_0x23f763[_0x5dbf('0x19')],_0x2d32cc=_0x23f763[_0x5dbf('0x19')]+_0x23f763[_0x5dbf('0x1a')],_0x50ef1d;if(_0x2d32cc>=_0x181816){_0x2d32cc=_0x181816;_0x50ef1d=0xc8;}else{_0x50ef1d=0xce;}_0x248e3c[_0x5dbf('0x17')](_0x50ef1d);return _0x248e3c[_0x5dbf('0x1b')]('Content-Range',_0x472eb9+'-'+_0x2d32cc+'/'+_0x181816)[_0x5dbf('0x18')](_0x2dfa44);}return null;};}function patchUpdates(_0x4dd03c){return function(_0x565efa){try{jsonpatch['apply'](_0x565efa,_0x4dd03c,!![]);}catch(_0x23d1e7){return BPromise[_0x5dbf('0x1c')](_0x23d1e7);}return _0x565efa[_0x5dbf('0x1d')]();};}function saveUpdates(_0x2ab57c,_0x1e3cce){return function(_0x5b2518){if(_0x5b2518){return _0x5b2518[_0x5dbf('0x1e')](_0x2ab57c)['then'](function(_0xb68f92){return _0xb68f92;});}return null;};}function removeEntity(_0x11cc67,_0x14d133){return function(_0x43a612){if(_0x43a612){return _0x43a612[_0x5dbf('0x1f')]()[_0x5dbf('0x20')](function(){_0x11cc67['status'](0xcc)[_0x5dbf('0x21')]();});}};}function handleEntityNotFound(_0x3e3a2d,_0x2d3e1b){return function(_0x2079fc){if(!_0x2079fc){_0x3e3a2d[_0x5dbf('0x16')](0x194);}return _0x2079fc;};}function handleError(_0x226b93,_0x290456){_0x290456=_0x290456||0x1f4;return function(_0x20ab1b){logger[_0x5dbf('0x22')](_0x20ab1b[_0x5dbf('0x23')]);if(_0x20ab1b[_0x5dbf('0x24')]){delete _0x20ab1b[_0x5dbf('0x24')];}_0x226b93[_0x5dbf('0x17')](_0x290456)[_0x5dbf('0x25')](_0x20ab1b);};}exports[_0x5dbf('0x26')]=function(_0x17f135,_0x466985){var _0x3f8341={},_0x159e61={},_0x22ec42={'count':0x0,'rows':[]};var _0x6a9757=_[_0x5dbf('0x27')](db[_0x5dbf('0x28')]['rawAttributes'],function(_0x2f71eb){return{'name':_0x2f71eb[_0x5dbf('0x29')],'type':_0x2f71eb[_0x5dbf('0x2a')][_0x5dbf('0x2b')]};});_0x159e61[_0x5dbf('0x2c')]=_[_0x5dbf('0x27')](_0x6a9757,_0x5dbf('0x24'));_0x159e61[_0x5dbf('0x2d')]=_[_0x5dbf('0x2e')](_0x17f135[_0x5dbf('0x2d')]);_0x159e61[_0x5dbf('0x2f')]=_['intersection'](_0x159e61['model'],_0x159e61[_0x5dbf('0x2d')]);_0x3f8341[_0x5dbf('0x30')]=_[_0x5dbf('0x31')](_0x159e61[_0x5dbf('0x2c')],qs[_0x5dbf('0x32')](_0x17f135['query']['fields']));_0x3f8341[_0x5dbf('0x30')]=_0x3f8341[_0x5dbf('0x30')]['length']?_0x3f8341[_0x5dbf('0x30')]:_0x159e61[_0x5dbf('0x2c')];if(!_0x17f135[_0x5dbf('0x2d')][_0x5dbf('0x33')](_0x5dbf('0x34'))){_0x3f8341['limit']=qs[_0x5dbf('0x1a')](_0x17f135[_0x5dbf('0x2d')][_0x5dbf('0x1a')]);_0x3f8341[_0x5dbf('0x19')]=qs[_0x5dbf('0x19')](_0x17f135['query'][_0x5dbf('0x19')]);}_0x3f8341[_0x5dbf('0x35')]=qs[_0x5dbf('0x36')](_0x17f135[_0x5dbf('0x2d')]['sort']);_0x3f8341[_0x5dbf('0x37')]=qs[_0x5dbf('0x2f')](_[_0x5dbf('0x38')](_0x17f135[_0x5dbf('0x2d')],_0x159e61[_0x5dbf('0x2f')]),_0x6a9757);if(_0x17f135[_0x5dbf('0x2d')][_0x5dbf('0x39')]){_0x3f8341[_0x5dbf('0x37')]=_[_0x5dbf('0x3a')](_0x3f8341[_0x5dbf('0x37')],{'$or':_[_0x5dbf('0x27')](_0x6a9757,function(_0x51c667){if(_0x51c667[_0x5dbf('0x2a')]!==_0x5dbf('0x3b')){var _0x12d595={};_0x12d595[_0x51c667['name']]={'$like':'%'+_0x17f135[_0x5dbf('0x2d')][_0x5dbf('0x39')]+'%'};return _0x12d595;}})});}_0x3f8341=_[_0x5dbf('0x3a')]({},_0x3f8341,_0x17f135['options']);var _0x444814={'where':_0x3f8341[_0x5dbf('0x37')]};return db[_0x5dbf('0x28')]['count'](_0x444814)[_0x5dbf('0x20')](function(_0x29a62d){_0x22ec42[_0x5dbf('0x3c')]=_0x29a62d;if(_0x17f135[_0x5dbf('0x2d')][_0x5dbf('0x3d')]){_0x3f8341[_0x5dbf('0x3e')]=[{'all':!![]}];}return db[_0x5dbf('0x28')][_0x5dbf('0x3f')](_0x3f8341);})['then'](function(_0x5be96b){_0x22ec42['rows']=_0x5be96b;return _0x22ec42;})['then'](respondWithFilteredResult(_0x466985,_0x3f8341))[_0x5dbf('0x40')](handleError(_0x466985,null));};exports[_0x5dbf('0x41')]=function(_0x54e5e7,_0x3ef0eb){var _0x229abf={'raw':![],'where':{'id':_0x54e5e7[_0x5dbf('0x42')]['id']}},_0x5a60e8={};_0x5a60e8[_0x5dbf('0x2c')]=_[_0x5dbf('0x2e')](db[_0x5dbf('0x28')][_0x5dbf('0x43')]);_0x5a60e8[_0x5dbf('0x2d')]=_[_0x5dbf('0x2e')](_0x54e5e7[_0x5dbf('0x2d')]);_0x5a60e8[_0x5dbf('0x2f')]=_[_0x5dbf('0x31')](_0x5a60e8['model'],_0x5a60e8[_0x5dbf('0x2d')]);_0x229abf[_0x5dbf('0x30')]=_[_0x5dbf('0x31')](_0x5a60e8['model'],qs[_0x5dbf('0x32')](_0x54e5e7[_0x5dbf('0x2d')][_0x5dbf('0x32')]));_0x229abf[_0x5dbf('0x30')]=_0x229abf['attributes'][_0x5dbf('0x44')]?_0x229abf['attributes']:_0x5a60e8[_0x5dbf('0x2c')];if(_0x54e5e7[_0x5dbf('0x2d')][_0x5dbf('0x3d')]){_0x229abf[_0x5dbf('0x3e')]=[{'all':!![]}];}_0x229abf=_['merge']({},_0x229abf,_0x54e5e7['options']);return db[_0x5dbf('0x28')][_0x5dbf('0x45')](_0x229abf)[_0x5dbf('0x20')](handleEntityNotFound(_0x3ef0eb,null))['then'](respondWithResult(_0x3ef0eb,null))[_0x5dbf('0x40')](handleError(_0x3ef0eb,null));};exports['create']=function(_0x4d8df1,_0x573d69){return db['UserProfileResource'][_0x5dbf('0x46')](_0x4d8df1[_0x5dbf('0x47')],{})['then'](respondWithResult(_0x573d69,0xc9))[_0x5dbf('0x40')](handleError(_0x573d69,null));};exports[_0x5dbf('0x1e')]=function(_0x4b6f30,_0x366102){if(_0x4b6f30[_0x5dbf('0x47')]['id']){delete _0x4b6f30['body']['id'];}return db[_0x5dbf('0x28')]['find']({'where':{'id':_0x4b6f30['params']['id']}})[_0x5dbf('0x20')](handleEntityNotFound(_0x366102,null))[_0x5dbf('0x20')](saveUpdates(_0x4b6f30[_0x5dbf('0x47')],null))['then'](respondWithResult(_0x366102,null))['catch'](handleError(_0x366102,null));};exports[_0x5dbf('0x1f')]=function(_0x3e8612,_0x21f477){return db[_0x5dbf('0x28')][_0x5dbf('0x45')]({'where':{'id':_0x3e8612[_0x5dbf('0x42')]['id']}})[_0x5dbf('0x20')](handleEntityNotFound(_0x21f477,null))[_0x5dbf('0x20')](removeEntity(_0x21f477,null))['catch'](handleError(_0x21f477,null));};exports[_0x5dbf('0x48')]=function(_0x387eb7,_0x2927a3){return db[_0x5dbf('0x28')][_0x5dbf('0x48')]()[_0x5dbf('0x20')](respondWithResult(_0x2927a3,null))[_0x5dbf('0x40')](handleError(_0x2927a3,null));};