e7fd76b6b0658c677dfb3a752c31665eddaa974a
[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 _0x0b0e=['limit','Content-Range','apply','save','update','then','stack','name','send','rawAttributes','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','map','type','key','filter','options','UserProfileSection','includeAll','include','findAll','rows','catch','find','create','body','params','describe','html-pdf','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset'];(function(_0x52a505,_0x5dec98){var _0x1fc95e=function(_0xdc7744){while(--_0xdc7744){_0x52a505['push'](_0x52a505['shift']());}};_0x1fc95e(++_0x5dec98);}(_0x0b0e,0x187));var _0xe0b0=function(_0x1809c5,_0x46cabc){_0x1809c5=_0x1809c5-0x0;var _0x5254a4=_0x0b0e[_0x1809c5];return _0x5254a4;};'use strict';var pdf=require(_0xe0b0('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xe0b0('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xe0b0('0x2'));var rp=require(_0xe0b0('0x3'));var moment=require(_0xe0b0('0x4'));var BPromise=require(_0xe0b0('0x5'));var Mustache=require(_0xe0b0('0x6'));var util=require(_0xe0b0('0x7'));var path=require(_0xe0b0('0x8'));var sox=require(_0xe0b0('0x9'));var csv=require(_0xe0b0('0xa'));var ejs=require(_0xe0b0('0xb'));var fs=require('fs');var _=require(_0xe0b0('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xe0b0('0xd'));var deskjs=require(_0xe0b0('0xe'));var toCsv=require(_0xe0b0('0xa'));var querystring=require(_0xe0b0('0xf'));var Papa=require('papaparse');var Redis=require(_0xe0b0('0x10'));var authService=require(_0xe0b0('0x11'));var qs=require('../../components/parsers/qs');var hardwareService=require(_0xe0b0('0x12'));var logger=require(_0xe0b0('0x13'))('api');var utils=require(_0xe0b0('0x14'));var config=require(_0xe0b0('0x15'));var db=require(_0xe0b0('0x16'))['db'];function respondWithStatusCode(_0x585615,_0x3068c0){_0x3068c0=_0x3068c0||0xcc;return function(_0x1c358a){if(_0x1c358a){return _0x585615[_0xe0b0('0x17')](_0x3068c0);}return _0x585615[_0xe0b0('0x18')](_0x3068c0)[_0xe0b0('0x19')]();};}function respondWithResult(_0x4d2bf7,_0x3782be){_0x3782be=_0x3782be||0xc8;return function(_0x154de6){if(_0x154de6){return _0x4d2bf7[_0xe0b0('0x18')](_0x3782be)[_0xe0b0('0x1a')](_0x154de6);}};}function respondWithFilteredResult(_0x177c24,_0x55d884){return function(_0x41a7e2){if(_0x41a7e2){var _0x5adb01=_0x41a7e2[_0xe0b0('0x1b')],_0x35cb40=_0x55d884['offset'],_0xadee6e=_0x55d884[_0xe0b0('0x1c')]+_0x55d884[_0xe0b0('0x1d')],_0x519ae8;if(_0xadee6e>=_0x5adb01){_0xadee6e=_0x5adb01;_0x519ae8=0xc8;}else{_0x519ae8=0xce;}_0x177c24['status'](_0x519ae8);return _0x177c24['set'](_0xe0b0('0x1e'),_0x35cb40+'-'+_0xadee6e+'/'+_0x5adb01)['json'](_0x41a7e2);}return null;};}function patchUpdates(_0x4df8da){return function(_0x4bce65){try{jsonpatch[_0xe0b0('0x1f')](_0x4bce65,_0x4df8da,!![]);}catch(_0x50fa4a){return BPromise['reject'](_0x50fa4a);}return _0x4bce65[_0xe0b0('0x20')]();};}function saveUpdates(_0x59dff5,_0x472286){return function(_0x5dba2f){if(_0x5dba2f){return _0x5dba2f[_0xe0b0('0x21')](_0x59dff5)[_0xe0b0('0x22')](function(_0x3e10b3){return _0x3e10b3;});}return null;};}function removeEntity(_0x310a6d,_0x2cf6a1){return function(_0x58b804){if(_0x58b804){return _0x58b804['destroy']()[_0xe0b0('0x22')](function(){_0x310a6d['status'](0xcc)[_0xe0b0('0x19')]();});}};}function handleEntityNotFound(_0x31b5f8,_0x513e63){return function(_0x170ad8){if(!_0x170ad8){_0x31b5f8['sendStatus'](0x194);}return _0x170ad8;};}function handleError(_0x2208d0,_0x49a727){_0x49a727=_0x49a727||0x1f4;return function(_0x28586d){logger['error'](_0x28586d[_0xe0b0('0x23')]);if(_0x28586d['name']){delete _0x28586d[_0xe0b0('0x24')];}_0x2208d0['status'](_0x49a727)[_0xe0b0('0x25')](_0x28586d);};}exports['index']=function(_0x362aba,_0x3c3bc2){var _0x1f1ebd={},_0x1d91ad={},_0x3ec2={'count':0x0,'rows':[]};var _0x10745d=db['UserProfileSection'][_0xe0b0('0x26')];_0x1d91ad[_0xe0b0('0x27')]=_['keys'](_0x10745d);_0x1d91ad[_0xe0b0('0x28')]=_[_0xe0b0('0x29')](_0x362aba[_0xe0b0('0x28')]);_0x1d91ad[_0xe0b0('0x2a')]=_[_0xe0b0('0x2b')](_0x1d91ad[_0xe0b0('0x27')],_0x1d91ad[_0xe0b0('0x28')]);_0x1f1ebd['attributes']=_[_0xe0b0('0x2b')](_0x1d91ad[_0xe0b0('0x27')],qs['fields'](_0x362aba['query'][_0xe0b0('0x2c')]));_0x1f1ebd[_0xe0b0('0x2d')]=_0x1f1ebd[_0xe0b0('0x2d')][_0xe0b0('0x2e')]?_0x1f1ebd[_0xe0b0('0x2d')]:_0x1d91ad['model'];if(!_0x362aba[_0xe0b0('0x28')][_0xe0b0('0x2f')](_0xe0b0('0x30'))){_0x1f1ebd[_0xe0b0('0x1d')]=qs[_0xe0b0('0x1d')](_0x362aba['query'][_0xe0b0('0x1d')]);_0x1f1ebd[_0xe0b0('0x1c')]=qs[_0xe0b0('0x1c')](_0x362aba[_0xe0b0('0x28')][_0xe0b0('0x1c')]);}_0x1f1ebd[_0xe0b0('0x31')]=qs[_0xe0b0('0x32')](_0x362aba[_0xe0b0('0x28')][_0xe0b0('0x32')]);_0x1f1ebd[_0xe0b0('0x33')]=qs[_0xe0b0('0x2a')](_[_0xe0b0('0x34')](_0x362aba[_0xe0b0('0x28')],_0x1d91ad[_0xe0b0('0x2a')]));if(_0x362aba[_0xe0b0('0x28')]['filter']){_0x1f1ebd[_0xe0b0('0x33')]=_[_0xe0b0('0x35')](_0x1f1ebd[_0xe0b0('0x33')],{'$or':_[_0xe0b0('0x36')](_0x10745d,function(_0x1a2d24){if(_0x1a2d24[_0xe0b0('0x37')][_0xe0b0('0x38')]!=='VIRTUAL'){var _0x521243={};_0x521243[_0x1a2d24['field']]={'$like':'%'+_0x362aba['query'][_0xe0b0('0x39')]+'%'};return _0x521243;}})});}_0x1f1ebd=_[_0xe0b0('0x35')]({},_0x1f1ebd,_0x362aba[_0xe0b0('0x3a')]);var _0x4e4b20={'where':_0x1f1ebd[_0xe0b0('0x33')]};return db[_0xe0b0('0x3b')][_0xe0b0('0x1b')](_0x4e4b20)[_0xe0b0('0x22')](function(_0x563e28){_0x3ec2[_0xe0b0('0x1b')]=_0x563e28;if(_0x362aba[_0xe0b0('0x28')][_0xe0b0('0x3c')]){_0x1f1ebd[_0xe0b0('0x3d')]=[{'all':!![]}];}return db[_0xe0b0('0x3b')][_0xe0b0('0x3e')](_0x1f1ebd);})[_0xe0b0('0x22')](function(_0x115a69){_0x3ec2[_0xe0b0('0x3f')]=_0x115a69;return _0x3ec2;})['then'](respondWithFilteredResult(_0x3c3bc2,_0x1f1ebd))[_0xe0b0('0x40')](handleError(_0x3c3bc2,null));};exports['show']=function(_0x34178d,_0x2d5f47){var _0x46c4ea={'raw':![],'where':{'id':_0x34178d['params']['id']}},_0x74f3fa={};_0x74f3fa[_0xe0b0('0x27')]=_[_0xe0b0('0x29')](db[_0xe0b0('0x3b')][_0xe0b0('0x26')]);_0x74f3fa[_0xe0b0('0x28')]=_[_0xe0b0('0x29')](_0x34178d[_0xe0b0('0x28')]);_0x74f3fa[_0xe0b0('0x2a')]=_['intersection'](_0x74f3fa[_0xe0b0('0x27')],_0x74f3fa[_0xe0b0('0x28')]);_0x46c4ea['attributes']=_['intersection'](_0x74f3fa[_0xe0b0('0x27')],qs[_0xe0b0('0x2c')](_0x34178d['query'][_0xe0b0('0x2c')]));_0x46c4ea[_0xe0b0('0x2d')]=_0x46c4ea[_0xe0b0('0x2d')][_0xe0b0('0x2e')]?_0x46c4ea[_0xe0b0('0x2d')]:_0x74f3fa['model'];if(_0x34178d['query']['includeAll']){_0x46c4ea[_0xe0b0('0x3d')]=[{'all':!![]}];}_0x46c4ea=_[_0xe0b0('0x35')]({},_0x46c4ea,_0x34178d['options']);return db[_0xe0b0('0x3b')][_0xe0b0('0x41')](_0x46c4ea)[_0xe0b0('0x22')](handleEntityNotFound(_0x2d5f47,null))[_0xe0b0('0x22')](respondWithResult(_0x2d5f47,null))[_0xe0b0('0x40')](handleError(_0x2d5f47,null));};exports['create']=function(_0x57d4b0,_0x2405ae){return db[_0xe0b0('0x3b')][_0xe0b0('0x42')](_0x57d4b0[_0xe0b0('0x43')],{})[_0xe0b0('0x22')](respondWithResult(_0x2405ae,0xc9))['catch'](handleError(_0x2405ae,null));};exports[_0xe0b0('0x21')]=function(_0x11d4fd,_0x534340){if(_0x11d4fd['body']['id']){delete _0x11d4fd['body']['id'];}return db[_0xe0b0('0x3b')][_0xe0b0('0x41')]({'where':{'id':_0x11d4fd[_0xe0b0('0x44')]['id']}})[_0xe0b0('0x22')](handleEntityNotFound(_0x534340,null))['then'](saveUpdates(_0x11d4fd[_0xe0b0('0x43')],null))[_0xe0b0('0x22')](respondWithResult(_0x534340,null))['catch'](handleError(_0x534340,null));};exports['destroy']=function(_0x2365be,_0x1bc6e0){return db['UserProfileSection'][_0xe0b0('0x41')]({'where':{'id':_0x2365be[_0xe0b0('0x44')]['id']}})['then'](handleEntityNotFound(_0x1bc6e0,null))['then'](removeEntity(_0x1bc6e0,null))[_0xe0b0('0x40')](handleError(_0x1bc6e0,null));};exports['describe']=function(_0x165dc8,_0x215f7d){return db[_0xe0b0('0x3b')][_0xe0b0('0x45')]()[_0xe0b0('0x22')](respondWithResult(_0x215f7d,null))[_0xe0b0('0x40')](handleError(_0x215f7d,null));};