Built motion from commit c116dc8b.|2.6.30
[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 _0xa7f2=['fs-extra','lodash','squel','crypto','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','Content-Range','apply','reject','update','then','destroy','stack','name','send','index','map','fieldName','model','query','attributes','intersection','fields','length','hasOwnProperty','sort','where','filters','pick','filter','merge','type','VIRTUAL','UserProfileSection','includeAll','include','findAll','rows','params','keys','options','catch','create','body','find','describe','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv'];(function(_0x6131cd,_0x4c26a1){var _0x47e916=function(_0x1f2bce){while(--_0x1f2bce){_0x6131cd['push'](_0x6131cd['shift']());}};_0x47e916(++_0x4c26a1);}(_0xa7f2,0x164));var _0x2a7f=function(_0x1915e2,_0x51f382){_0x1915e2=_0x1915e2-0x0;var _0x550ab2=_0xa7f2[_0x1915e2];return _0x550ab2;};'use strict';var emlformat=require(_0x2a7f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x2a7f('0x1'));var jsonpatch=require(_0x2a7f('0x2'));var rp=require('request-promise');var moment=require(_0x2a7f('0x3'));var BPromise=require(_0x2a7f('0x4'));var Mustache=require(_0x2a7f('0x5'));var util=require(_0x2a7f('0x6'));var path=require('path');var sox=require(_0x2a7f('0x7'));var csv=require(_0x2a7f('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x2a7f('0x9'));var _=require(_0x2a7f('0xa'));var squel=require(_0x2a7f('0xb'));var crypto=require(_0x2a7f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x2a7f('0xd'));var toCsv=require(_0x2a7f('0x8'));var querystring=require('querystring');var Papa=require(_0x2a7f('0xe'));var Redis=require('ioredis');var authService=require(_0x2a7f('0xf'));var qs=require(_0x2a7f('0x10'));var as=require(_0x2a7f('0x11'));var hardwareService=require(_0x2a7f('0x12'));var logger=require(_0x2a7f('0x13'))(_0x2a7f('0x14'));var utils=require(_0x2a7f('0x15'));var config=require(_0x2a7f('0x16'));var licenseUtil=require(_0x2a7f('0x17'));var db=require(_0x2a7f('0x18'))['db'];function respondWithStatusCode(_0x356b2e,_0x255d65){_0x255d65=_0x255d65||0xcc;return function(_0x195d41){if(_0x195d41){return _0x356b2e[_0x2a7f('0x19')](_0x255d65);}return _0x356b2e[_0x2a7f('0x1a')](_0x255d65)[_0x2a7f('0x1b')]();};}function respondWithResult(_0x3e8a2b,_0x2b5c0c){_0x2b5c0c=_0x2b5c0c||0xc8;return function(_0x3d25d7){if(_0x3d25d7){return _0x3e8a2b[_0x2a7f('0x1a')](_0x2b5c0c)[_0x2a7f('0x1c')](_0x3d25d7);}};}function respondWithFilteredResult(_0x3390cb,_0x54bda0){return function(_0x28ea27){if(_0x28ea27){var _0x366df0=typeof _0x54bda0[_0x2a7f('0x1d')]==='undefined'&&typeof _0x54bda0[_0x2a7f('0x1e')]===_0x2a7f('0x1f');var _0xb683f5=_0x28ea27[_0x2a7f('0x20')];var _0x33890e=_0x366df0?0x0:_0x54bda0[_0x2a7f('0x1d')];var _0x22619c=_0x366df0?_0x28ea27['count']:_0x54bda0['offset']+_0x54bda0[_0x2a7f('0x1e')];var _0x38da4b;if(_0x22619c>=_0xb683f5){_0x22619c=_0xb683f5;_0x38da4b=0xc8;}else{_0x38da4b=0xce;}_0x3390cb['status'](_0x38da4b);return _0x3390cb['set'](_0x2a7f('0x21'),_0x33890e+'-'+_0x22619c+'/'+_0xb683f5)['json'](_0x28ea27);}return null;};}function patchUpdates(_0x2b6b00){return function(_0x48c3be){try{jsonpatch[_0x2a7f('0x22')](_0x48c3be,_0x2b6b00,!![]);}catch(_0x129bd4){return BPromise[_0x2a7f('0x23')](_0x129bd4);}return _0x48c3be['save']();};}function saveUpdates(_0x5afa04,_0x57035d){return function(_0x3fa540){if(_0x3fa540){return _0x3fa540[_0x2a7f('0x24')](_0x5afa04)[_0x2a7f('0x25')](function(_0x1f3a18){return _0x1f3a18;});}return null;};}function removeEntity(_0xabea77,_0x2890ae){return function(_0x2bd4b7){if(_0x2bd4b7){return _0x2bd4b7[_0x2a7f('0x26')]()[_0x2a7f('0x25')](function(){_0xabea77[_0x2a7f('0x1a')](0xcc)[_0x2a7f('0x1b')]();});}};}function handleEntityNotFound(_0x48f21c,_0x15e9ae){return function(_0x33198f){if(!_0x33198f){_0x48f21c[_0x2a7f('0x19')](0x194);}return _0x33198f;};}function handleError(_0x1e009e,_0x627c5e){_0x627c5e=_0x627c5e||0x1f4;return function(_0x4149e2){logger['error'](_0x4149e2[_0x2a7f('0x27')]);if(_0x4149e2[_0x2a7f('0x28')]){delete _0x4149e2[_0x2a7f('0x28')];}_0x1e009e[_0x2a7f('0x1a')](_0x627c5e)[_0x2a7f('0x29')](_0x4149e2);};}exports[_0x2a7f('0x2a')]=function(_0x2f594b,_0x3f65ee){var _0x3aeda2={},_0x469827={},_0xe84999={'count':0x0,'rows':[]};var _0x199726=_[_0x2a7f('0x2b')](db['UserProfileSection']['rawAttributes'],function(_0x54839c){return{'name':_0x54839c[_0x2a7f('0x2c')],'type':_0x54839c['type']['key']};});_0x469827[_0x2a7f('0x2d')]=_['map'](_0x199726,_0x2a7f('0x28'));_0x469827[_0x2a7f('0x2e')]=_['keys'](_0x2f594b[_0x2a7f('0x2e')]);_0x469827['filters']=_['intersection'](_0x469827[_0x2a7f('0x2d')],_0x469827[_0x2a7f('0x2e')]);_0x3aeda2[_0x2a7f('0x2f')]=_[_0x2a7f('0x30')](_0x469827[_0x2a7f('0x2d')],qs[_0x2a7f('0x31')](_0x2f594b['query']['fields']));_0x3aeda2[_0x2a7f('0x2f')]=_0x3aeda2[_0x2a7f('0x2f')][_0x2a7f('0x32')]?_0x3aeda2[_0x2a7f('0x2f')]:_0x469827[_0x2a7f('0x2d')];if(!_0x2f594b['query'][_0x2a7f('0x33')]('nolimit')){_0x3aeda2[_0x2a7f('0x1e')]=qs[_0x2a7f('0x1e')](_0x2f594b['query'][_0x2a7f('0x1e')]);_0x3aeda2[_0x2a7f('0x1d')]=qs['offset'](_0x2f594b['query'][_0x2a7f('0x1d')]);}_0x3aeda2['order']=qs['sort'](_0x2f594b[_0x2a7f('0x2e')][_0x2a7f('0x34')]);_0x3aeda2[_0x2a7f('0x35')]=qs[_0x2a7f('0x36')](_[_0x2a7f('0x37')](_0x2f594b[_0x2a7f('0x2e')],_0x469827[_0x2a7f('0x36')]),_0x199726);if(_0x2f594b[_0x2a7f('0x2e')][_0x2a7f('0x38')]){_0x3aeda2[_0x2a7f('0x35')]=_[_0x2a7f('0x39')](_0x3aeda2[_0x2a7f('0x35')],{'$or':_[_0x2a7f('0x2b')](_0x199726,function(_0x27d7f3){if(_0x27d7f3[_0x2a7f('0x3a')]!==_0x2a7f('0x3b')){var _0x368d65={};_0x368d65[_0x27d7f3[_0x2a7f('0x28')]]={'$like':'%'+_0x2f594b[_0x2a7f('0x2e')]['filter']+'%'};return _0x368d65;}})});}_0x3aeda2=_[_0x2a7f('0x39')]({},_0x3aeda2,_0x2f594b['options']);var _0x189494={'where':_0x3aeda2[_0x2a7f('0x35')]};return db[_0x2a7f('0x3c')]['count'](_0x189494)['then'](function(_0xd9c568){_0xe84999[_0x2a7f('0x20')]=_0xd9c568;if(_0x2f594b[_0x2a7f('0x2e')][_0x2a7f('0x3d')]){_0x3aeda2[_0x2a7f('0x3e')]=[{'all':!![]}];}return db[_0x2a7f('0x3c')][_0x2a7f('0x3f')](_0x3aeda2);})[_0x2a7f('0x25')](function(_0x1d726e){_0xe84999[_0x2a7f('0x40')]=_0x1d726e;return _0xe84999;})['then'](respondWithFilteredResult(_0x3f65ee,_0x3aeda2))['catch'](handleError(_0x3f65ee,null));};exports['show']=function(_0x3f09bb,_0x179908){var _0x4923bb={'raw':![],'where':{'id':_0x3f09bb[_0x2a7f('0x41')]['id']}},_0x3d469b={};_0x3d469b[_0x2a7f('0x2d')]=_[_0x2a7f('0x42')](db[_0x2a7f('0x3c')]['rawAttributes']);_0x3d469b[_0x2a7f('0x2e')]=_['keys'](_0x3f09bb[_0x2a7f('0x2e')]);_0x3d469b[_0x2a7f('0x36')]=_[_0x2a7f('0x30')](_0x3d469b[_0x2a7f('0x2d')],_0x3d469b[_0x2a7f('0x2e')]);_0x4923bb[_0x2a7f('0x2f')]=_[_0x2a7f('0x30')](_0x3d469b[_0x2a7f('0x2d')],qs[_0x2a7f('0x31')](_0x3f09bb[_0x2a7f('0x2e')][_0x2a7f('0x31')]));_0x4923bb[_0x2a7f('0x2f')]=_0x4923bb[_0x2a7f('0x2f')][_0x2a7f('0x32')]?_0x4923bb[_0x2a7f('0x2f')]:_0x3d469b[_0x2a7f('0x2d')];if(_0x3f09bb['query'][_0x2a7f('0x3d')]){_0x4923bb[_0x2a7f('0x3e')]=[{'all':!![]}];}_0x4923bb=_[_0x2a7f('0x39')]({},_0x4923bb,_0x3f09bb[_0x2a7f('0x43')]);return db[_0x2a7f('0x3c')]['find'](_0x4923bb)[_0x2a7f('0x25')](handleEntityNotFound(_0x179908,null))[_0x2a7f('0x25')](respondWithResult(_0x179908,null))[_0x2a7f('0x44')](handleError(_0x179908,null));};exports[_0x2a7f('0x45')]=function(_0x18d227,_0xd10d31){return db[_0x2a7f('0x3c')][_0x2a7f('0x45')](_0x18d227[_0x2a7f('0x46')],{})[_0x2a7f('0x25')](respondWithResult(_0xd10d31,0xc9))[_0x2a7f('0x44')](handleError(_0xd10d31,null));};exports['update']=function(_0x36d8d6,_0x56dd4a){if(_0x36d8d6[_0x2a7f('0x46')]['id']){delete _0x36d8d6[_0x2a7f('0x46')]['id'];}return db[_0x2a7f('0x3c')][_0x2a7f('0x47')]({'where':{'id':_0x36d8d6[_0x2a7f('0x41')]['id']}})[_0x2a7f('0x25')](handleEntityNotFound(_0x56dd4a,null))[_0x2a7f('0x25')](saveUpdates(_0x36d8d6[_0x2a7f('0x46')],null))[_0x2a7f('0x25')](respondWithResult(_0x56dd4a,null))[_0x2a7f('0x44')](handleError(_0x56dd4a,null));};exports[_0x2a7f('0x26')]=function(_0x4d7ba3,_0x23b70f){return db['UserProfileSection'][_0x2a7f('0x47')]({'where':{'id':_0x4d7ba3[_0x2a7f('0x41')]['id']}})['then'](handleEntityNotFound(_0x23b70f,null))[_0x2a7f('0x25')](removeEntity(_0x23b70f,null))[_0x2a7f('0x44')](handleError(_0x23b70f,null));};exports[_0x2a7f('0x48')]=function(_0x5ea09c,_0x5c8e03){return db['UserProfileSection']['describe']()[_0x2a7f('0x25')](respondWithResult(_0x5c8e03,null))[_0x2a7f('0x44')](handleError(_0x5c8e03,null));};