Built motion from commit 64440dd5.|2.6.29
[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 _0xb5f5=['hasOwnProperty','nolimit','order','sort','pick','filter','where','map','merge','includeAll','include','rows','catch','show','params','options','find','create','body','describe','eml-format','rimraf','zip-dir','request-promise','moment','mustache','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','Content-Range','save','update','destroy','then','error','stack','name','send','index','UserProfileSection','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length'];(function(_0x1d91c6,_0x6d90ba){var _0x29ce25=function(_0x55645c){while(--_0x55645c){_0x1d91c6['push'](_0x1d91c6['shift']());}};_0x29ce25(++_0x6d90ba);}(_0xb5f5,0xf8));var _0x5b5f=function(_0x16f4e5,_0x2de654){_0x16f4e5=_0x16f4e5-0x0;var _0x4fd22e=_0xb5f5[_0x16f4e5];return _0x4fd22e;};'use strict';var emlformat=require(_0x5b5f('0x0'));var rimraf=require(_0x5b5f('0x1'));var zipdir=require(_0x5b5f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x5b5f('0x3'));var moment=require(_0x5b5f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x5b5f('0x5'));var util=require('util');var path=require(_0x5b5f('0x6'));var sox=require(_0x5b5f('0x7'));var csv=require('to-csv');var ejs=require(_0x5b5f('0x8'));var fs=require('fs');var fs_extra=require(_0x5b5f('0x9'));var _=require(_0x5b5f('0xa'));var squel=require(_0x5b5f('0xb'));var crypto=require(_0x5b5f('0xc'));var jsforce=require(_0x5b5f('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x5b5f('0xe'));var querystring=require(_0x5b5f('0xf'));var Papa=require(_0x5b5f('0x10'));var Redis=require('ioredis');var authService=require(_0x5b5f('0x11'));var qs=require(_0x5b5f('0x12'));var as=require(_0x5b5f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x5b5f('0x14'))(_0x5b5f('0x15'));var utils=require(_0x5b5f('0x16'));var config=require(_0x5b5f('0x17'));var licenseUtil=require(_0x5b5f('0x18'));var db=require(_0x5b5f('0x19'))['db'];function respondWithStatusCode(_0x2bdd40,_0x1602d6){_0x1602d6=_0x1602d6||0xcc;return function(_0x5b4f01){if(_0x5b4f01){return _0x2bdd40['sendStatus'](_0x1602d6);}return _0x2bdd40[_0x5b5f('0x1a')](_0x1602d6)[_0x5b5f('0x1b')]();};}function respondWithResult(_0x5a9406,_0x4f2033){_0x4f2033=_0x4f2033||0xc8;return function(_0x325aa1){if(_0x325aa1){return _0x5a9406[_0x5b5f('0x1a')](_0x4f2033)[_0x5b5f('0x1c')](_0x325aa1);}};}function respondWithFilteredResult(_0x2ab98f,_0x1b9bed){return function(_0x856707){if(_0x856707){var _0x4273cb=typeof _0x1b9bed[_0x5b5f('0x1d')]===_0x5b5f('0x1e')&&typeof _0x1b9bed[_0x5b5f('0x1f')]===_0x5b5f('0x1e');var _0x5c0776=_0x856707[_0x5b5f('0x20')];var _0x249f0e=_0x4273cb?0x0:_0x1b9bed[_0x5b5f('0x1d')];var _0x162638=_0x4273cb?_0x856707[_0x5b5f('0x20')]:_0x1b9bed[_0x5b5f('0x1d')]+_0x1b9bed['limit'];var _0x518413;if(_0x162638>=_0x5c0776){_0x162638=_0x5c0776;_0x518413=0xc8;}else{_0x518413=0xce;}_0x2ab98f[_0x5b5f('0x1a')](_0x518413);return _0x2ab98f['set'](_0x5b5f('0x21'),_0x249f0e+'-'+_0x162638+'/'+_0x5c0776)['json'](_0x856707);}return null;};}function patchUpdates(_0x2e973d){return function(_0x470b78){try{jsonpatch['apply'](_0x470b78,_0x2e973d,!![]);}catch(_0x235fb4){return BPromise['reject'](_0x235fb4);}return _0x470b78[_0x5b5f('0x22')]();};}function saveUpdates(_0x3c5bfb,_0x3188f9){return function(_0x30cbe5){if(_0x30cbe5){return _0x30cbe5[_0x5b5f('0x23')](_0x3c5bfb)['then'](function(_0x681c42){return _0x681c42;});}return null;};}function removeEntity(_0x1bb64a,_0x1cd3fe){return function(_0x228b61){if(_0x228b61){return _0x228b61[_0x5b5f('0x24')]()[_0x5b5f('0x25')](function(){_0x1bb64a['status'](0xcc)[_0x5b5f('0x1b')]();});}};}function handleEntityNotFound(_0x429e0d,_0x5dee8b){return function(_0x31a896){if(!_0x31a896){_0x429e0d['sendStatus'](0x194);}return _0x31a896;};}function handleError(_0x1b9717,_0x2c691a){_0x2c691a=_0x2c691a||0x1f4;return function(_0x3d56f6){logger[_0x5b5f('0x26')](_0x3d56f6[_0x5b5f('0x27')]);if(_0x3d56f6[_0x5b5f('0x28')]){delete _0x3d56f6[_0x5b5f('0x28')];}_0x1b9717[_0x5b5f('0x1a')](_0x2c691a)[_0x5b5f('0x29')](_0x3d56f6);};}exports[_0x5b5f('0x2a')]=function(_0x24070b,_0x21de42){var _0x46ed0e={},_0x1a4c1a={},_0x513c4d={'count':0x0,'rows':[]};var _0x58163c=_['map'](db[_0x5b5f('0x2b')][_0x5b5f('0x2c')],function(_0x53d47c){return{'name':_0x53d47c[_0x5b5f('0x2d')],'type':_0x53d47c[_0x5b5f('0x2e')][_0x5b5f('0x2f')]};});_0x1a4c1a[_0x5b5f('0x30')]=_['map'](_0x58163c,'name');_0x1a4c1a[_0x5b5f('0x31')]=_[_0x5b5f('0x32')](_0x24070b[_0x5b5f('0x31')]);_0x1a4c1a[_0x5b5f('0x33')]=_[_0x5b5f('0x34')](_0x1a4c1a[_0x5b5f('0x30')],_0x1a4c1a[_0x5b5f('0x31')]);_0x46ed0e['attributes']=_[_0x5b5f('0x34')](_0x1a4c1a[_0x5b5f('0x30')],qs[_0x5b5f('0x35')](_0x24070b[_0x5b5f('0x31')][_0x5b5f('0x35')]));_0x46ed0e[_0x5b5f('0x36')]=_0x46ed0e[_0x5b5f('0x36')][_0x5b5f('0x37')]?_0x46ed0e['attributes']:_0x1a4c1a['model'];if(!_0x24070b['query'][_0x5b5f('0x38')](_0x5b5f('0x39'))){_0x46ed0e[_0x5b5f('0x1f')]=qs[_0x5b5f('0x1f')](_0x24070b[_0x5b5f('0x31')][_0x5b5f('0x1f')]);_0x46ed0e[_0x5b5f('0x1d')]=qs['offset'](_0x24070b[_0x5b5f('0x31')]['offset']);}_0x46ed0e[_0x5b5f('0x3a')]=qs[_0x5b5f('0x3b')](_0x24070b['query']['sort']);_0x46ed0e['where']=qs['filters'](_[_0x5b5f('0x3c')](_0x24070b[_0x5b5f('0x31')],_0x1a4c1a[_0x5b5f('0x33')]),_0x58163c);if(_0x24070b['query'][_0x5b5f('0x3d')]){_0x46ed0e[_0x5b5f('0x3e')]=_['merge'](_0x46ed0e['where'],{'$or':_[_0x5b5f('0x3f')](_0x58163c,function(_0x1a6f75){if(_0x1a6f75[_0x5b5f('0x2e')]!=='VIRTUAL'){var _0x1d8d8d={};_0x1d8d8d[_0x1a6f75[_0x5b5f('0x28')]]={'$like':'%'+_0x24070b[_0x5b5f('0x31')][_0x5b5f('0x3d')]+'%'};return _0x1d8d8d;}})});}_0x46ed0e=_[_0x5b5f('0x40')]({},_0x46ed0e,_0x24070b['options']);var _0x49ee59={'where':_0x46ed0e[_0x5b5f('0x3e')]};return db[_0x5b5f('0x2b')][_0x5b5f('0x20')](_0x49ee59)[_0x5b5f('0x25')](function(_0x317df3){_0x513c4d['count']=_0x317df3;if(_0x24070b[_0x5b5f('0x31')][_0x5b5f('0x41')]){_0x46ed0e[_0x5b5f('0x42')]=[{'all':!![]}];}return db[_0x5b5f('0x2b')]['findAll'](_0x46ed0e);})[_0x5b5f('0x25')](function(_0x151f7a){_0x513c4d[_0x5b5f('0x43')]=_0x151f7a;return _0x513c4d;})[_0x5b5f('0x25')](respondWithFilteredResult(_0x21de42,_0x46ed0e))[_0x5b5f('0x44')](handleError(_0x21de42,null));};exports[_0x5b5f('0x45')]=function(_0x107ffd,_0x3770ff){var _0x37db4f={'raw':![],'where':{'id':_0x107ffd[_0x5b5f('0x46')]['id']}},_0xf08c43={};_0xf08c43[_0x5b5f('0x30')]=_['keys'](db['UserProfileSection'][_0x5b5f('0x2c')]);_0xf08c43['query']=_[_0x5b5f('0x32')](_0x107ffd[_0x5b5f('0x31')]);_0xf08c43[_0x5b5f('0x33')]=_[_0x5b5f('0x34')](_0xf08c43['model'],_0xf08c43[_0x5b5f('0x31')]);_0x37db4f[_0x5b5f('0x36')]=_[_0x5b5f('0x34')](_0xf08c43[_0x5b5f('0x30')],qs[_0x5b5f('0x35')](_0x107ffd[_0x5b5f('0x31')][_0x5b5f('0x35')]));_0x37db4f['attributes']=_0x37db4f['attributes'][_0x5b5f('0x37')]?_0x37db4f[_0x5b5f('0x36')]:_0xf08c43[_0x5b5f('0x30')];if(_0x107ffd[_0x5b5f('0x31')]['includeAll']){_0x37db4f[_0x5b5f('0x42')]=[{'all':!![]}];}_0x37db4f=_[_0x5b5f('0x40')]({},_0x37db4f,_0x107ffd[_0x5b5f('0x47')]);return db[_0x5b5f('0x2b')][_0x5b5f('0x48')](_0x37db4f)['then'](handleEntityNotFound(_0x3770ff,null))[_0x5b5f('0x25')](respondWithResult(_0x3770ff,null))[_0x5b5f('0x44')](handleError(_0x3770ff,null));};exports[_0x5b5f('0x49')]=function(_0x3701e1,_0x3147aa){return db[_0x5b5f('0x2b')][_0x5b5f('0x49')](_0x3701e1[_0x5b5f('0x4a')],{})[_0x5b5f('0x25')](respondWithResult(_0x3147aa,0xc9))[_0x5b5f('0x44')](handleError(_0x3147aa,null));};exports[_0x5b5f('0x23')]=function(_0x31656a,_0x20ffda){if(_0x31656a[_0x5b5f('0x4a')]['id']){delete _0x31656a[_0x5b5f('0x4a')]['id'];}return db['UserProfileSection']['find']({'where':{'id':_0x31656a[_0x5b5f('0x46')]['id']}})['then'](handleEntityNotFound(_0x20ffda,null))[_0x5b5f('0x25')](saveUpdates(_0x31656a[_0x5b5f('0x4a')],null))[_0x5b5f('0x25')](respondWithResult(_0x20ffda,null))[_0x5b5f('0x44')](handleError(_0x20ffda,null));};exports[_0x5b5f('0x24')]=function(_0x29efd5,_0x4a9edc){return db[_0x5b5f('0x2b')][_0x5b5f('0x48')]({'where':{'id':_0x29efd5[_0x5b5f('0x46')]['id']}})['then'](handleEntityNotFound(_0x4a9edc,null))['then'](removeEntity(_0x4a9edc,null))['catch'](handleError(_0x4a9edc,null));};exports[_0x5b5f('0x4b')]=function(_0x5b29a6,_0x124055){return db[_0x5b5f('0x2b')][_0x5b5f('0x4b')]()['then'](respondWithResult(_0x124055,null))[_0x5b5f('0x44')](handleError(_0x124055,null));};