f924b0cf9466b91802ae47a7836e89f12b167c4c
[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 _0xf9c3=['type','key','model','keys','query','filters','intersection','fields','attributes','length','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','show','params','rawAttributes','options','find','catch','create','body','html-pdf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','destroy','then','error','name','send','index','map','UserProfileSection','fieldName'];(function(_0x5c351c,_0x2046d8){var _0x26f3b3=function(_0x47ac18){while(--_0x47ac18){_0x5c351c['push'](_0x5c351c['shift']());}};_0x26f3b3(++_0x2046d8);}(_0xf9c3,0xfa));var _0x3f9c=function(_0x179314,_0x32d3a2){_0x179314=_0x179314-0x0;var _0x3556f7=_0xf9c3[_0x179314];return _0x3556f7;};'use strict';var pdf=require(_0x3f9c('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x3f9c('0x1'));var jsonpatch=require(_0x3f9c('0x2'));var rp=require(_0x3f9c('0x3'));var moment=require(_0x3f9c('0x4'));var BPromise=require(_0x3f9c('0x5'));var Mustache=require(_0x3f9c('0x6'));var util=require('util');var path=require(_0x3f9c('0x7'));var sox=require(_0x3f9c('0x8'));var csv=require(_0x3f9c('0x9'));var ejs=require(_0x3f9c('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0x3f9c('0xb'));var crypto=require(_0x3f9c('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x3f9c('0xd'));var toCsv=require(_0x3f9c('0x9'));var querystring=require(_0x3f9c('0xe'));var Papa=require(_0x3f9c('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x3f9c('0x10'));var as=require(_0x3f9c('0x11'));var hardwareService=require(_0x3f9c('0x12'));var logger=require(_0x3f9c('0x13'))('api');var utils=require(_0x3f9c('0x14'));var config=require(_0x3f9c('0x15'));var licenseUtil=require(_0x3f9c('0x16'));var db=require(_0x3f9c('0x17'))['db'];function respondWithStatusCode(_0x10dd99,_0x2a86c5){_0x2a86c5=_0x2a86c5||0xcc;return function(_0x3ba616){if(_0x3ba616){return _0x10dd99[_0x3f9c('0x18')](_0x2a86c5);}return _0x10dd99[_0x3f9c('0x19')](_0x2a86c5)[_0x3f9c('0x1a')]();};}function respondWithResult(_0x1fe8d8,_0x196dba){_0x196dba=_0x196dba||0xc8;return function(_0x315b37){if(_0x315b37){return _0x1fe8d8[_0x3f9c('0x19')](_0x196dba)[_0x3f9c('0x1b')](_0x315b37);}};}function respondWithFilteredResult(_0x4e0215,_0x196d7f){return function(_0x41b4ed){if(_0x41b4ed){var _0x2fa742=_0x41b4ed[_0x3f9c('0x1c')],_0x569328=_0x196d7f[_0x3f9c('0x1d')],_0x248c0e=_0x196d7f[_0x3f9c('0x1d')]+_0x196d7f[_0x3f9c('0x1e')],_0x2f55b9;if(_0x248c0e>=_0x2fa742){_0x248c0e=_0x2fa742;_0x2f55b9=0xc8;}else{_0x2f55b9=0xce;}_0x4e0215[_0x3f9c('0x19')](_0x2f55b9);return _0x4e0215[_0x3f9c('0x1f')](_0x3f9c('0x20'),_0x569328+'-'+_0x248c0e+'/'+_0x2fa742)['json'](_0x41b4ed);}return null;};}function patchUpdates(_0x1d3539){return function(_0x4ce22d){try{jsonpatch[_0x3f9c('0x21')](_0x4ce22d,_0x1d3539,!![]);}catch(_0x316aa5){return BPromise[_0x3f9c('0x22')](_0x316aa5);}return _0x4ce22d[_0x3f9c('0x23')]();};}function saveUpdates(_0x2cc86a,_0x38e6cf){return function(_0x380bde){if(_0x380bde){return _0x380bde[_0x3f9c('0x24')](_0x2cc86a)['then'](function(_0x2d9f91){return _0x2d9f91;});}return null;};}function removeEntity(_0x99bd26,_0x4f4d3c){return function(_0xdb7c1){if(_0xdb7c1){return _0xdb7c1[_0x3f9c('0x25')]()[_0x3f9c('0x26')](function(){_0x99bd26[_0x3f9c('0x19')](0xcc)[_0x3f9c('0x1a')]();});}};}function handleEntityNotFound(_0xc975e0,_0x573bee){return function(_0x1fa3b5){if(!_0x1fa3b5){_0xc975e0[_0x3f9c('0x18')](0x194);}return _0x1fa3b5;};}function handleError(_0x2e0fb3,_0xabd21d){_0xabd21d=_0xabd21d||0x1f4;return function(_0x50b058){logger[_0x3f9c('0x27')](_0x50b058['stack']);if(_0x50b058['name']){delete _0x50b058[_0x3f9c('0x28')];}_0x2e0fb3['status'](_0xabd21d)[_0x3f9c('0x29')](_0x50b058);};}exports[_0x3f9c('0x2a')]=function(_0x45f26d,_0x1adbc2){var _0x74d3da={},_0x5e4802={},_0x106402={'count':0x0,'rows':[]};var _0x2ad802=_[_0x3f9c('0x2b')](db[_0x3f9c('0x2c')]['rawAttributes'],function(_0x15b34a){return{'name':_0x15b34a[_0x3f9c('0x2d')],'type':_0x15b34a[_0x3f9c('0x2e')][_0x3f9c('0x2f')]};});_0x5e4802[_0x3f9c('0x30')]=_['map'](_0x2ad802,_0x3f9c('0x28'));_0x5e4802['query']=_[_0x3f9c('0x31')](_0x45f26d[_0x3f9c('0x32')]);_0x5e4802[_0x3f9c('0x33')]=_[_0x3f9c('0x34')](_0x5e4802['model'],_0x5e4802[_0x3f9c('0x32')]);_0x74d3da['attributes']=_['intersection'](_0x5e4802['model'],qs[_0x3f9c('0x35')](_0x45f26d['query'][_0x3f9c('0x35')]));_0x74d3da[_0x3f9c('0x36')]=_0x74d3da[_0x3f9c('0x36')][_0x3f9c('0x37')]?_0x74d3da[_0x3f9c('0x36')]:_0x5e4802[_0x3f9c('0x30')];if(!_0x45f26d[_0x3f9c('0x32')]['hasOwnProperty']('nolimit')){_0x74d3da['limit']=qs[_0x3f9c('0x1e')](_0x45f26d[_0x3f9c('0x32')][_0x3f9c('0x1e')]);_0x74d3da['offset']=qs['offset'](_0x45f26d[_0x3f9c('0x32')][_0x3f9c('0x1d')]);}_0x74d3da[_0x3f9c('0x38')]=qs[_0x3f9c('0x39')](_0x45f26d['query'][_0x3f9c('0x39')]);_0x74d3da[_0x3f9c('0x3a')]=qs[_0x3f9c('0x33')](_[_0x3f9c('0x3b')](_0x45f26d[_0x3f9c('0x32')],_0x5e4802[_0x3f9c('0x33')]),_0x2ad802);if(_0x45f26d[_0x3f9c('0x32')][_0x3f9c('0x3c')]){_0x74d3da[_0x3f9c('0x3a')]=_[_0x3f9c('0x3d')](_0x74d3da[_0x3f9c('0x3a')],{'$or':_[_0x3f9c('0x2b')](_0x2ad802,function(_0x15fe0a){if(_0x15fe0a[_0x3f9c('0x2e')]!==_0x3f9c('0x3e')){var _0x5ef826={};_0x5ef826[_0x15fe0a[_0x3f9c('0x28')]]={'$like':'%'+_0x45f26d[_0x3f9c('0x32')][_0x3f9c('0x3c')]+'%'};return _0x5ef826;}})});}_0x74d3da=_['merge']({},_0x74d3da,_0x45f26d['options']);var _0x50f7c9={'where':_0x74d3da[_0x3f9c('0x3a')]};return db['UserProfileSection'][_0x3f9c('0x1c')](_0x50f7c9)[_0x3f9c('0x26')](function(_0x16334c){_0x106402['count']=_0x16334c;if(_0x45f26d['query'][_0x3f9c('0x3f')]){_0x74d3da[_0x3f9c('0x40')]=[{'all':!![]}];}return db[_0x3f9c('0x2c')][_0x3f9c('0x41')](_0x74d3da);})[_0x3f9c('0x26')](function(_0x1c898b){_0x106402['rows']=_0x1c898b;return _0x106402;})[_0x3f9c('0x26')](respondWithFilteredResult(_0x1adbc2,_0x74d3da))['catch'](handleError(_0x1adbc2,null));};exports[_0x3f9c('0x42')]=function(_0x1ce251,_0x2cdea5){var _0x25d13b={'raw':![],'where':{'id':_0x1ce251[_0x3f9c('0x43')]['id']}},_0x521be6={};_0x521be6[_0x3f9c('0x30')]=_['keys'](db[_0x3f9c('0x2c')][_0x3f9c('0x44')]);_0x521be6['query']=_[_0x3f9c('0x31')](_0x1ce251[_0x3f9c('0x32')]);_0x521be6[_0x3f9c('0x33')]=_[_0x3f9c('0x34')](_0x521be6[_0x3f9c('0x30')],_0x521be6[_0x3f9c('0x32')]);_0x25d13b[_0x3f9c('0x36')]=_[_0x3f9c('0x34')](_0x521be6[_0x3f9c('0x30')],qs[_0x3f9c('0x35')](_0x1ce251[_0x3f9c('0x32')][_0x3f9c('0x35')]));_0x25d13b['attributes']=_0x25d13b[_0x3f9c('0x36')]['length']?_0x25d13b[_0x3f9c('0x36')]:_0x521be6[_0x3f9c('0x30')];if(_0x1ce251[_0x3f9c('0x32')][_0x3f9c('0x3f')]){_0x25d13b[_0x3f9c('0x40')]=[{'all':!![]}];}_0x25d13b=_['merge']({},_0x25d13b,_0x1ce251[_0x3f9c('0x45')]);return db[_0x3f9c('0x2c')][_0x3f9c('0x46')](_0x25d13b)[_0x3f9c('0x26')](handleEntityNotFound(_0x2cdea5,null))[_0x3f9c('0x26')](respondWithResult(_0x2cdea5,null))[_0x3f9c('0x47')](handleError(_0x2cdea5,null));};exports['create']=function(_0x5ea2b6,_0x4c6f0e){return db['UserProfileSection'][_0x3f9c('0x48')](_0x5ea2b6[_0x3f9c('0x49')],{})[_0x3f9c('0x26')](respondWithResult(_0x4c6f0e,0xc9))[_0x3f9c('0x47')](handleError(_0x4c6f0e,null));};exports['update']=function(_0x1f6673,_0x5be878){if(_0x1f6673[_0x3f9c('0x49')]['id']){delete _0x1f6673['body']['id'];}return db['UserProfileSection'][_0x3f9c('0x46')]({'where':{'id':_0x1f6673['params']['id']}})[_0x3f9c('0x26')](handleEntityNotFound(_0x5be878,null))[_0x3f9c('0x26')](saveUpdates(_0x1f6673['body'],null))[_0x3f9c('0x26')](respondWithResult(_0x5be878,null))[_0x3f9c('0x47')](handleError(_0x5be878,null));};exports[_0x3f9c('0x25')]=function(_0x3727cf,_0x41a4fb){return db[_0x3f9c('0x2c')][_0x3f9c('0x46')]({'where':{'id':_0x3727cf[_0x3f9c('0x43')]['id']}})['then'](handleEntityNotFound(_0x41a4fb,null))[_0x3f9c('0x26')](removeEntity(_0x41a4fb,null))[_0x3f9c('0x47')](handleError(_0x41a4fb,null));};exports['describe']=function(_0x672b39,_0x3d6e8f){return db[_0x3f9c('0x2c')]['describe']()[_0x3f9c('0x26')](respondWithResult(_0x3d6e8f,null))[_0x3f9c('0x47')](handleError(_0x3d6e8f,null));};