7da7cc7920d3fbc184b991e119f8f4f527501414
[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 _0x0cda=['../../config/logger','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','send','map','UserProfileSection','rawAttributes','type','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','rows','catch','show','params','length','find','create','body','update','describe','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x35f53a,_0x2b8b76){var _0x50ea70=function(_0x5b7d99){while(--_0x5b7d99){_0x35f53a['push'](_0x35f53a['shift']());}};_0x50ea70(++_0x2b8b76);}(_0x0cda,0x80));var _0xa0cd=function(_0x3881ef,_0x81a4ba){_0x3881ef=_0x3881ef-0x0;var _0x409e00=_0x0cda[_0x3881ef];return _0x409e00;};'use strict';var pdf=require(_0xa0cd('0x0'));var emlformat=require(_0xa0cd('0x1'));var rimraf=require(_0xa0cd('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xa0cd('0x3'));var rp=require(_0xa0cd('0x4'));var moment=require(_0xa0cd('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xa0cd('0x6'));var util=require('util');var path=require(_0xa0cd('0x7'));var sox=require(_0xa0cd('0x8'));var csv=require(_0xa0cd('0x9'));var ejs=require(_0xa0cd('0xa'));var fs=require('fs');var _=require(_0xa0cd('0xb'));var squel=require(_0xa0cd('0xc'));var crypto=require(_0xa0cd('0xd'));var jsforce=require(_0xa0cd('0xe'));var deskjs=require(_0xa0cd('0xf'));var toCsv=require(_0xa0cd('0x9'));var querystring=require(_0xa0cd('0x10'));var Papa=require(_0xa0cd('0x11'));var Redis=require('ioredis');var authService=require(_0xa0cd('0x12'));var qs=require(_0xa0cd('0x13'));var as=require(_0xa0cd('0x14'));var hardwareService=require(_0xa0cd('0x15'));var logger=require(_0xa0cd('0x16'))('api');var utils=require('../../config/utils');var config=require(_0xa0cd('0x17'));var db=require(_0xa0cd('0x18'))['db'];function respondWithStatusCode(_0x464e23,_0x223f50){_0x223f50=_0x223f50||0xcc;return function(_0x3510e8){if(_0x3510e8){return _0x464e23[_0xa0cd('0x19')](_0x223f50);}return _0x464e23[_0xa0cd('0x1a')](_0x223f50)[_0xa0cd('0x1b')]();};}function respondWithResult(_0x3bfe4a,_0x13c2e8){_0x13c2e8=_0x13c2e8||0xc8;return function(_0x3c0e43){if(_0x3c0e43){return _0x3bfe4a[_0xa0cd('0x1a')](_0x13c2e8)[_0xa0cd('0x1c')](_0x3c0e43);}};}function respondWithFilteredResult(_0x44714e,_0x269ba9){return function(_0x482a5b){if(_0x482a5b){var _0x21e155=_0x482a5b[_0xa0cd('0x1d')],_0x1efaa4=_0x269ba9[_0xa0cd('0x1e')],_0x39599e=_0x269ba9['offset']+_0x269ba9[_0xa0cd('0x1f')],_0x3a3e63;if(_0x39599e>=_0x21e155){_0x39599e=_0x21e155;_0x3a3e63=0xc8;}else{_0x3a3e63=0xce;}_0x44714e['status'](_0x3a3e63);return _0x44714e[_0xa0cd('0x20')](_0xa0cd('0x21'),_0x1efaa4+'-'+_0x39599e+'/'+_0x21e155)[_0xa0cd('0x1c')](_0x482a5b);}return null;};}function patchUpdates(_0x58e618){return function(_0x358952){try{jsonpatch[_0xa0cd('0x22')](_0x358952,_0x58e618,!![]);}catch(_0xb41622){return BPromise[_0xa0cd('0x23')](_0xb41622);}return _0x358952[_0xa0cd('0x24')]();};}function saveUpdates(_0x2f0e0f,_0x32ffc7){return function(_0x5db6eb){if(_0x5db6eb){return _0x5db6eb['update'](_0x2f0e0f)[_0xa0cd('0x25')](function(_0x3fbf69){return _0x3fbf69;});}return null;};}function removeEntity(_0x38c4ef,_0x979962){return function(_0x366c93){if(_0x366c93){return _0x366c93[_0xa0cd('0x26')]()[_0xa0cd('0x25')](function(){_0x38c4ef['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x474c75,_0x16bdd9){return function(_0x4803a0){if(!_0x4803a0){_0x474c75[_0xa0cd('0x19')](0x194);}return _0x4803a0;};}function handleError(_0x1d687f,_0x13357c){_0x13357c=_0x13357c||0x1f4;return function(_0x182f82){logger[_0xa0cd('0x27')](_0x182f82[_0xa0cd('0x28')]);if(_0x182f82[_0xa0cd('0x29')]){delete _0x182f82[_0xa0cd('0x29')];}_0x1d687f[_0xa0cd('0x1a')](_0x13357c)[_0xa0cd('0x2a')](_0x182f82);};}exports['index']=function(_0x4cb2b1,_0x591d9c){var _0xd5e675={},_0x323e1b={},_0x1eb3ec={'count':0x0,'rows':[]};var _0x2679ae=_[_0xa0cd('0x2b')](db[_0xa0cd('0x2c')][_0xa0cd('0x2d')],function(_0x1104c6){return{'name':_0x1104c6['fieldName'],'type':_0x1104c6[_0xa0cd('0x2e')][_0xa0cd('0x2f')]};});_0x323e1b[_0xa0cd('0x30')]=_[_0xa0cd('0x2b')](_0x2679ae,'name');_0x323e1b[_0xa0cd('0x31')]=_[_0xa0cd('0x32')](_0x4cb2b1['query']);_0x323e1b[_0xa0cd('0x33')]=_['intersection'](_0x323e1b['model'],_0x323e1b[_0xa0cd('0x31')]);_0xd5e675[_0xa0cd('0x34')]=_[_0xa0cd('0x35')](_0x323e1b[_0xa0cd('0x30')],qs[_0xa0cd('0x36')](_0x4cb2b1[_0xa0cd('0x31')][_0xa0cd('0x36')]));_0xd5e675['attributes']=_0xd5e675[_0xa0cd('0x34')]['length']?_0xd5e675[_0xa0cd('0x34')]:_0x323e1b[_0xa0cd('0x30')];if(!_0x4cb2b1[_0xa0cd('0x31')][_0xa0cd('0x37')]('nolimit')){_0xd5e675[_0xa0cd('0x1f')]=qs[_0xa0cd('0x1f')](_0x4cb2b1[_0xa0cd('0x31')]['limit']);_0xd5e675[_0xa0cd('0x1e')]=qs[_0xa0cd('0x1e')](_0x4cb2b1[_0xa0cd('0x31')][_0xa0cd('0x1e')]);}_0xd5e675[_0xa0cd('0x38')]=qs[_0xa0cd('0x39')](_0x4cb2b1['query'][_0xa0cd('0x39')]);_0xd5e675[_0xa0cd('0x3a')]=qs['filters'](_[_0xa0cd('0x3b')](_0x4cb2b1[_0xa0cd('0x31')],_0x323e1b[_0xa0cd('0x33')]));if(_0x4cb2b1[_0xa0cd('0x31')][_0xa0cd('0x3c')]){_0xd5e675[_0xa0cd('0x3a')]=_[_0xa0cd('0x3d')](_0xd5e675[_0xa0cd('0x3a')],{'$or':_[_0xa0cd('0x2b')](_0x2679ae,function(_0x1a1957){if(_0x1a1957[_0xa0cd('0x2e')]!==_0xa0cd('0x3e')){var _0x22b038={};_0x22b038[_0x1a1957[_0xa0cd('0x29')]]={'$like':'%'+_0x4cb2b1['query'][_0xa0cd('0x3c')]+'%'};return _0x22b038;}})});}_0xd5e675=_[_0xa0cd('0x3d')]({},_0xd5e675,_0x4cb2b1[_0xa0cd('0x3f')]);var _0x10d060={'where':_0xd5e675[_0xa0cd('0x3a')]};return db[_0xa0cd('0x2c')][_0xa0cd('0x1d')](_0x10d060)[_0xa0cd('0x25')](function(_0x5c3554){_0x1eb3ec[_0xa0cd('0x1d')]=_0x5c3554;if(_0x4cb2b1['query'][_0xa0cd('0x40')]){_0xd5e675['include']=[{'all':!![]}];}return db[_0xa0cd('0x2c')]['findAll'](_0xd5e675);})[_0xa0cd('0x25')](function(_0xe6bc52){_0x1eb3ec[_0xa0cd('0x41')]=_0xe6bc52;return _0x1eb3ec;})[_0xa0cd('0x25')](respondWithFilteredResult(_0x591d9c,_0xd5e675))[_0xa0cd('0x42')](handleError(_0x591d9c,null));};exports[_0xa0cd('0x43')]=function(_0x4497e7,_0x38a880){var _0x1de1db={'raw':![],'where':{'id':_0x4497e7[_0xa0cd('0x44')]['id']}},_0x2923ff={};_0x2923ff[_0xa0cd('0x30')]=_[_0xa0cd('0x32')](db[_0xa0cd('0x2c')][_0xa0cd('0x2d')]);_0x2923ff[_0xa0cd('0x31')]=_['keys'](_0x4497e7['query']);_0x2923ff[_0xa0cd('0x33')]=_[_0xa0cd('0x35')](_0x2923ff[_0xa0cd('0x30')],_0x2923ff[_0xa0cd('0x31')]);_0x1de1db['attributes']=_[_0xa0cd('0x35')](_0x2923ff[_0xa0cd('0x30')],qs['fields'](_0x4497e7[_0xa0cd('0x31')][_0xa0cd('0x36')]));_0x1de1db[_0xa0cd('0x34')]=_0x1de1db['attributes'][_0xa0cd('0x45')]?_0x1de1db['attributes']:_0x2923ff[_0xa0cd('0x30')];if(_0x4497e7[_0xa0cd('0x31')][_0xa0cd('0x40')]){_0x1de1db['include']=[{'all':!![]}];}_0x1de1db=_['merge']({},_0x1de1db,_0x4497e7['options']);return db[_0xa0cd('0x2c')][_0xa0cd('0x46')](_0x1de1db)[_0xa0cd('0x25')](handleEntityNotFound(_0x38a880,null))[_0xa0cd('0x25')](respondWithResult(_0x38a880,null))[_0xa0cd('0x42')](handleError(_0x38a880,null));};exports['create']=function(_0x1ae7ca,_0x3d4d3f){return db[_0xa0cd('0x2c')][_0xa0cd('0x47')](_0x1ae7ca[_0xa0cd('0x48')],{})[_0xa0cd('0x25')](respondWithResult(_0x3d4d3f,0xc9))['catch'](handleError(_0x3d4d3f,null));};exports[_0xa0cd('0x49')]=function(_0x3054e2,_0x38a28d){if(_0x3054e2[_0xa0cd('0x48')]['id']){delete _0x3054e2['body']['id'];}return db[_0xa0cd('0x2c')][_0xa0cd('0x46')]({'where':{'id':_0x3054e2[_0xa0cd('0x44')]['id']}})[_0xa0cd('0x25')](handleEntityNotFound(_0x38a28d,null))[_0xa0cd('0x25')](saveUpdates(_0x3054e2[_0xa0cd('0x48')],null))[_0xa0cd('0x25')](respondWithResult(_0x38a28d,null))['catch'](handleError(_0x38a28d,null));};exports[_0xa0cd('0x26')]=function(_0x4dc2f3,_0x396820){return db['UserProfileSection'][_0xa0cd('0x46')]({'where':{'id':_0x4dc2f3[_0xa0cd('0x44')]['id']}})[_0xa0cd('0x25')](handleEntityNotFound(_0x396820,null))[_0xa0cd('0x25')](removeEntity(_0x396820,null))[_0xa0cd('0x42')](handleError(_0x396820,null));};exports[_0xa0cd('0x4a')]=function(_0x158716,_0x50e639){return db[_0xa0cd('0x2c')][_0xa0cd('0x4a')]()[_0xa0cd('0x25')](respondWithResult(_0x50e639,null))['catch'](handleError(_0x50e639,null));};