Built motion from commit 43538d75.|2.5.35
[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 _0x66ff=['body','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','path','sox','fs-extra','lodash','crypto','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','then','destroy','end','sendStatus','error','stack','name','send','index','map','UserProfileSection','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','sort','where','merge','VIRTUAL','filter','options','includeAll','include','findAll','catch','show','params','find','create'];(function(_0x25d386,_0x108d0d){var _0x857f4a=function(_0x3eb98d){while(--_0x3eb98d){_0x25d386['push'](_0x25d386['shift']());}};_0x857f4a(++_0x108d0d);}(_0x66ff,0x1c4));var _0xf66f=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x66ff[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xf66f('0x0'));var rimraf=require(_0xf66f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf66f('0x2'));var rp=require(_0xf66f('0x3'));var moment=require(_0xf66f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xf66f('0x5'));var util=require('util');var path=require(_0xf66f('0x6'));var sox=require(_0xf66f('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf66f('0x8'));var _=require(_0xf66f('0x9'));var squel=require('squel');var crypto=require(_0xf66f('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xf66f('0xb'));var toCsv=require(_0xf66f('0xc'));var querystring=require(_0xf66f('0xd'));var Papa=require('papaparse');var Redis=require(_0xf66f('0xe'));var authService=require(_0xf66f('0xf'));var qs=require(_0xf66f('0x10'));var as=require(_0xf66f('0x11'));var hardwareService=require(_0xf66f('0x12'));var logger=require(_0xf66f('0x13'))(_0xf66f('0x14'));var utils=require(_0xf66f('0x15'));var config=require(_0xf66f('0x16'));var licenseUtil=require(_0xf66f('0x17'));var db=require(_0xf66f('0x18'))['db'];function respondWithStatusCode(_0x3d16aa,_0x4fd957){_0x4fd957=_0x4fd957||0xcc;return function(_0x1d5dcf){if(_0x1d5dcf){return _0x3d16aa['sendStatus'](_0x4fd957);}return _0x3d16aa[_0xf66f('0x19')](_0x4fd957)['end']();};}function respondWithResult(_0x19b119,_0x5ebe7e){_0x5ebe7e=_0x5ebe7e||0xc8;return function(_0x2bf84c){if(_0x2bf84c){return _0x19b119[_0xf66f('0x19')](_0x5ebe7e)[_0xf66f('0x1a')](_0x2bf84c);}};}function respondWithFilteredResult(_0x3b4161,_0xd6b5d9){return function(_0x52b738){if(_0x52b738){var _0x467948=typeof _0xd6b5d9[_0xf66f('0x1b')]===_0xf66f('0x1c')&&typeof _0xd6b5d9[_0xf66f('0x1d')]===_0xf66f('0x1c');var _0x23e5d9=_0x52b738[_0xf66f('0x1e')];var _0x573e9f=_0x467948?0x0:_0xd6b5d9[_0xf66f('0x1b')];var _0x5858cb=_0x467948?_0x52b738[_0xf66f('0x1e')]:_0xd6b5d9[_0xf66f('0x1b')]+_0xd6b5d9[_0xf66f('0x1d')];var _0x370679;if(_0x5858cb>=_0x23e5d9){_0x5858cb=_0x23e5d9;_0x370679=0xc8;}else{_0x370679=0xce;}_0x3b4161['status'](_0x370679);return _0x3b4161[_0xf66f('0x1f')](_0xf66f('0x20'),_0x573e9f+'-'+_0x5858cb+'/'+_0x23e5d9)['json'](_0x52b738);}return null;};}function patchUpdates(_0x43b572){return function(_0x596805){try{jsonpatch[_0xf66f('0x21')](_0x596805,_0x43b572,!![]);}catch(_0x3dca5b){return BPromise[_0xf66f('0x22')](_0x3dca5b);}return _0x596805['save']();};}function saveUpdates(_0x447a92,_0x21da6d){return function(_0x1d1c1d){if(_0x1d1c1d){return _0x1d1c1d[_0xf66f('0x23')](_0x447a92)[_0xf66f('0x24')](function(_0x49074f){return _0x49074f;});}return null;};}function removeEntity(_0x45fad9,_0x45b829){return function(_0x1b85a8){if(_0x1b85a8){return _0x1b85a8[_0xf66f('0x25')]()[_0xf66f('0x24')](function(){_0x45fad9[_0xf66f('0x19')](0xcc)[_0xf66f('0x26')]();});}};}function handleEntityNotFound(_0x15d6f9,_0x13ef43){return function(_0xb5e91e){if(!_0xb5e91e){_0x15d6f9[_0xf66f('0x27')](0x194);}return _0xb5e91e;};}function handleError(_0x13481f,_0x1b809f){_0x1b809f=_0x1b809f||0x1f4;return function(_0x41c046){logger[_0xf66f('0x28')](_0x41c046[_0xf66f('0x29')]);if(_0x41c046[_0xf66f('0x2a')]){delete _0x41c046[_0xf66f('0x2a')];}_0x13481f[_0xf66f('0x19')](_0x1b809f)[_0xf66f('0x2b')](_0x41c046);};}exports[_0xf66f('0x2c')]=function(_0x396d66,_0x3b9f42){var _0x1d7b89={},_0x61ac06={},_0x100da2={'count':0x0,'rows':[]};var _0x37623e=_[_0xf66f('0x2d')](db[_0xf66f('0x2e')][_0xf66f('0x2f')],function(_0x447a67){return{'name':_0x447a67[_0xf66f('0x30')],'type':_0x447a67[_0xf66f('0x31')][_0xf66f('0x32')]};});_0x61ac06[_0xf66f('0x33')]=_[_0xf66f('0x2d')](_0x37623e,_0xf66f('0x2a'));_0x61ac06[_0xf66f('0x34')]=_[_0xf66f('0x35')](_0x396d66[_0xf66f('0x34')]);_0x61ac06[_0xf66f('0x36')]=_[_0xf66f('0x37')](_0x61ac06[_0xf66f('0x33')],_0x61ac06['query']);_0x1d7b89['attributes']=_[_0xf66f('0x37')](_0x61ac06[_0xf66f('0x33')],qs[_0xf66f('0x38')](_0x396d66['query'][_0xf66f('0x38')]));_0x1d7b89[_0xf66f('0x39')]=_0x1d7b89[_0xf66f('0x39')][_0xf66f('0x3a')]?_0x1d7b89[_0xf66f('0x39')]:_0x61ac06['model'];if(!_0x396d66[_0xf66f('0x34')]['hasOwnProperty']('nolimit')){_0x1d7b89[_0xf66f('0x1d')]=qs[_0xf66f('0x1d')](_0x396d66[_0xf66f('0x34')]['limit']);_0x1d7b89[_0xf66f('0x1b')]=qs[_0xf66f('0x1b')](_0x396d66[_0xf66f('0x34')][_0xf66f('0x1b')]);}_0x1d7b89['order']=qs[_0xf66f('0x3b')](_0x396d66[_0xf66f('0x34')][_0xf66f('0x3b')]);_0x1d7b89['where']=qs[_0xf66f('0x36')](_['pick'](_0x396d66[_0xf66f('0x34')],_0x61ac06[_0xf66f('0x36')]),_0x37623e);if(_0x396d66[_0xf66f('0x34')]['filter']){_0x1d7b89[_0xf66f('0x3c')]=_[_0xf66f('0x3d')](_0x1d7b89[_0xf66f('0x3c')],{'$or':_['map'](_0x37623e,function(_0x231ff9){if(_0x231ff9[_0xf66f('0x31')]!==_0xf66f('0x3e')){var _0x2cd622={};_0x2cd622[_0x231ff9[_0xf66f('0x2a')]]={'$like':'%'+_0x396d66[_0xf66f('0x34')][_0xf66f('0x3f')]+'%'};return _0x2cd622;}})});}_0x1d7b89=_[_0xf66f('0x3d')]({},_0x1d7b89,_0x396d66[_0xf66f('0x40')]);var _0x392917={'where':_0x1d7b89[_0xf66f('0x3c')]};return db[_0xf66f('0x2e')]['count'](_0x392917)[_0xf66f('0x24')](function(_0x3c0ccc){_0x100da2[_0xf66f('0x1e')]=_0x3c0ccc;if(_0x396d66[_0xf66f('0x34')][_0xf66f('0x41')]){_0x1d7b89[_0xf66f('0x42')]=[{'all':!![]}];}return db[_0xf66f('0x2e')][_0xf66f('0x43')](_0x1d7b89);})[_0xf66f('0x24')](function(_0xf6926){_0x100da2['rows']=_0xf6926;return _0x100da2;})['then'](respondWithFilteredResult(_0x3b9f42,_0x1d7b89))[_0xf66f('0x44')](handleError(_0x3b9f42,null));};exports[_0xf66f('0x45')]=function(_0x192b01,_0x18e095){var _0x4803b6={'raw':![],'where':{'id':_0x192b01[_0xf66f('0x46')]['id']}},_0xb2ace5={};_0xb2ace5[_0xf66f('0x33')]=_[_0xf66f('0x35')](db['UserProfileSection']['rawAttributes']);_0xb2ace5[_0xf66f('0x34')]=_['keys'](_0x192b01[_0xf66f('0x34')]);_0xb2ace5[_0xf66f('0x36')]=_[_0xf66f('0x37')](_0xb2ace5[_0xf66f('0x33')],_0xb2ace5[_0xf66f('0x34')]);_0x4803b6[_0xf66f('0x39')]=_[_0xf66f('0x37')](_0xb2ace5['model'],qs[_0xf66f('0x38')](_0x192b01[_0xf66f('0x34')][_0xf66f('0x38')]));_0x4803b6[_0xf66f('0x39')]=_0x4803b6[_0xf66f('0x39')][_0xf66f('0x3a')]?_0x4803b6['attributes']:_0xb2ace5[_0xf66f('0x33')];if(_0x192b01[_0xf66f('0x34')][_0xf66f('0x41')]){_0x4803b6[_0xf66f('0x42')]=[{'all':!![]}];}_0x4803b6=_[_0xf66f('0x3d')]({},_0x4803b6,_0x192b01[_0xf66f('0x40')]);return db['UserProfileSection'][_0xf66f('0x47')](_0x4803b6)[_0xf66f('0x24')](handleEntityNotFound(_0x18e095,null))[_0xf66f('0x24')](respondWithResult(_0x18e095,null))[_0xf66f('0x44')](handleError(_0x18e095,null));};exports[_0xf66f('0x48')]=function(_0x33ce6f,_0x5d2926){return db[_0xf66f('0x2e')][_0xf66f('0x48')](_0x33ce6f[_0xf66f('0x49')],{})[_0xf66f('0x24')](respondWithResult(_0x5d2926,0xc9))[_0xf66f('0x44')](handleError(_0x5d2926,null));};exports[_0xf66f('0x23')]=function(_0x5aec58,_0x32a7d5){if(_0x5aec58[_0xf66f('0x49')]['id']){delete _0x5aec58[_0xf66f('0x49')]['id'];}return db[_0xf66f('0x2e')][_0xf66f('0x47')]({'where':{'id':_0x5aec58[_0xf66f('0x46')]['id']}})[_0xf66f('0x24')](handleEntityNotFound(_0x32a7d5,null))[_0xf66f('0x24')](saveUpdates(_0x5aec58['body'],null))[_0xf66f('0x24')](respondWithResult(_0x32a7d5,null))['catch'](handleError(_0x32a7d5,null));};exports['destroy']=function(_0x43140c,_0x519f17){return db[_0xf66f('0x2e')][_0xf66f('0x47')]({'where':{'id':_0x43140c[_0xf66f('0x46')]['id']}})[_0xf66f('0x24')](handleEntityNotFound(_0x519f17,null))[_0xf66f('0x24')](removeEntity(_0x519f17,null))[_0xf66f('0x44')](handleError(_0x519f17,null));};exports[_0xf66f('0x4a')]=function(_0x49c5e5,_0x400f9d){return db[_0xf66f('0x2e')][_0xf66f('0x4a')]()['then'](respondWithResult(_0x400f9d,null))['catch'](handleError(_0x400f9d,null));};