Built motion from commit 97153652.|2.6.26
[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 _0xcf68=['index','map','UserProfileSection','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','offset','order','sort','pick','filter','merge','where','VIRTUAL','options','includeAll','findAll','rows','catch','show','rawAttributes','find','create','body','params','describe','eml-format','zip-dir','mustache','util','path','ejs','fs-extra','squel','desk.js','to-csv','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','set','apply','reject','save','update','destroy','then','error','stack','name'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xcf68,0x136));var _0x8cf6=function(_0x3b0731,_0xcf9925){_0x3b0731=_0x3b0731-0x0;var _0x4204d7=_0xcf68[_0x3b0731];return _0x4204d7;};'use strict';var emlformat=require(_0x8cf6('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x8cf6('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x8cf6('0x2'));var util=require(_0x8cf6('0x3'));var path=require(_0x8cf6('0x4'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x8cf6('0x5'));var fs=require('fs');var fs_extra=require(_0x8cf6('0x6'));var _=require('lodash');var squel=require(_0x8cf6('0x7'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x8cf6('0x8'));var toCsv=require(_0x8cf6('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x8cf6('0xa'));var authService=require('../../components/auth/service');var qs=require(_0x8cf6('0xb'));var as=require(_0x8cf6('0xc'));var hardwareService=require(_0x8cf6('0xd'));var logger=require(_0x8cf6('0xe'))('api');var utils=require(_0x8cf6('0xf'));var config=require('../../config/environment');var licenseUtil=require(_0x8cf6('0x10'));var db=require(_0x8cf6('0x11'))['db'];function respondWithStatusCode(_0x1351eb,_0x1bcbdf){_0x1bcbdf=_0x1bcbdf||0xcc;return function(_0x17ff3f){if(_0x17ff3f){return _0x1351eb[_0x8cf6('0x12')](_0x1bcbdf);}return _0x1351eb[_0x8cf6('0x13')](_0x1bcbdf)[_0x8cf6('0x14')]();};}function respondWithResult(_0x2db173,_0x22b39e){_0x22b39e=_0x22b39e||0xc8;return function(_0x3f62d9){if(_0x3f62d9){return _0x2db173[_0x8cf6('0x13')](_0x22b39e)[_0x8cf6('0x15')](_0x3f62d9);}};}function respondWithFilteredResult(_0x3958a6,_0xa5a52d){return function(_0x1c544d){if(_0x1c544d){var _0x14acbc=typeof _0xa5a52d['offset']===_0x8cf6('0x16')&&typeof _0xa5a52d[_0x8cf6('0x17')]===_0x8cf6('0x16');var _0x40cffa=_0x1c544d['count'];var _0x4bc1ca=_0x14acbc?0x0:_0xa5a52d['offset'];var _0x3eacca=_0x14acbc?_0x1c544d[_0x8cf6('0x18')]:_0xa5a52d['offset']+_0xa5a52d[_0x8cf6('0x17')];var _0x233d06;if(_0x3eacca>=_0x40cffa){_0x3eacca=_0x40cffa;_0x233d06=0xc8;}else{_0x233d06=0xce;}_0x3958a6['status'](_0x233d06);return _0x3958a6[_0x8cf6('0x19')]('Content-Range',_0x4bc1ca+'-'+_0x3eacca+'/'+_0x40cffa)['json'](_0x1c544d);}return null;};}function patchUpdates(_0x23fffb){return function(_0x47e6b7){try{jsonpatch[_0x8cf6('0x1a')](_0x47e6b7,_0x23fffb,!![]);}catch(_0x735cb4){return BPromise[_0x8cf6('0x1b')](_0x735cb4);}return _0x47e6b7[_0x8cf6('0x1c')]();};}function saveUpdates(_0x3daf4d,_0x39f305){return function(_0x74f371){if(_0x74f371){return _0x74f371[_0x8cf6('0x1d')](_0x3daf4d)['then'](function(_0x27b990){return _0x27b990;});}return null;};}function removeEntity(_0x564e2b,_0x432c46){return function(_0x2ff8e9){if(_0x2ff8e9){return _0x2ff8e9[_0x8cf6('0x1e')]()[_0x8cf6('0x1f')](function(){_0x564e2b[_0x8cf6('0x13')](0xcc)['end']();});}};}function handleEntityNotFound(_0x83b956,_0x47804c){return function(_0x118e9e){if(!_0x118e9e){_0x83b956[_0x8cf6('0x12')](0x194);}return _0x118e9e;};}function handleError(_0x1d3402,_0x256c99){_0x256c99=_0x256c99||0x1f4;return function(_0x231ce4){logger[_0x8cf6('0x20')](_0x231ce4[_0x8cf6('0x21')]);if(_0x231ce4[_0x8cf6('0x22')]){delete _0x231ce4[_0x8cf6('0x22')];}_0x1d3402['status'](_0x256c99)['send'](_0x231ce4);};}exports[_0x8cf6('0x23')]=function(_0x2303da,_0x5beee8){var _0x1e6a97={},_0x5d7805={},_0x1398fe={'count':0x0,'rows':[]};var _0x3b2d1e=_[_0x8cf6('0x24')](db[_0x8cf6('0x25')]['rawAttributes'],function(_0xe6dd22){return{'name':_0xe6dd22['fieldName'],'type':_0xe6dd22[_0x8cf6('0x26')][_0x8cf6('0x27')]};});_0x5d7805[_0x8cf6('0x28')]=_['map'](_0x3b2d1e,_0x8cf6('0x22'));_0x5d7805[_0x8cf6('0x29')]=_[_0x8cf6('0x2a')](_0x2303da[_0x8cf6('0x29')]);_0x5d7805[_0x8cf6('0x2b')]=_[_0x8cf6('0x2c')](_0x5d7805[_0x8cf6('0x28')],_0x5d7805[_0x8cf6('0x29')]);_0x1e6a97['attributes']=_['intersection'](_0x5d7805['model'],qs[_0x8cf6('0x2d')](_0x2303da[_0x8cf6('0x29')][_0x8cf6('0x2d')]));_0x1e6a97[_0x8cf6('0x2e')]=_0x1e6a97['attributes'][_0x8cf6('0x2f')]?_0x1e6a97[_0x8cf6('0x2e')]:_0x5d7805['model'];if(!_0x2303da[_0x8cf6('0x29')][_0x8cf6('0x30')]('nolimit')){_0x1e6a97[_0x8cf6('0x17')]=qs['limit'](_0x2303da[_0x8cf6('0x29')][_0x8cf6('0x17')]);_0x1e6a97[_0x8cf6('0x31')]=qs[_0x8cf6('0x31')](_0x2303da['query']['offset']);}_0x1e6a97[_0x8cf6('0x32')]=qs['sort'](_0x2303da[_0x8cf6('0x29')][_0x8cf6('0x33')]);_0x1e6a97['where']=qs[_0x8cf6('0x2b')](_[_0x8cf6('0x34')](_0x2303da[_0x8cf6('0x29')],_0x5d7805[_0x8cf6('0x2b')]),_0x3b2d1e);if(_0x2303da[_0x8cf6('0x29')][_0x8cf6('0x35')]){_0x1e6a97['where']=_[_0x8cf6('0x36')](_0x1e6a97[_0x8cf6('0x37')],{'$or':_[_0x8cf6('0x24')](_0x3b2d1e,function(_0xc57a00){if(_0xc57a00[_0x8cf6('0x26')]!==_0x8cf6('0x38')){var _0x4c4b09={};_0x4c4b09[_0xc57a00['name']]={'$like':'%'+_0x2303da['query'][_0x8cf6('0x35')]+'%'};return _0x4c4b09;}})});}_0x1e6a97=_[_0x8cf6('0x36')]({},_0x1e6a97,_0x2303da[_0x8cf6('0x39')]);var _0x2175eb={'where':_0x1e6a97[_0x8cf6('0x37')]};return db[_0x8cf6('0x25')][_0x8cf6('0x18')](_0x2175eb)['then'](function(_0xc8df94){_0x1398fe[_0x8cf6('0x18')]=_0xc8df94;if(_0x2303da['query'][_0x8cf6('0x3a')]){_0x1e6a97['include']=[{'all':!![]}];}return db[_0x8cf6('0x25')][_0x8cf6('0x3b')](_0x1e6a97);})[_0x8cf6('0x1f')](function(_0x4abd1a){_0x1398fe[_0x8cf6('0x3c')]=_0x4abd1a;return _0x1398fe;})[_0x8cf6('0x1f')](respondWithFilteredResult(_0x5beee8,_0x1e6a97))[_0x8cf6('0x3d')](handleError(_0x5beee8,null));};exports[_0x8cf6('0x3e')]=function(_0x59d376,_0x583037){var _0x456b68={'raw':![],'where':{'id':_0x59d376['params']['id']}},_0x2158c0={};_0x2158c0[_0x8cf6('0x28')]=_[_0x8cf6('0x2a')](db[_0x8cf6('0x25')][_0x8cf6('0x3f')]);_0x2158c0[_0x8cf6('0x29')]=_[_0x8cf6('0x2a')](_0x59d376[_0x8cf6('0x29')]);_0x2158c0[_0x8cf6('0x2b')]=_['intersection'](_0x2158c0['model'],_0x2158c0[_0x8cf6('0x29')]);_0x456b68['attributes']=_['intersection'](_0x2158c0[_0x8cf6('0x28')],qs[_0x8cf6('0x2d')](_0x59d376['query'][_0x8cf6('0x2d')]));_0x456b68[_0x8cf6('0x2e')]=_0x456b68['attributes']['length']?_0x456b68[_0x8cf6('0x2e')]:_0x2158c0[_0x8cf6('0x28')];if(_0x59d376['query'][_0x8cf6('0x3a')]){_0x456b68['include']=[{'all':!![]}];}_0x456b68=_['merge']({},_0x456b68,_0x59d376[_0x8cf6('0x39')]);return db[_0x8cf6('0x25')][_0x8cf6('0x40')](_0x456b68)[_0x8cf6('0x1f')](handleEntityNotFound(_0x583037,null))[_0x8cf6('0x1f')](respondWithResult(_0x583037,null))[_0x8cf6('0x3d')](handleError(_0x583037,null));};exports[_0x8cf6('0x41')]=function(_0x4300fe,_0x35afbb){return db['UserProfileSection'][_0x8cf6('0x41')](_0x4300fe['body'],{})[_0x8cf6('0x1f')](respondWithResult(_0x35afbb,0xc9))['catch'](handleError(_0x35afbb,null));};exports['update']=function(_0x4acb79,_0x368a62){if(_0x4acb79[_0x8cf6('0x42')]['id']){delete _0x4acb79[_0x8cf6('0x42')]['id'];}return db[_0x8cf6('0x25')][_0x8cf6('0x40')]({'where':{'id':_0x4acb79[_0x8cf6('0x43')]['id']}})[_0x8cf6('0x1f')](handleEntityNotFound(_0x368a62,null))[_0x8cf6('0x1f')](saveUpdates(_0x4acb79[_0x8cf6('0x42')],null))[_0x8cf6('0x1f')](respondWithResult(_0x368a62,null))['catch'](handleError(_0x368a62,null));};exports['destroy']=function(_0x1d92dd,_0x2b10c0){return db[_0x8cf6('0x25')]['find']({'where':{'id':_0x1d92dd[_0x8cf6('0x43')]['id']}})[_0x8cf6('0x1f')](handleEntityNotFound(_0x2b10c0,null))['then'](removeEntity(_0x2b10c0,null))[_0x8cf6('0x3d')](handleError(_0x2b10c0,null));};exports[_0x8cf6('0x44')]=function(_0xef1654,_0x523612){return db[_0x8cf6('0x25')][_0x8cf6('0x44')]()['then'](respondWithResult(_0x523612,null))[_0x8cf6('0x3d')](handleError(_0x523612,null));};