Built motion from commit da24aabd.|2.6.20
[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 _0xda3d=['sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','count','limit','set','Content-Range','json','apply','reject','update','then','destroy','error','stack','send','index','map','UserProfileSection','type','key','model','query','keys','filters','intersection','attributes','fields','length','order','sort','where','pick','filter','merge','VIRTUAL','name','options','includeAll','include','findAll','rows','catch','show','params','rawAttributes','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path'];(function(_0x1cc8fe,_0x105328){var _0x230054=function(_0x1a1b56){while(--_0x1a1b56){_0x1cc8fe['push'](_0x1cc8fe['shift']());}};_0x230054(++_0x105328);}(_0xda3d,0xe6));var _0xdda3=function(_0xe38bb1,_0x38a9ff){_0xe38bb1=_0xe38bb1-0x0;var _0x431789=_0xda3d[_0xe38bb1];return _0x431789;};'use strict';var emlformat=require(_0xdda3('0x0'));var rimraf=require(_0xdda3('0x1'));var zipdir=require(_0xdda3('0x2'));var jsonpatch=require(_0xdda3('0x3'));var rp=require(_0xdda3('0x4'));var moment=require(_0xdda3('0x5'));var BPromise=require(_0xdda3('0x6'));var Mustache=require(_0xdda3('0x7'));var util=require(_0xdda3('0x8'));var path=require(_0xdda3('0x9'));var sox=require(_0xdda3('0xa'));var csv=require(_0xdda3('0xb'));var ejs=require(_0xdda3('0xc'));var fs=require('fs');var fs_extra=require(_0xdda3('0xd'));var _=require('lodash');var squel=require(_0xdda3('0xe'));var crypto=require(_0xdda3('0xf'));var jsforce=require(_0xdda3('0x10'));var deskjs=require(_0xdda3('0x11'));var toCsv=require('to-csv');var querystring=require(_0xdda3('0x12'));var Papa=require(_0xdda3('0x13'));var Redis=require(_0xdda3('0x14'));var authService=require('../../components/auth/service');var qs=require(_0xdda3('0x15'));var as=require(_0xdda3('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xdda3('0x17'))(_0xdda3('0x18'));var utils=require('../../config/utils');var config=require(_0xdda3('0x19'));var licenseUtil=require(_0xdda3('0x1a'));var db=require(_0xdda3('0x1b'))['db'];function respondWithStatusCode(_0x4ff1aa,_0x13de6f){_0x13de6f=_0x13de6f||0xcc;return function(_0x52696e){if(_0x52696e){return _0x4ff1aa[_0xdda3('0x1c')](_0x13de6f);}return _0x4ff1aa[_0xdda3('0x1d')](_0x13de6f)[_0xdda3('0x1e')]();};}function respondWithResult(_0xbab1ee,_0x5193c7){_0x5193c7=_0x5193c7||0xc8;return function(_0x57f37a){if(_0x57f37a){return _0xbab1ee['status'](_0x5193c7)['json'](_0x57f37a);}};}function respondWithFilteredResult(_0x5e138c,_0xdf9c9c){return function(_0x7d5878){if(_0x7d5878){var _0x65fa47=typeof _0xdf9c9c[_0xdda3('0x1f')]===_0xdda3('0x20')&&typeof _0xdf9c9c['limit']==='undefined';var _0x48993a=_0x7d5878[_0xdda3('0x21')];var _0x29478c=_0x65fa47?0x0:_0xdf9c9c[_0xdda3('0x1f')];var _0x5c5970=_0x65fa47?_0x7d5878[_0xdda3('0x21')]:_0xdf9c9c['offset']+_0xdf9c9c[_0xdda3('0x22')];var _0x3feb92;if(_0x5c5970>=_0x48993a){_0x5c5970=_0x48993a;_0x3feb92=0xc8;}else{_0x3feb92=0xce;}_0x5e138c[_0xdda3('0x1d')](_0x3feb92);return _0x5e138c[_0xdda3('0x23')](_0xdda3('0x24'),_0x29478c+'-'+_0x5c5970+'/'+_0x48993a)[_0xdda3('0x25')](_0x7d5878);}return null;};}function patchUpdates(_0x2b0163){return function(_0xf7249c){try{jsonpatch[_0xdda3('0x26')](_0xf7249c,_0x2b0163,!![]);}catch(_0x2557a8){return BPromise[_0xdda3('0x27')](_0x2557a8);}return _0xf7249c['save']();};}function saveUpdates(_0x237be2,_0x1ed2b7){return function(_0x1183f0){if(_0x1183f0){return _0x1183f0[_0xdda3('0x28')](_0x237be2)[_0xdda3('0x29')](function(_0x284aba){return _0x284aba;});}return null;};}function removeEntity(_0x1186c4,_0x1ce9c5){return function(_0x4e4ccd){if(_0x4e4ccd){return _0x4e4ccd[_0xdda3('0x2a')]()[_0xdda3('0x29')](function(){_0x1186c4[_0xdda3('0x1d')](0xcc)[_0xdda3('0x1e')]();});}};}function handleEntityNotFound(_0x104bab,_0x5f5446){return function(_0x168c76){if(!_0x168c76){_0x104bab['sendStatus'](0x194);}return _0x168c76;};}function handleError(_0x161f4f,_0x2b96ce){_0x2b96ce=_0x2b96ce||0x1f4;return function(_0x5d9fd1){logger[_0xdda3('0x2b')](_0x5d9fd1[_0xdda3('0x2c')]);if(_0x5d9fd1['name']){delete _0x5d9fd1['name'];}_0x161f4f['status'](_0x2b96ce)[_0xdda3('0x2d')](_0x5d9fd1);};}exports[_0xdda3('0x2e')]=function(_0x125363,_0x199aec){var _0x1f1f9f={},_0x3810f2={},_0xc63223={'count':0x0,'rows':[]};var _0x17c85b=_[_0xdda3('0x2f')](db[_0xdda3('0x30')]['rawAttributes'],function(_0x58cf67){return{'name':_0x58cf67['fieldName'],'type':_0x58cf67[_0xdda3('0x31')][_0xdda3('0x32')]};});_0x3810f2[_0xdda3('0x33')]=_[_0xdda3('0x2f')](_0x17c85b,'name');_0x3810f2[_0xdda3('0x34')]=_[_0xdda3('0x35')](_0x125363[_0xdda3('0x34')]);_0x3810f2[_0xdda3('0x36')]=_[_0xdda3('0x37')](_0x3810f2['model'],_0x3810f2[_0xdda3('0x34')]);_0x1f1f9f[_0xdda3('0x38')]=_[_0xdda3('0x37')](_0x3810f2[_0xdda3('0x33')],qs[_0xdda3('0x39')](_0x125363[_0xdda3('0x34')][_0xdda3('0x39')]));_0x1f1f9f[_0xdda3('0x38')]=_0x1f1f9f[_0xdda3('0x38')][_0xdda3('0x3a')]?_0x1f1f9f[_0xdda3('0x38')]:_0x3810f2[_0xdda3('0x33')];if(!_0x125363['query']['hasOwnProperty']('nolimit')){_0x1f1f9f[_0xdda3('0x22')]=qs[_0xdda3('0x22')](_0x125363['query'][_0xdda3('0x22')]);_0x1f1f9f[_0xdda3('0x1f')]=qs[_0xdda3('0x1f')](_0x125363['query'][_0xdda3('0x1f')]);}_0x1f1f9f[_0xdda3('0x3b')]=qs[_0xdda3('0x3c')](_0x125363[_0xdda3('0x34')]['sort']);_0x1f1f9f[_0xdda3('0x3d')]=qs[_0xdda3('0x36')](_[_0xdda3('0x3e')](_0x125363[_0xdda3('0x34')],_0x3810f2['filters']),_0x17c85b);if(_0x125363[_0xdda3('0x34')][_0xdda3('0x3f')]){_0x1f1f9f[_0xdda3('0x3d')]=_[_0xdda3('0x40')](_0x1f1f9f['where'],{'$or':_[_0xdda3('0x2f')](_0x17c85b,function(_0x596618){if(_0x596618[_0xdda3('0x31')]!==_0xdda3('0x41')){var _0xb5ec3d={};_0xb5ec3d[_0x596618[_0xdda3('0x42')]]={'$like':'%'+_0x125363[_0xdda3('0x34')][_0xdda3('0x3f')]+'%'};return _0xb5ec3d;}})});}_0x1f1f9f=_[_0xdda3('0x40')]({},_0x1f1f9f,_0x125363[_0xdda3('0x43')]);var _0x8a9dac={'where':_0x1f1f9f[_0xdda3('0x3d')]};return db['UserProfileSection']['count'](_0x8a9dac)[_0xdda3('0x29')](function(_0xad7e8f){_0xc63223[_0xdda3('0x21')]=_0xad7e8f;if(_0x125363['query'][_0xdda3('0x44')]){_0x1f1f9f[_0xdda3('0x45')]=[{'all':!![]}];}return db[_0xdda3('0x30')][_0xdda3('0x46')](_0x1f1f9f);})[_0xdda3('0x29')](function(_0x462ae8){_0xc63223[_0xdda3('0x47')]=_0x462ae8;return _0xc63223;})[_0xdda3('0x29')](respondWithFilteredResult(_0x199aec,_0x1f1f9f))[_0xdda3('0x48')](handleError(_0x199aec,null));};exports[_0xdda3('0x49')]=function(_0x4ff3ed,_0x7b08f8){var _0x43ea49={'raw':![],'where':{'id':_0x4ff3ed[_0xdda3('0x4a')]['id']}},_0x17edd0={};_0x17edd0[_0xdda3('0x33')]=_[_0xdda3('0x35')](db['UserProfileSection'][_0xdda3('0x4b')]);_0x17edd0[_0xdda3('0x34')]=_[_0xdda3('0x35')](_0x4ff3ed[_0xdda3('0x34')]);_0x17edd0[_0xdda3('0x36')]=_[_0xdda3('0x37')](_0x17edd0['model'],_0x17edd0['query']);_0x43ea49[_0xdda3('0x38')]=_[_0xdda3('0x37')](_0x17edd0[_0xdda3('0x33')],qs[_0xdda3('0x39')](_0x4ff3ed[_0xdda3('0x34')][_0xdda3('0x39')]));_0x43ea49[_0xdda3('0x38')]=_0x43ea49['attributes']['length']?_0x43ea49[_0xdda3('0x38')]:_0x17edd0[_0xdda3('0x33')];if(_0x4ff3ed[_0xdda3('0x34')][_0xdda3('0x44')]){_0x43ea49['include']=[{'all':!![]}];}_0x43ea49=_[_0xdda3('0x40')]({},_0x43ea49,_0x4ff3ed['options']);return db['UserProfileSection'][_0xdda3('0x4c')](_0x43ea49)[_0xdda3('0x29')](handleEntityNotFound(_0x7b08f8,null))[_0xdda3('0x29')](respondWithResult(_0x7b08f8,null))['catch'](handleError(_0x7b08f8,null));};exports[_0xdda3('0x4d')]=function(_0x721b56,_0x3b99e4){return db['UserProfileSection']['create'](_0x721b56['body'],{})[_0xdda3('0x29')](respondWithResult(_0x3b99e4,0xc9))[_0xdda3('0x48')](handleError(_0x3b99e4,null));};exports[_0xdda3('0x28')]=function(_0x400b5c,_0x2ea5ad){if(_0x400b5c[_0xdda3('0x4e')]['id']){delete _0x400b5c[_0xdda3('0x4e')]['id'];}return db[_0xdda3('0x30')]['find']({'where':{'id':_0x400b5c[_0xdda3('0x4a')]['id']}})[_0xdda3('0x29')](handleEntityNotFound(_0x2ea5ad,null))[_0xdda3('0x29')](saveUpdates(_0x400b5c['body'],null))[_0xdda3('0x29')](respondWithResult(_0x2ea5ad,null))['catch'](handleError(_0x2ea5ad,null));};exports[_0xdda3('0x2a')]=function(_0x50b760,_0x27788a){return db[_0xdda3('0x30')][_0xdda3('0x4c')]({'where':{'id':_0x50b760[_0xdda3('0x4a')]['id']}})[_0xdda3('0x29')](handleEntityNotFound(_0x27788a,null))[_0xdda3('0x29')](removeEntity(_0x27788a,null))[_0xdda3('0x48')](handleError(_0x27788a,null));};exports[_0xdda3('0x4f')]=function(_0x7f020,_0x8d3dd0){return db[_0xdda3('0x30')][_0xdda3('0x4f')]()[_0xdda3('0x29')](respondWithResult(_0x8d3dd0,null))[_0xdda3('0x48')](handleError(_0x8d3dd0,null));};