972ed9756729c00a3caea184c92f74935f4d6809
[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 _0x142b=['query','keys','filters','intersection','model','attributes','fields','length','nolimit','limit','order','sort','pick','filter','where','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','options','find','catch','create','body','describe','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','crypto','jsforce','querystring','papaparse','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','status','end','json','count','offset','set','Content-Range','apply','reject','update','destroy','then','sendStatus','error','send','index','UserProfileSection','rawAttributes','fieldName','type','key','map','name'];(function(_0xb7b878,_0x5c3b92){var _0x3c84b9=function(_0x21d5a2){while(--_0x21d5a2){_0xb7b878['push'](_0xb7b878['shift']());}};_0x3c84b9(++_0x5c3b92);}(_0x142b,0x1bb));var _0xb142=function(_0x417600,_0x2439fe){_0x417600=_0x417600-0x0;var _0x1b9bb3=_0x142b[_0x417600];return _0x1b9bb3;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xb142('0x0'));var rp=require(_0xb142('0x1'));var moment=require(_0xb142('0x2'));var BPromise=require(_0xb142('0x3'));var Mustache=require(_0xb142('0x4'));var util=require('util');var path=require(_0xb142('0x5'));var sox=require(_0xb142('0x6'));var csv=require(_0xb142('0x7'));var ejs=require(_0xb142('0x8'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xb142('0x9'));var jsforce=require(_0xb142('0xa'));var deskjs=require('desk.js');var toCsv=require(_0xb142('0x7'));var querystring=require(_0xb142('0xb'));var Papa=require(_0xb142('0xc'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xb142('0xd'));var hardwareService=require(_0xb142('0xe'));var logger=require(_0xb142('0xf'))('api');var utils=require(_0xb142('0x10'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5f2df6,_0x3f67ea){_0x3f67ea=_0x3f67ea||0xcc;return function(_0x134291){if(_0x134291){return _0x5f2df6['sendStatus'](_0x3f67ea);}return _0x5f2df6[_0xb142('0x11')](_0x3f67ea)[_0xb142('0x12')]();};}function respondWithResult(_0x3ba5d3,_0x4b143a){_0x4b143a=_0x4b143a||0xc8;return function(_0x223414){if(_0x223414){return _0x3ba5d3[_0xb142('0x11')](_0x4b143a)[_0xb142('0x13')](_0x223414);}};}function respondWithFilteredResult(_0x53673a,_0xe088e3){return function(_0x58fa25){if(_0x58fa25){var _0x202311=_0x58fa25[_0xb142('0x14')],_0x4c8539=_0xe088e3[_0xb142('0x15')],_0x49984a=_0xe088e3[_0xb142('0x15')]+_0xe088e3['limit'],_0x579b83;if(_0x49984a>=_0x202311){_0x49984a=_0x202311;_0x579b83=0xc8;}else{_0x579b83=0xce;}_0x53673a[_0xb142('0x11')](_0x579b83);return _0x53673a[_0xb142('0x16')](_0xb142('0x17'),_0x4c8539+'-'+_0x49984a+'/'+_0x202311)[_0xb142('0x13')](_0x58fa25);}return null;};}function patchUpdates(_0x46c986){return function(_0xf47f7b){try{jsonpatch[_0xb142('0x18')](_0xf47f7b,_0x46c986,!![]);}catch(_0x159210){return BPromise[_0xb142('0x19')](_0x159210);}return _0xf47f7b['save']();};}function saveUpdates(_0x38b982,_0x45339b){return function(_0x2e3d3f){if(_0x2e3d3f){return _0x2e3d3f[_0xb142('0x1a')](_0x38b982)['then'](function(_0x5d796f){return _0x5d796f;});}return null;};}function removeEntity(_0x49adc7,_0x1abee0){return function(_0x4c1bd1){if(_0x4c1bd1){return _0x4c1bd1[_0xb142('0x1b')]()[_0xb142('0x1c')](function(){_0x49adc7[_0xb142('0x11')](0xcc)[_0xb142('0x12')]();});}};}function handleEntityNotFound(_0x20379f,_0x5d1719){return function(_0xf7c23d){if(!_0xf7c23d){_0x20379f[_0xb142('0x1d')](0x194);}return _0xf7c23d;};}function handleError(_0x49521a,_0x153191){_0x153191=_0x153191||0x1f4;return function(_0x3c13f8){logger[_0xb142('0x1e')](_0x3c13f8['stack']);if(_0x3c13f8['name']){delete _0x3c13f8['name'];}_0x49521a[_0xb142('0x11')](_0x153191)[_0xb142('0x1f')](_0x3c13f8);};}exports[_0xb142('0x20')]=function(_0x436d13,_0x1a6827){var _0x10aafd={},_0x574602={},_0x7b674d={'count':0x0,'rows':[]};var _0x39dd28=_['map'](db[_0xb142('0x21')][_0xb142('0x22')],function(_0x5dad4f){return{'name':_0x5dad4f[_0xb142('0x23')],'type':_0x5dad4f[_0xb142('0x24')][_0xb142('0x25')]};});_0x574602['model']=_[_0xb142('0x26')](_0x39dd28,_0xb142('0x27'));_0x574602[_0xb142('0x28')]=_[_0xb142('0x29')](_0x436d13[_0xb142('0x28')]);_0x574602[_0xb142('0x2a')]=_[_0xb142('0x2b')](_0x574602[_0xb142('0x2c')],_0x574602['query']);_0x10aafd[_0xb142('0x2d')]=_[_0xb142('0x2b')](_0x574602[_0xb142('0x2c')],qs[_0xb142('0x2e')](_0x436d13['query']['fields']));_0x10aafd['attributes']=_0x10aafd[_0xb142('0x2d')][_0xb142('0x2f')]?_0x10aafd['attributes']:_0x574602[_0xb142('0x2c')];if(!_0x436d13[_0xb142('0x28')]['hasOwnProperty'](_0xb142('0x30'))){_0x10aafd[_0xb142('0x31')]=qs['limit'](_0x436d13[_0xb142('0x28')][_0xb142('0x31')]);_0x10aafd['offset']=qs[_0xb142('0x15')](_0x436d13['query'][_0xb142('0x15')]);}_0x10aafd[_0xb142('0x32')]=qs[_0xb142('0x33')](_0x436d13['query']['sort']);_0x10aafd['where']=qs[_0xb142('0x2a')](_[_0xb142('0x34')](_0x436d13[_0xb142('0x28')],_0x574602[_0xb142('0x2a')]),_0x39dd28);if(_0x436d13[_0xb142('0x28')][_0xb142('0x35')]){_0x10aafd[_0xb142('0x36')]=_[_0xb142('0x37')](_0x10aafd['where'],{'$or':_[_0xb142('0x26')](_0x39dd28,function(_0x340a42){if(_0x340a42[_0xb142('0x24')]!==_0xb142('0x38')){var _0x99af70={};_0x99af70[_0x340a42[_0xb142('0x27')]]={'$like':'%'+_0x436d13[_0xb142('0x28')][_0xb142('0x35')]+'%'};return _0x99af70;}})});}_0x10aafd=_[_0xb142('0x37')]({},_0x10aafd,_0x436d13['options']);var _0x269e5d={'where':_0x10aafd[_0xb142('0x36')]};return db[_0xb142('0x21')][_0xb142('0x14')](_0x269e5d)['then'](function(_0x291489){_0x7b674d[_0xb142('0x14')]=_0x291489;if(_0x436d13['query'][_0xb142('0x39')]){_0x10aafd[_0xb142('0x3a')]=[{'all':!![]}];}return db['UserProfileSection'][_0xb142('0x3b')](_0x10aafd);})['then'](function(_0x5dbdda){_0x7b674d[_0xb142('0x3c')]=_0x5dbdda;return _0x7b674d;})[_0xb142('0x1c')](respondWithFilteredResult(_0x1a6827,_0x10aafd))['catch'](handleError(_0x1a6827,null));};exports[_0xb142('0x3d')]=function(_0x55d9d4,_0x429ddc){var _0x39821d={'raw':![],'where':{'id':_0x55d9d4[_0xb142('0x3e')]['id']}},_0xe09e20={};_0xe09e20[_0xb142('0x2c')]=_[_0xb142('0x29')](db['UserProfileSection'][_0xb142('0x22')]);_0xe09e20[_0xb142('0x28')]=_[_0xb142('0x29')](_0x55d9d4[_0xb142('0x28')]);_0xe09e20[_0xb142('0x2a')]=_[_0xb142('0x2b')](_0xe09e20[_0xb142('0x2c')],_0xe09e20[_0xb142('0x28')]);_0x39821d[_0xb142('0x2d')]=_[_0xb142('0x2b')](_0xe09e20[_0xb142('0x2c')],qs[_0xb142('0x2e')](_0x55d9d4[_0xb142('0x28')][_0xb142('0x2e')]));_0x39821d['attributes']=_0x39821d[_0xb142('0x2d')]['length']?_0x39821d[_0xb142('0x2d')]:_0xe09e20[_0xb142('0x2c')];if(_0x55d9d4[_0xb142('0x28')][_0xb142('0x39')]){_0x39821d[_0xb142('0x3a')]=[{'all':!![]}];}_0x39821d=_['merge']({},_0x39821d,_0x55d9d4[_0xb142('0x3f')]);return db['UserProfileSection'][_0xb142('0x40')](_0x39821d)[_0xb142('0x1c')](handleEntityNotFound(_0x429ddc,null))[_0xb142('0x1c')](respondWithResult(_0x429ddc,null))[_0xb142('0x41')](handleError(_0x429ddc,null));};exports[_0xb142('0x42')]=function(_0x905606,_0x218b45){return db[_0xb142('0x21')][_0xb142('0x42')](_0x905606[_0xb142('0x43')],{})[_0xb142('0x1c')](respondWithResult(_0x218b45,0xc9))['catch'](handleError(_0x218b45,null));};exports[_0xb142('0x1a')]=function(_0x3b4973,_0x28a786){if(_0x3b4973[_0xb142('0x43')]['id']){delete _0x3b4973[_0xb142('0x43')]['id'];}return db[_0xb142('0x21')][_0xb142('0x40')]({'where':{'id':_0x3b4973['params']['id']}})[_0xb142('0x1c')](handleEntityNotFound(_0x28a786,null))[_0xb142('0x1c')](saveUpdates(_0x3b4973[_0xb142('0x43')],null))[_0xb142('0x1c')](respondWithResult(_0x28a786,null))['catch'](handleError(_0x28a786,null));};exports[_0xb142('0x1b')]=function(_0x26991d,_0x17b40c){return db[_0xb142('0x21')]['find']({'where':{'id':_0x26991d[_0xb142('0x3e')]['id']}})[_0xb142('0x1c')](handleEntityNotFound(_0x17b40c,null))[_0xb142('0x1c')](removeEntity(_0x17b40c,null))[_0xb142('0x41')](handleError(_0x17b40c,null));};exports[_0xb142('0x44')]=function(_0x456f92,_0x4e912a){return db[_0xb142('0x21')][_0xb142('0x44')]()[_0xb142('0x1c')](respondWithResult(_0x4e912a,null))[_0xb142('0x41')](handleError(_0x4e912a,null));};