Built motion from commit a679711e.|2.6.15
[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 _0x1f22=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','destroy','then','sendStatus','stack','name','send','index','UserProfileSection','rawAttributes','key','query','filters','model','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','pick','merge','map','VIRTUAL','filter','includeAll','include','findAll','catch','show','params','keys','options','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs'];(function(_0x16cff1,_0x210729){var _0x141cb3=function(_0x26dfcb){while(--_0x26dfcb){_0x16cff1['push'](_0x16cff1['shift']());}};_0x141cb3(++_0x210729);}(_0x1f22,0x16a));var _0x21f2=function(_0x3c7fca,_0x122dc1){_0x3c7fca=_0x3c7fca-0x0;var _0xf030eb=_0x1f22[_0x3c7fca];return _0xf030eb;};'use strict';var emlformat=require(_0x21f2('0x0'));var rimraf=require(_0x21f2('0x1'));var zipdir=require(_0x21f2('0x2'));var jsonpatch=require(_0x21f2('0x3'));var rp=require('request-promise');var moment=require(_0x21f2('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x21f2('0x5'));var util=require(_0x21f2('0x6'));var path=require(_0x21f2('0x7'));var sox=require('sox');var csv=require(_0x21f2('0x8'));var ejs=require(_0x21f2('0x9'));var fs=require('fs');var fs_extra=require(_0x21f2('0xa'));var _=require(_0x21f2('0xb'));var squel=require('squel');var crypto=require(_0x21f2('0xc'));var jsforce=require(_0x21f2('0xd'));var deskjs=require(_0x21f2('0xe'));var toCsv=require(_0x21f2('0x8'));var querystring=require(_0x21f2('0xf'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x21f2('0x10'));var qs=require(_0x21f2('0x11'));var as=require(_0x21f2('0x12'));var hardwareService=require(_0x21f2('0x13'));var logger=require(_0x21f2('0x14'))(_0x21f2('0x15'));var utils=require(_0x21f2('0x16'));var config=require(_0x21f2('0x17'));var licenseUtil=require(_0x21f2('0x18'));var db=require(_0x21f2('0x19'))['db'];function respondWithStatusCode(_0x1f9174,_0xaa82f5){_0xaa82f5=_0xaa82f5||0xcc;return function(_0x56d922){if(_0x56d922){return _0x1f9174['sendStatus'](_0xaa82f5);}return _0x1f9174[_0x21f2('0x1a')](_0xaa82f5)[_0x21f2('0x1b')]();};}function respondWithResult(_0x85d131,_0x54d54c){_0x54d54c=_0x54d54c||0xc8;return function(_0x428e99){if(_0x428e99){return _0x85d131[_0x21f2('0x1a')](_0x54d54c)[_0x21f2('0x1c')](_0x428e99);}};}function respondWithFilteredResult(_0x546d5b,_0x459838){return function(_0x7b7479){if(_0x7b7479){var _0x1dae40=typeof _0x459838[_0x21f2('0x1d')]===_0x21f2('0x1e')&&typeof _0x459838[_0x21f2('0x1f')]===_0x21f2('0x1e');var _0x3ae4c7=_0x7b7479[_0x21f2('0x20')];var _0x50bff7=_0x1dae40?0x0:_0x459838[_0x21f2('0x1d')];var _0x57303a=_0x1dae40?_0x7b7479['count']:_0x459838[_0x21f2('0x1d')]+_0x459838[_0x21f2('0x1f')];var _0x57b362;if(_0x57303a>=_0x3ae4c7){_0x57303a=_0x3ae4c7;_0x57b362=0xc8;}else{_0x57b362=0xce;}_0x546d5b[_0x21f2('0x1a')](_0x57b362);return _0x546d5b[_0x21f2('0x21')](_0x21f2('0x22'),_0x50bff7+'-'+_0x57303a+'/'+_0x3ae4c7)[_0x21f2('0x1c')](_0x7b7479);}return null;};}function patchUpdates(_0x554633){return function(_0x48a8cc){try{jsonpatch[_0x21f2('0x23')](_0x48a8cc,_0x554633,!![]);}catch(_0x193248){return BPromise['reject'](_0x193248);}return _0x48a8cc[_0x21f2('0x24')]();};}function saveUpdates(_0x129605,_0x5e6334){return function(_0x5c1221){if(_0x5c1221){return _0x5c1221[_0x21f2('0x25')](_0x129605)['then'](function(_0x3fe639){return _0x3fe639;});}return null;};}function removeEntity(_0x4e4221,_0x3e3636){return function(_0x2c9c7c){if(_0x2c9c7c){return _0x2c9c7c[_0x21f2('0x26')]()[_0x21f2('0x27')](function(){_0x4e4221[_0x21f2('0x1a')](0xcc)[_0x21f2('0x1b')]();});}};}function handleEntityNotFound(_0x24eecf,_0x28af95){return function(_0xca3e87){if(!_0xca3e87){_0x24eecf[_0x21f2('0x28')](0x194);}return _0xca3e87;};}function handleError(_0x8d4420,_0x48f3bc){_0x48f3bc=_0x48f3bc||0x1f4;return function(_0x2b319c){logger['error'](_0x2b319c[_0x21f2('0x29')]);if(_0x2b319c[_0x21f2('0x2a')]){delete _0x2b319c[_0x21f2('0x2a')];}_0x8d4420['status'](_0x48f3bc)[_0x21f2('0x2b')](_0x2b319c);};}exports[_0x21f2('0x2c')]=function(_0x259823,_0x53214b){var _0x5f0466={},_0x294b31={},_0x45d1c9={'count':0x0,'rows':[]};var _0x571166=_['map'](db[_0x21f2('0x2d')][_0x21f2('0x2e')],function(_0x1ff146){return{'name':_0x1ff146['fieldName'],'type':_0x1ff146['type'][_0x21f2('0x2f')]};});_0x294b31['model']=_['map'](_0x571166,_0x21f2('0x2a'));_0x294b31[_0x21f2('0x30')]=_['keys'](_0x259823[_0x21f2('0x30')]);_0x294b31[_0x21f2('0x31')]=_['intersection'](_0x294b31[_0x21f2('0x32')],_0x294b31['query']);_0x5f0466[_0x21f2('0x33')]=_[_0x21f2('0x34')](_0x294b31[_0x21f2('0x32')],qs[_0x21f2('0x35')](_0x259823[_0x21f2('0x30')]['fields']));_0x5f0466['attributes']=_0x5f0466[_0x21f2('0x33')][_0x21f2('0x36')]?_0x5f0466[_0x21f2('0x33')]:_0x294b31[_0x21f2('0x32')];if(!_0x259823[_0x21f2('0x30')][_0x21f2('0x37')]('nolimit')){_0x5f0466[_0x21f2('0x1f')]=qs['limit'](_0x259823['query']['limit']);_0x5f0466[_0x21f2('0x1d')]=qs[_0x21f2('0x1d')](_0x259823[_0x21f2('0x30')][_0x21f2('0x1d')]);}_0x5f0466[_0x21f2('0x38')]=qs[_0x21f2('0x39')](_0x259823[_0x21f2('0x30')][_0x21f2('0x39')]);_0x5f0466[_0x21f2('0x3a')]=qs[_0x21f2('0x31')](_[_0x21f2('0x3b')](_0x259823[_0x21f2('0x30')],_0x294b31['filters']),_0x571166);if(_0x259823[_0x21f2('0x30')]['filter']){_0x5f0466[_0x21f2('0x3a')]=_[_0x21f2('0x3c')](_0x5f0466[_0x21f2('0x3a')],{'$or':_[_0x21f2('0x3d')](_0x571166,function(_0x6862a1){if(_0x6862a1['type']!==_0x21f2('0x3e')){var _0x385de2={};_0x385de2[_0x6862a1[_0x21f2('0x2a')]]={'$like':'%'+_0x259823['query'][_0x21f2('0x3f')]+'%'};return _0x385de2;}})});}_0x5f0466=_[_0x21f2('0x3c')]({},_0x5f0466,_0x259823['options']);var _0x5df46a={'where':_0x5f0466[_0x21f2('0x3a')]};return db['UserProfileSection'][_0x21f2('0x20')](_0x5df46a)[_0x21f2('0x27')](function(_0x4d8f04){_0x45d1c9[_0x21f2('0x20')]=_0x4d8f04;if(_0x259823[_0x21f2('0x30')][_0x21f2('0x40')]){_0x5f0466[_0x21f2('0x41')]=[{'all':!![]}];}return db[_0x21f2('0x2d')][_0x21f2('0x42')](_0x5f0466);})[_0x21f2('0x27')](function(_0x2c9ba7){_0x45d1c9['rows']=_0x2c9ba7;return _0x45d1c9;})['then'](respondWithFilteredResult(_0x53214b,_0x5f0466))[_0x21f2('0x43')](handleError(_0x53214b,null));};exports[_0x21f2('0x44')]=function(_0x623a8d,_0x5a2f12){var _0x370aec={'raw':![],'where':{'id':_0x623a8d[_0x21f2('0x45')]['id']}},_0x52b9e5={};_0x52b9e5['model']=_[_0x21f2('0x46')](db[_0x21f2('0x2d')][_0x21f2('0x2e')]);_0x52b9e5[_0x21f2('0x30')]=_[_0x21f2('0x46')](_0x623a8d[_0x21f2('0x30')]);_0x52b9e5['filters']=_['intersection'](_0x52b9e5[_0x21f2('0x32')],_0x52b9e5['query']);_0x370aec[_0x21f2('0x33')]=_[_0x21f2('0x34')](_0x52b9e5[_0x21f2('0x32')],qs[_0x21f2('0x35')](_0x623a8d['query'][_0x21f2('0x35')]));_0x370aec['attributes']=_0x370aec['attributes'][_0x21f2('0x36')]?_0x370aec[_0x21f2('0x33')]:_0x52b9e5['model'];if(_0x623a8d['query'][_0x21f2('0x40')]){_0x370aec[_0x21f2('0x41')]=[{'all':!![]}];}_0x370aec=_[_0x21f2('0x3c')]({},_0x370aec,_0x623a8d[_0x21f2('0x47')]);return db[_0x21f2('0x2d')][_0x21f2('0x48')](_0x370aec)[_0x21f2('0x27')](handleEntityNotFound(_0x5a2f12,null))[_0x21f2('0x27')](respondWithResult(_0x5a2f12,null))[_0x21f2('0x43')](handleError(_0x5a2f12,null));};exports[_0x21f2('0x49')]=function(_0x3e3a25,_0x2a909d){return db[_0x21f2('0x2d')][_0x21f2('0x49')](_0x3e3a25['body'],{})['then'](respondWithResult(_0x2a909d,0xc9))[_0x21f2('0x43')](handleError(_0x2a909d,null));};exports[_0x21f2('0x25')]=function(_0x12187b,_0x4df719){if(_0x12187b['body']['id']){delete _0x12187b[_0x21f2('0x4a')]['id'];}return db[_0x21f2('0x2d')][_0x21f2('0x48')]({'where':{'id':_0x12187b[_0x21f2('0x45')]['id']}})[_0x21f2('0x27')](handleEntityNotFound(_0x4df719,null))[_0x21f2('0x27')](saveUpdates(_0x12187b[_0x21f2('0x4a')],null))['then'](respondWithResult(_0x4df719,null))['catch'](handleError(_0x4df719,null));};exports['destroy']=function(_0x47d501,_0x184dbd){return db[_0x21f2('0x2d')][_0x21f2('0x48')]({'where':{'id':_0x47d501[_0x21f2('0x45')]['id']}})['then'](handleEntityNotFound(_0x184dbd,null))['then'](removeEntity(_0x184dbd,null))['catch'](handleError(_0x184dbd,null));};exports[_0x21f2('0x4b')]=function(_0x3d51b,_0x4efe0c){return db[_0x21f2('0x2d')][_0x21f2('0x4b')]()[_0x21f2('0x27')](respondWithResult(_0x4efe0c,null))[_0x21f2('0x43')](handleError(_0x4efe0c,null));};