Built motion from commit 616d3211.|2.6.4
[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 _0x62d7=['model','query','keys','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','map','type','UserProfileSection','includeAll','include','findAll','rows','catch','show','params','rawAttributes','length','create','body','update','find','destroy','describe','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','count','Content-Range','apply','reject','save','then','error','stack','name','send','index','fieldName','key'];(function(_0x1c2843,_0x199d3c){var _0x547e9a=function(_0x5639fe){while(--_0x5639fe){_0x1c2843['push'](_0x1c2843['shift']());}};_0x547e9a(++_0x199d3c);}(_0x62d7,0x1a7));var _0x762d=function(_0x5f4da4,_0xcd17ea){_0x5f4da4=_0x5f4da4-0x0;var _0x934fe6=_0x62d7[_0x5f4da4];return _0x934fe6;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x762d('0x0'));var zipdir=require(_0x762d('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x762d('0x2'));var moment=require(_0x762d('0x3'));var BPromise=require(_0x762d('0x4'));var Mustache=require('mustache');var util=require(_0x762d('0x5'));var path=require(_0x762d('0x6'));var sox=require(_0x762d('0x7'));var csv=require(_0x762d('0x8'));var ejs=require(_0x762d('0x9'));var fs=require('fs');var fs_extra=require(_0x762d('0xa'));var _=require(_0x762d('0xb'));var squel=require(_0x762d('0xc'));var crypto=require(_0x762d('0xd'));var jsforce=require(_0x762d('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x762d('0x8'));var querystring=require(_0x762d('0xf'));var Papa=require('papaparse');var Redis=require(_0x762d('0x10'));var authService=require(_0x762d('0x11'));var qs=require(_0x762d('0x12'));var as=require(_0x762d('0x13'));var hardwareService=require(_0x762d('0x14'));var logger=require(_0x762d('0x15'))(_0x762d('0x16'));var utils=require('../../config/utils');var config=require(_0x762d('0x17'));var licenseUtil=require(_0x762d('0x18'));var db=require(_0x762d('0x19'))['db'];function respondWithStatusCode(_0x3063a4,_0x4d448){_0x4d448=_0x4d448||0xcc;return function(_0x1a2ddc){if(_0x1a2ddc){return _0x3063a4[_0x762d('0x1a')](_0x4d448);}return _0x3063a4[_0x762d('0x1b')](_0x4d448)[_0x762d('0x1c')]();};}function respondWithResult(_0x636718,_0x7684c9){_0x7684c9=_0x7684c9||0xc8;return function(_0x1cd231){if(_0x1cd231){return _0x636718[_0x762d('0x1b')](_0x7684c9)[_0x762d('0x1d')](_0x1cd231);}};}function respondWithFilteredResult(_0x28ae0e,_0x585873){return function(_0x1ae555){if(_0x1ae555){var _0x73445c=typeof _0x585873[_0x762d('0x1e')]==='undefined'&&typeof _0x585873[_0x762d('0x1f')]==='undefined';var _0x1469c6=_0x1ae555[_0x762d('0x20')];var _0x53fe64=_0x73445c?0x0:_0x585873[_0x762d('0x1e')];var _0x18e9e5=_0x73445c?_0x1ae555[_0x762d('0x20')]:_0x585873[_0x762d('0x1e')]+_0x585873[_0x762d('0x1f')];var _0x70b220;if(_0x18e9e5>=_0x1469c6){_0x18e9e5=_0x1469c6;_0x70b220=0xc8;}else{_0x70b220=0xce;}_0x28ae0e[_0x762d('0x1b')](_0x70b220);return _0x28ae0e['set'](_0x762d('0x21'),_0x53fe64+'-'+_0x18e9e5+'/'+_0x1469c6)[_0x762d('0x1d')](_0x1ae555);}return null;};}function patchUpdates(_0x5991c3){return function(_0x40a26c){try{jsonpatch[_0x762d('0x22')](_0x40a26c,_0x5991c3,!![]);}catch(_0x32a897){return BPromise[_0x762d('0x23')](_0x32a897);}return _0x40a26c[_0x762d('0x24')]();};}function saveUpdates(_0x1d194a,_0x2e95d7){return function(_0x355127){if(_0x355127){return _0x355127['update'](_0x1d194a)[_0x762d('0x25')](function(_0x4c5191){return _0x4c5191;});}return null;};}function removeEntity(_0x1c0f15,_0xf87d7f){return function(_0x14beb5){if(_0x14beb5){return _0x14beb5['destroy']()[_0x762d('0x25')](function(){_0x1c0f15[_0x762d('0x1b')](0xcc)[_0x762d('0x1c')]();});}};}function handleEntityNotFound(_0x50fdcc,_0x4aaadd){return function(_0x316d76){if(!_0x316d76){_0x50fdcc['sendStatus'](0x194);}return _0x316d76;};}function handleError(_0x798ea7,_0x27d2cb){_0x27d2cb=_0x27d2cb||0x1f4;return function(_0x3cb255){logger[_0x762d('0x26')](_0x3cb255[_0x762d('0x27')]);if(_0x3cb255['name']){delete _0x3cb255[_0x762d('0x28')];}_0x798ea7[_0x762d('0x1b')](_0x27d2cb)[_0x762d('0x29')](_0x3cb255);};}exports[_0x762d('0x2a')]=function(_0x46a3e3,_0x2fd4f6){var _0x511584={},_0x491b44={},_0x37a721={'count':0x0,'rows':[]};var _0x137426=_['map'](db['UserProfileSection']['rawAttributes'],function(_0x16ca34){return{'name':_0x16ca34[_0x762d('0x2b')],'type':_0x16ca34['type'][_0x762d('0x2c')]};});_0x491b44[_0x762d('0x2d')]=_['map'](_0x137426,_0x762d('0x28'));_0x491b44[_0x762d('0x2e')]=_[_0x762d('0x2f')](_0x46a3e3[_0x762d('0x2e')]);_0x491b44['filters']=_[_0x762d('0x30')](_0x491b44[_0x762d('0x2d')],_0x491b44[_0x762d('0x2e')]);_0x511584['attributes']=_[_0x762d('0x30')](_0x491b44[_0x762d('0x2d')],qs[_0x762d('0x31')](_0x46a3e3['query'][_0x762d('0x31')]));_0x511584[_0x762d('0x32')]=_0x511584[_0x762d('0x32')]['length']?_0x511584[_0x762d('0x32')]:_0x491b44[_0x762d('0x2d')];if(!_0x46a3e3[_0x762d('0x2e')][_0x762d('0x33')](_0x762d('0x34'))){_0x511584[_0x762d('0x1f')]=qs[_0x762d('0x1f')](_0x46a3e3['query']['limit']);_0x511584['offset']=qs[_0x762d('0x1e')](_0x46a3e3[_0x762d('0x2e')][_0x762d('0x1e')]);}_0x511584[_0x762d('0x35')]=qs['sort'](_0x46a3e3[_0x762d('0x2e')][_0x762d('0x36')]);_0x511584[_0x762d('0x37')]=qs[_0x762d('0x38')](_[_0x762d('0x39')](_0x46a3e3[_0x762d('0x2e')],_0x491b44[_0x762d('0x38')]),_0x137426);if(_0x46a3e3['query'][_0x762d('0x3a')]){_0x511584['where']=_[_0x762d('0x3b')](_0x511584['where'],{'$or':_[_0x762d('0x3c')](_0x137426,function(_0x263063){if(_0x263063[_0x762d('0x3d')]!=='VIRTUAL'){var _0x454a42={};_0x454a42[_0x263063[_0x762d('0x28')]]={'$like':'%'+_0x46a3e3[_0x762d('0x2e')][_0x762d('0x3a')]+'%'};return _0x454a42;}})});}_0x511584=_[_0x762d('0x3b')]({},_0x511584,_0x46a3e3['options']);var _0x4f8547={'where':_0x511584['where']};return db[_0x762d('0x3e')][_0x762d('0x20')](_0x4f8547)[_0x762d('0x25')](function(_0x485fb5){_0x37a721[_0x762d('0x20')]=_0x485fb5;if(_0x46a3e3[_0x762d('0x2e')][_0x762d('0x3f')]){_0x511584[_0x762d('0x40')]=[{'all':!![]}];}return db['UserProfileSection'][_0x762d('0x41')](_0x511584);})['then'](function(_0x3c2bba){_0x37a721[_0x762d('0x42')]=_0x3c2bba;return _0x37a721;})[_0x762d('0x25')](respondWithFilteredResult(_0x2fd4f6,_0x511584))[_0x762d('0x43')](handleError(_0x2fd4f6,null));};exports[_0x762d('0x44')]=function(_0x350c00,_0x4b07a1){var _0x455730={'raw':![],'where':{'id':_0x350c00[_0x762d('0x45')]['id']}},_0x38c990={};_0x38c990[_0x762d('0x2d')]=_[_0x762d('0x2f')](db[_0x762d('0x3e')][_0x762d('0x46')]);_0x38c990['query']=_['keys'](_0x350c00[_0x762d('0x2e')]);_0x38c990[_0x762d('0x38')]=_[_0x762d('0x30')](_0x38c990[_0x762d('0x2d')],_0x38c990[_0x762d('0x2e')]);_0x455730['attributes']=_[_0x762d('0x30')](_0x38c990[_0x762d('0x2d')],qs[_0x762d('0x31')](_0x350c00['query']['fields']));_0x455730[_0x762d('0x32')]=_0x455730[_0x762d('0x32')][_0x762d('0x47')]?_0x455730[_0x762d('0x32')]:_0x38c990[_0x762d('0x2d')];if(_0x350c00[_0x762d('0x2e')][_0x762d('0x3f')]){_0x455730['include']=[{'all':!![]}];}_0x455730=_[_0x762d('0x3b')]({},_0x455730,_0x350c00['options']);return db['UserProfileSection']['find'](_0x455730)[_0x762d('0x25')](handleEntityNotFound(_0x4b07a1,null))[_0x762d('0x25')](respondWithResult(_0x4b07a1,null))['catch'](handleError(_0x4b07a1,null));};exports[_0x762d('0x48')]=function(_0x462d88,_0x566073){return db['UserProfileSection'][_0x762d('0x48')](_0x462d88[_0x762d('0x49')],{})[_0x762d('0x25')](respondWithResult(_0x566073,0xc9))['catch'](handleError(_0x566073,null));};exports[_0x762d('0x4a')]=function(_0x359648,_0x51b00a){if(_0x359648[_0x762d('0x49')]['id']){delete _0x359648[_0x762d('0x49')]['id'];}return db[_0x762d('0x3e')][_0x762d('0x4b')]({'where':{'id':_0x359648[_0x762d('0x45')]['id']}})[_0x762d('0x25')](handleEntityNotFound(_0x51b00a,null))[_0x762d('0x25')](saveUpdates(_0x359648[_0x762d('0x49')],null))[_0x762d('0x25')](respondWithResult(_0x51b00a,null))['catch'](handleError(_0x51b00a,null));};exports[_0x762d('0x4c')]=function(_0x169be9,_0x19fee7){return db['UserProfileSection'][_0x762d('0x4b')]({'where':{'id':_0x169be9['params']['id']}})[_0x762d('0x25')](handleEntityNotFound(_0x19fee7,null))[_0x762d('0x25')](removeEntity(_0x19fee7,null))[_0x762d('0x43')](handleError(_0x19fee7,null));};exports[_0x762d('0x4d')]=function(_0x2aabeb,_0x376482){return db[_0x762d('0x3e')]['describe']()['then'](respondWithResult(_0x376482,null))['catch'](handleError(_0x376482,null));};