b10535c75225f850c1be1fa9d8c55cf4d8f90892
[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 _0xab05=['querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../mysqldb','sendStatus','status','end','json','count','set','Content-Range','reject','then','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','offset','order','sort','pick','filter','where','merge','VIRTUAL','options','UserProfileSection','includeAll','include','findAll','catch','params','keys','find','create','update','body','describe','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js'];(function(_0x28b088,_0xddb75e){var _0x4b329e=function(_0x1944bb){while(--_0x1944bb){_0x28b088['push'](_0x28b088['shift']());}};_0x4b329e(++_0xddb75e);}(_0xab05,0x1b6));var _0x5ab0=function(_0x4e9628,_0x250573){_0x4e9628=_0x4e9628-0x0;var _0x27bc8c=_0xab05[_0x4e9628];return _0x27bc8c;};'use strict';var pdf=require(_0x5ab0('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x5ab0('0x1'));var zipdir=require(_0x5ab0('0x2'));var jsonpatch=require(_0x5ab0('0x3'));var rp=require(_0x5ab0('0x4'));var moment=require(_0x5ab0('0x5'));var BPromise=require(_0x5ab0('0x6'));var Mustache=require(_0x5ab0('0x7'));var util=require(_0x5ab0('0x8'));var path=require(_0x5ab0('0x9'));var sox=require(_0x5ab0('0xa'));var csv=require(_0x5ab0('0xb'));var ejs=require(_0x5ab0('0xc'));var fs=require('fs');var _=require(_0x5ab0('0xd'));var squel=require(_0x5ab0('0xe'));var crypto=require(_0x5ab0('0xf'));var jsforce=require(_0x5ab0('0x10'));var deskjs=require(_0x5ab0('0x11'));var toCsv=require(_0x5ab0('0xb'));var querystring=require(_0x5ab0('0x12'));var Papa=require(_0x5ab0('0x13'));var Redis=require('ioredis');var authService=require(_0x5ab0('0x14'));var qs=require(_0x5ab0('0x15'));var as=require(_0x5ab0('0x16'));var hardwareService=require(_0x5ab0('0x17'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x5ab0('0x18'))['db'];function respondWithStatusCode(_0x29886e,_0x202815){_0x202815=_0x202815||0xcc;return function(_0x3e2817){if(_0x3e2817){return _0x29886e[_0x5ab0('0x19')](_0x202815);}return _0x29886e[_0x5ab0('0x1a')](_0x202815)[_0x5ab0('0x1b')]();};}function respondWithResult(_0x4c80c9,_0x58f239){_0x58f239=_0x58f239||0xc8;return function(_0x2378f8){if(_0x2378f8){return _0x4c80c9['status'](_0x58f239)[_0x5ab0('0x1c')](_0x2378f8);}};}function respondWithFilteredResult(_0x3a210c,_0x55b0b5){return function(_0x42e500){if(_0x42e500){var _0x2a382d=_0x42e500[_0x5ab0('0x1d')],_0x475b82=_0x55b0b5['offset'],_0x54a1fc=_0x55b0b5['offset']+_0x55b0b5['limit'],_0xbc3efa;if(_0x54a1fc>=_0x2a382d){_0x54a1fc=_0x2a382d;_0xbc3efa=0xc8;}else{_0xbc3efa=0xce;}_0x3a210c[_0x5ab0('0x1a')](_0xbc3efa);return _0x3a210c[_0x5ab0('0x1e')](_0x5ab0('0x1f'),_0x475b82+'-'+_0x54a1fc+'/'+_0x2a382d)[_0x5ab0('0x1c')](_0x42e500);}return null;};}function patchUpdates(_0xdc2607){return function(_0x23d784){try{jsonpatch['apply'](_0x23d784,_0xdc2607,!![]);}catch(_0x4795ec){return BPromise[_0x5ab0('0x20')](_0x4795ec);}return _0x23d784['save']();};}function saveUpdates(_0x41b971,_0x2b3e67){return function(_0x350682){if(_0x350682){return _0x350682['update'](_0x41b971)[_0x5ab0('0x21')](function(_0x4a583a){return _0x4a583a;});}return null;};}function removeEntity(_0x3fce1b,_0x3d3762){return function(_0x7ae3fa){if(_0x7ae3fa){return _0x7ae3fa[_0x5ab0('0x22')]()[_0x5ab0('0x21')](function(){_0x3fce1b[_0x5ab0('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2f4cf6,_0x549841){return function(_0x48ef57){if(!_0x48ef57){_0x2f4cf6[_0x5ab0('0x19')](0x194);}return _0x48ef57;};}function handleError(_0x4081e1,_0x4a473a){_0x4a473a=_0x4a473a||0x1f4;return function(_0x3628a6){logger[_0x5ab0('0x23')](_0x3628a6[_0x5ab0('0x24')]);if(_0x3628a6[_0x5ab0('0x25')]){delete _0x3628a6[_0x5ab0('0x25')];}_0x4081e1[_0x5ab0('0x1a')](_0x4a473a)[_0x5ab0('0x26')](_0x3628a6);};}exports[_0x5ab0('0x27')]=function(_0x5e0b03,_0x29b146){var _0x458c9b={},_0x291e82={},_0x94fa1={'count':0x0,'rows':[]};var _0x39d000=_[_0x5ab0('0x28')](db['UserProfileSection'][_0x5ab0('0x29')],function(_0x4985be){return{'name':_0x4985be[_0x5ab0('0x2a')],'type':_0x4985be[_0x5ab0('0x2b')][_0x5ab0('0x2c')]};});_0x291e82[_0x5ab0('0x2d')]=_[_0x5ab0('0x28')](_0x39d000,_0x5ab0('0x25'));_0x291e82[_0x5ab0('0x2e')]=_['keys'](_0x5e0b03[_0x5ab0('0x2e')]);_0x291e82[_0x5ab0('0x2f')]=_[_0x5ab0('0x30')](_0x291e82[_0x5ab0('0x2d')],_0x291e82['query']);_0x458c9b[_0x5ab0('0x31')]=_[_0x5ab0('0x30')](_0x291e82['model'],qs['fields'](_0x5e0b03[_0x5ab0('0x2e')][_0x5ab0('0x32')]));_0x458c9b[_0x5ab0('0x31')]=_0x458c9b['attributes'][_0x5ab0('0x33')]?_0x458c9b[_0x5ab0('0x31')]:_0x291e82['model'];if(!_0x5e0b03[_0x5ab0('0x2e')][_0x5ab0('0x34')](_0x5ab0('0x35'))){_0x458c9b[_0x5ab0('0x36')]=qs[_0x5ab0('0x36')](_0x5e0b03[_0x5ab0('0x2e')][_0x5ab0('0x36')]);_0x458c9b['offset']=qs[_0x5ab0('0x37')](_0x5e0b03[_0x5ab0('0x2e')][_0x5ab0('0x37')]);}_0x458c9b[_0x5ab0('0x38')]=qs[_0x5ab0('0x39')](_0x5e0b03['query'][_0x5ab0('0x39')]);_0x458c9b['where']=qs[_0x5ab0('0x2f')](_[_0x5ab0('0x3a')](_0x5e0b03[_0x5ab0('0x2e')],_0x291e82[_0x5ab0('0x2f')]),_0x39d000);if(_0x5e0b03[_0x5ab0('0x2e')][_0x5ab0('0x3b')]){_0x458c9b[_0x5ab0('0x3c')]=_[_0x5ab0('0x3d')](_0x458c9b[_0x5ab0('0x3c')],{'$or':_[_0x5ab0('0x28')](_0x39d000,function(_0x2426f1){if(_0x2426f1['type']!==_0x5ab0('0x3e')){var _0x130f93={};_0x130f93[_0x2426f1[_0x5ab0('0x25')]]={'$like':'%'+_0x5e0b03[_0x5ab0('0x2e')][_0x5ab0('0x3b')]+'%'};return _0x130f93;}})});}_0x458c9b=_[_0x5ab0('0x3d')]({},_0x458c9b,_0x5e0b03[_0x5ab0('0x3f')]);var _0x53d218={'where':_0x458c9b[_0x5ab0('0x3c')]};return db[_0x5ab0('0x40')][_0x5ab0('0x1d')](_0x53d218)[_0x5ab0('0x21')](function(_0x5372d5){_0x94fa1[_0x5ab0('0x1d')]=_0x5372d5;if(_0x5e0b03[_0x5ab0('0x2e')][_0x5ab0('0x41')]){_0x458c9b[_0x5ab0('0x42')]=[{'all':!![]}];}return db['UserProfileSection'][_0x5ab0('0x43')](_0x458c9b);})['then'](function(_0x4e8b2a){_0x94fa1['rows']=_0x4e8b2a;return _0x94fa1;})[_0x5ab0('0x21')](respondWithFilteredResult(_0x29b146,_0x458c9b))[_0x5ab0('0x44')](handleError(_0x29b146,null));};exports['show']=function(_0x306e86,_0xeb9624){var _0x17e115={'raw':![],'where':{'id':_0x306e86[_0x5ab0('0x45')]['id']}},_0x2e54c4={};_0x2e54c4[_0x5ab0('0x2d')]=_[_0x5ab0('0x46')](db[_0x5ab0('0x40')][_0x5ab0('0x29')]);_0x2e54c4[_0x5ab0('0x2e')]=_[_0x5ab0('0x46')](_0x306e86[_0x5ab0('0x2e')]);_0x2e54c4[_0x5ab0('0x2f')]=_[_0x5ab0('0x30')](_0x2e54c4[_0x5ab0('0x2d')],_0x2e54c4['query']);_0x17e115[_0x5ab0('0x31')]=_[_0x5ab0('0x30')](_0x2e54c4[_0x5ab0('0x2d')],qs[_0x5ab0('0x32')](_0x306e86[_0x5ab0('0x2e')][_0x5ab0('0x32')]));_0x17e115[_0x5ab0('0x31')]=_0x17e115[_0x5ab0('0x31')]['length']?_0x17e115[_0x5ab0('0x31')]:_0x2e54c4[_0x5ab0('0x2d')];if(_0x306e86[_0x5ab0('0x2e')]['includeAll']){_0x17e115[_0x5ab0('0x42')]=[{'all':!![]}];}_0x17e115=_['merge']({},_0x17e115,_0x306e86[_0x5ab0('0x3f')]);return db[_0x5ab0('0x40')][_0x5ab0('0x47')](_0x17e115)[_0x5ab0('0x21')](handleEntityNotFound(_0xeb9624,null))['then'](respondWithResult(_0xeb9624,null))[_0x5ab0('0x44')](handleError(_0xeb9624,null));};exports['create']=function(_0x27add1,_0x3c5de2){return db[_0x5ab0('0x40')][_0x5ab0('0x48')](_0x27add1['body'],{})['then'](respondWithResult(_0x3c5de2,0xc9))[_0x5ab0('0x44')](handleError(_0x3c5de2,null));};exports[_0x5ab0('0x49')]=function(_0xa617ca,_0x2dd043){if(_0xa617ca[_0x5ab0('0x4a')]['id']){delete _0xa617ca[_0x5ab0('0x4a')]['id'];}return db[_0x5ab0('0x40')][_0x5ab0('0x47')]({'where':{'id':_0xa617ca[_0x5ab0('0x45')]['id']}})[_0x5ab0('0x21')](handleEntityNotFound(_0x2dd043,null))['then'](saveUpdates(_0xa617ca['body'],null))['then'](respondWithResult(_0x2dd043,null))[_0x5ab0('0x44')](handleError(_0x2dd043,null));};exports[_0x5ab0('0x22')]=function(_0x1dc63d,_0x3771b6){return db[_0x5ab0('0x40')][_0x5ab0('0x47')]({'where':{'id':_0x1dc63d['params']['id']}})[_0x5ab0('0x21')](handleEntityNotFound(_0x3771b6,null))['then'](removeEntity(_0x3771b6,null))[_0x5ab0('0x44')](handleError(_0x3771b6,null));};exports[_0x5ab0('0x4b')]=function(_0xf6bdc3,_0x57cc7d){return db[_0x5ab0('0x40')][_0x5ab0('0x4b')]()[_0x5ab0('0x21')](respondWithResult(_0x57cc7d,null))[_0x5ab0('0x44')](handleError(_0x57cc7d,null));};