Built motion from commit (unavailable).|2.4.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 _0x5f2f=['json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','error','stack','name','send','index','UserProfileSection','rawAttributes','query','keys','model','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','type','key','options','includeAll','include','findAll','catch','params','length','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/utils','../../config/environment','sendStatus','status','end'];(function(_0x46c975,_0x1d53b3){var _0x280ef8=function(_0x4d5ff2){while(--_0x4d5ff2){_0x46c975['push'](_0x46c975['shift']());}};_0x280ef8(++_0x1d53b3);}(_0x5f2f,0x73));var _0xf5f2=function(_0x9b3efc,_0x577a0d){_0x9b3efc=_0x9b3efc-0x0;var _0x200f05=_0x5f2f[_0x9b3efc];return _0x200f05;};'use strict';var pdf=require(_0xf5f2('0x0'));var emlformat=require(_0xf5f2('0x1'));var rimraf=require(_0xf5f2('0x2'));var zipdir=require(_0xf5f2('0x3'));var jsonpatch=require(_0xf5f2('0x4'));var rp=require(_0xf5f2('0x5'));var moment=require(_0xf5f2('0x6'));var BPromise=require(_0xf5f2('0x7'));var Mustache=require('mustache');var util=require('util');var path=require(_0xf5f2('0x8'));var sox=require(_0xf5f2('0x9'));var csv=require(_0xf5f2('0xa'));var ejs=require(_0xf5f2('0xb'));var fs=require('fs');var _=require(_0xf5f2('0xc'));var squel=require(_0xf5f2('0xd'));var crypto=require('crypto');var jsforce=require(_0xf5f2('0xe'));var deskjs=require(_0xf5f2('0xf'));var toCsv=require(_0xf5f2('0xa'));var querystring=require('querystring');var Papa=require(_0xf5f2('0x10'));var Redis=require(_0xf5f2('0x11'));var authService=require(_0xf5f2('0x12'));var qs=require('../../components/parsers/qs');var hardwareService=require(_0xf5f2('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xf5f2('0x14'));var config=require(_0xf5f2('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x336f6b,_0x14b51f){_0x14b51f=_0x14b51f||0xcc;return function(_0x331482){if(_0x331482){return _0x336f6b[_0xf5f2('0x16')](_0x14b51f);}return _0x336f6b[_0xf5f2('0x17')](_0x14b51f)[_0xf5f2('0x18')]();};}function respondWithResult(_0x5c01b8,_0x5850f4){_0x5850f4=_0x5850f4||0xc8;return function(_0xea612c){if(_0xea612c){return _0x5c01b8[_0xf5f2('0x17')](_0x5850f4)[_0xf5f2('0x19')](_0xea612c);}};}function respondWithFilteredResult(_0x422b55,_0x4d97fc){return function(_0xafe430){if(_0xafe430){var _0x286197=_0xafe430[_0xf5f2('0x1a')],_0x17d656=_0x4d97fc[_0xf5f2('0x1b')],_0x1b6dd2=_0x4d97fc[_0xf5f2('0x1b')]+_0x4d97fc[_0xf5f2('0x1c')],_0x23e23a;if(_0x1b6dd2>=_0x286197){_0x1b6dd2=_0x286197;_0x23e23a=0xc8;}else{_0x23e23a=0xce;}_0x422b55[_0xf5f2('0x17')](_0x23e23a);return _0x422b55[_0xf5f2('0x1d')](_0xf5f2('0x1e'),_0x17d656+'-'+_0x1b6dd2+'/'+_0x286197)[_0xf5f2('0x19')](_0xafe430);}return null;};}function patchUpdates(_0x3ee69){return function(_0x3cf5ea){try{jsonpatch[_0xf5f2('0x1f')](_0x3cf5ea,_0x3ee69,!![]);}catch(_0x1bf655){return BPromise['reject'](_0x1bf655);}return _0x3cf5ea[_0xf5f2('0x20')]();};}function saveUpdates(_0x47101e,_0x49dac2){return function(_0x47acfc){if(_0x47acfc){return _0x47acfc[_0xf5f2('0x21')](_0x47101e)[_0xf5f2('0x22')](function(_0x4ae323){return _0x4ae323;});}return null;};}function removeEntity(_0x45b74f,_0x170042){return function(_0x39e44a){if(_0x39e44a){return _0x39e44a[_0xf5f2('0x23')]()[_0xf5f2('0x22')](function(){_0x45b74f['status'](0xcc)[_0xf5f2('0x18')]();});}};}function handleEntityNotFound(_0x4669a6,_0x4e8bda){return function(_0x2833fe){if(!_0x2833fe){_0x4669a6[_0xf5f2('0x16')](0x194);}return _0x2833fe;};}function handleError(_0x5bdf4a,_0x529f07){_0x529f07=_0x529f07||0x1f4;return function(_0x5f1124){logger[_0xf5f2('0x24')](_0x5f1124[_0xf5f2('0x25')]);if(_0x5f1124[_0xf5f2('0x26')]){delete _0x5f1124[_0xf5f2('0x26')];}_0x5bdf4a[_0xf5f2('0x17')](_0x529f07)[_0xf5f2('0x27')](_0x5f1124);};}exports[_0xf5f2('0x28')]=function(_0x294414,_0x4ab014){var _0xaa2602={},_0x102449={},_0x375ca8={'count':0x0,'rows':[]};var _0x31bfcb=db[_0xf5f2('0x29')][_0xf5f2('0x2a')];_0x102449['model']=_['keys'](_0x31bfcb);_0x102449[_0xf5f2('0x2b')]=_[_0xf5f2('0x2c')](_0x294414[_0xf5f2('0x2b')]);_0x102449['filters']=_['intersection'](_0x102449[_0xf5f2('0x2d')],_0x102449[_0xf5f2('0x2b')]);_0xaa2602[_0xf5f2('0x2e')]=_[_0xf5f2('0x2f')](_0x102449[_0xf5f2('0x2d')],qs['fields'](_0x294414['query'][_0xf5f2('0x30')]));_0xaa2602['attributes']=_0xaa2602[_0xf5f2('0x2e')]['length']?_0xaa2602[_0xf5f2('0x2e')]:_0x102449[_0xf5f2('0x2d')];if(!_0x294414[_0xf5f2('0x2b')][_0xf5f2('0x31')](_0xf5f2('0x32'))){_0xaa2602[_0xf5f2('0x1c')]=qs[_0xf5f2('0x1c')](_0x294414[_0xf5f2('0x2b')]['limit']);_0xaa2602[_0xf5f2('0x1b')]=qs[_0xf5f2('0x1b')](_0x294414[_0xf5f2('0x2b')][_0xf5f2('0x1b')]);}_0xaa2602[_0xf5f2('0x33')]=qs[_0xf5f2('0x34')](_0x294414[_0xf5f2('0x2b')]['sort']);_0xaa2602[_0xf5f2('0x35')]=qs[_0xf5f2('0x36')](_['pick'](_0x294414[_0xf5f2('0x2b')],_0x102449['filters']));if(_0x294414[_0xf5f2('0x2b')][_0xf5f2('0x37')]){_0xaa2602[_0xf5f2('0x35')]=_[_0xf5f2('0x38')](_0xaa2602['where'],{'$or':_['map'](_0x31bfcb,function(_0x41088b){if(_0x41088b[_0xf5f2('0x39')][_0xf5f2('0x3a')]!=='VIRTUAL'){var _0x41447f={};_0x41447f[_0x41088b['field']]={'$like':'%'+_0x294414[_0xf5f2('0x2b')]['filter']+'%'};return _0x41447f;}})});}_0xaa2602=_[_0xf5f2('0x38')]({},_0xaa2602,_0x294414[_0xf5f2('0x3b')]);var _0x5337a6={'where':_0xaa2602[_0xf5f2('0x35')]};return db[_0xf5f2('0x29')][_0xf5f2('0x1a')](_0x5337a6)[_0xf5f2('0x22')](function(_0x542cd6){_0x375ca8['count']=_0x542cd6;if(_0x294414[_0xf5f2('0x2b')][_0xf5f2('0x3c')]){_0xaa2602[_0xf5f2('0x3d')]=[{'all':!![]}];}return db[_0xf5f2('0x29')][_0xf5f2('0x3e')](_0xaa2602);})[_0xf5f2('0x22')](function(_0x2bc20e){_0x375ca8['rows']=_0x2bc20e;return _0x375ca8;})[_0xf5f2('0x22')](respondWithFilteredResult(_0x4ab014,_0xaa2602))[_0xf5f2('0x3f')](handleError(_0x4ab014,null));};exports['show']=function(_0xc6a1ae,_0x3f3895){var _0x71b0e7={'raw':![],'where':{'id':_0xc6a1ae[_0xf5f2('0x40')]['id']}},_0x85b6d0={};_0x85b6d0[_0xf5f2('0x2d')]=_[_0xf5f2('0x2c')](db[_0xf5f2('0x29')]['rawAttributes']);_0x85b6d0[_0xf5f2('0x2b')]=_[_0xf5f2('0x2c')](_0xc6a1ae[_0xf5f2('0x2b')]);_0x85b6d0['filters']=_['intersection'](_0x85b6d0['model'],_0x85b6d0[_0xf5f2('0x2b')]);_0x71b0e7[_0xf5f2('0x2e')]=_['intersection'](_0x85b6d0[_0xf5f2('0x2d')],qs[_0xf5f2('0x30')](_0xc6a1ae[_0xf5f2('0x2b')][_0xf5f2('0x30')]));_0x71b0e7[_0xf5f2('0x2e')]=_0x71b0e7[_0xf5f2('0x2e')][_0xf5f2('0x41')]?_0x71b0e7[_0xf5f2('0x2e')]:_0x85b6d0[_0xf5f2('0x2d')];if(_0xc6a1ae[_0xf5f2('0x2b')][_0xf5f2('0x3c')]){_0x71b0e7[_0xf5f2('0x3d')]=[{'all':!![]}];}_0x71b0e7=_[_0xf5f2('0x38')]({},_0x71b0e7,_0xc6a1ae[_0xf5f2('0x3b')]);return db['UserProfileSection'][_0xf5f2('0x42')](_0x71b0e7)['then'](handleEntityNotFound(_0x3f3895,null))[_0xf5f2('0x22')](respondWithResult(_0x3f3895,null))[_0xf5f2('0x3f')](handleError(_0x3f3895,null));};exports[_0xf5f2('0x43')]=function(_0x36a4b0,_0x31bf0e){return db[_0xf5f2('0x29')]['create'](_0x36a4b0[_0xf5f2('0x44')],{})[_0xf5f2('0x22')](respondWithResult(_0x31bf0e,0xc9))[_0xf5f2('0x3f')](handleError(_0x31bf0e,null));};exports[_0xf5f2('0x21')]=function(_0x12124d,_0x10753a){if(_0x12124d[_0xf5f2('0x44')]['id']){delete _0x12124d[_0xf5f2('0x44')]['id'];}return db['UserProfileSection'][_0xf5f2('0x42')]({'where':{'id':_0x12124d[_0xf5f2('0x40')]['id']}})[_0xf5f2('0x22')](handleEntityNotFound(_0x10753a,null))['then'](saveUpdates(_0x12124d[_0xf5f2('0x44')],null))[_0xf5f2('0x22')](respondWithResult(_0x10753a,null))[_0xf5f2('0x3f')](handleError(_0x10753a,null));};exports['destroy']=function(_0x57a7cb,_0x7bb942){return db[_0xf5f2('0x29')]['find']({'where':{'id':_0x57a7cb[_0xf5f2('0x40')]['id']}})['then'](handleEntityNotFound(_0x7bb942,null))[_0xf5f2('0x22')](removeEntity(_0x7bb942,null))['catch'](handleError(_0x7bb942,null));};exports[_0xf5f2('0x45')]=function(_0x5d9120,_0x2d9017){return db[_0xf5f2('0x29')][_0xf5f2('0x45')]()[_0xf5f2('0x22')](respondWithResult(_0x2d9017,null))['catch'](handleError(_0x2d9017,null));};