eadbd3a95c17f6a1c6a9041b75ec3b9a5f642068
[motion2.git] / server / api / userProfileResource / userProfileResource.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 _0x6c9b=['destroy','stack','send','index','map','UserProfileResource','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','name','options','includeAll','findAll','rows','show','params','keys','rawAttributes','include','find','create','body','catch','describe','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','path','sox','ejs','squel','crypto','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then'];(function(_0xfec4f2,_0x27b2aa){var _0x4ee052=function(_0x195ba5){while(--_0x195ba5){_0xfec4f2['push'](_0xfec4f2['shift']());}};_0x4ee052(++_0x27b2aa);}(_0x6c9b,0x108));var _0xb6c9=function(_0x57e9b0,_0x1dfbdf){_0x57e9b0=_0x57e9b0-0x0;var _0xbd00=_0x6c9b[_0x57e9b0];return _0xbd00;};'use strict';var pdf=require(_0xb6c9('0x0'));var emlformat=require(_0xb6c9('0x1'));var rimraf=require(_0xb6c9('0x2'));var zipdir=require(_0xb6c9('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb6c9('0x4'));var moment=require(_0xb6c9('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xb6c9('0x6'));var util=require(_0xb6c9('0x7'));var path=require(_0xb6c9('0x8'));var sox=require(_0xb6c9('0x9'));var csv=require('to-csv');var ejs=require(_0xb6c9('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0xb6c9('0xb'));var crypto=require(_0xb6c9('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xb6c9('0xd'));var querystring=require('querystring');var Papa=require(_0xb6c9('0xe'));var Redis=require(_0xb6c9('0xf'));var authService=require(_0xb6c9('0x10'));var qs=require(_0xb6c9('0x11'));var as=require(_0xb6c9('0x12'));var hardwareService=require(_0xb6c9('0x13'));var logger=require('../../config/logger')(_0xb6c9('0x14'));var utils=require(_0xb6c9('0x15'));var config=require('../../config/environment');var db=require(_0xb6c9('0x16'))['db'];function respondWithStatusCode(_0x116c95,_0x490ad5){_0x490ad5=_0x490ad5||0xcc;return function(_0x481308){if(_0x481308){return _0x116c95[_0xb6c9('0x17')](_0x490ad5);}return _0x116c95[_0xb6c9('0x18')](_0x490ad5)[_0xb6c9('0x19')]();};}function respondWithResult(_0xf49df6,_0x17c8af){_0x17c8af=_0x17c8af||0xc8;return function(_0x1916f8){if(_0x1916f8){return _0xf49df6[_0xb6c9('0x18')](_0x17c8af)[_0xb6c9('0x1a')](_0x1916f8);}};}function respondWithFilteredResult(_0x30d0bc,_0x4806df){return function(_0x4c5a53){if(_0x4c5a53){var _0x2b84e8=_0x4c5a53[_0xb6c9('0x1b')],_0x511c5b=_0x4806df['offset'],_0x54c2df=_0x4806df[_0xb6c9('0x1c')]+_0x4806df[_0xb6c9('0x1d')],_0x3dd6f5;if(_0x54c2df>=_0x2b84e8){_0x54c2df=_0x2b84e8;_0x3dd6f5=0xc8;}else{_0x3dd6f5=0xce;}_0x30d0bc[_0xb6c9('0x18')](_0x3dd6f5);return _0x30d0bc['set'](_0xb6c9('0x1e'),_0x511c5b+'-'+_0x54c2df+'/'+_0x2b84e8)['json'](_0x4c5a53);}return null;};}function patchUpdates(_0x35ceaa){return function(_0x463118){try{jsonpatch[_0xb6c9('0x1f')](_0x463118,_0x35ceaa,!![]);}catch(_0x14657a){return BPromise[_0xb6c9('0x20')](_0x14657a);}return _0x463118[_0xb6c9('0x21')]();};}function saveUpdates(_0x1bcd05,_0x27ff7f){return function(_0x481f47){if(_0x481f47){return _0x481f47[_0xb6c9('0x22')](_0x1bcd05)[_0xb6c9('0x23')](function(_0x1e872d){return _0x1e872d;});}return null;};}function removeEntity(_0x536c51,_0x26554d){return function(_0x5422e1){if(_0x5422e1){return _0x5422e1[_0xb6c9('0x24')]()[_0xb6c9('0x23')](function(){_0x536c51[_0xb6c9('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2a12a8,_0x4954f7){return function(_0x2c31f7){if(!_0x2c31f7){_0x2a12a8[_0xb6c9('0x17')](0x194);}return _0x2c31f7;};}function handleError(_0x40d6d3,_0xf4c477){_0xf4c477=_0xf4c477||0x1f4;return function(_0x1aae02){logger['error'](_0x1aae02[_0xb6c9('0x25')]);if(_0x1aae02['name']){delete _0x1aae02['name'];}_0x40d6d3['status'](_0xf4c477)[_0xb6c9('0x26')](_0x1aae02);};}exports[_0xb6c9('0x27')]=function(_0x380c98,_0x4b8fd2){var _0x3efb1d={},_0x29f2b7={},_0x1ac47b={'count':0x0,'rows':[]};var _0x7783d3=_[_0xb6c9('0x28')](db[_0xb6c9('0x29')]['rawAttributes'],function(_0x1e54c2){return{'name':_0x1e54c2[_0xb6c9('0x2a')],'type':_0x1e54c2[_0xb6c9('0x2b')][_0xb6c9('0x2c')]};});_0x29f2b7[_0xb6c9('0x2d')]=_['map'](_0x7783d3,'name');_0x29f2b7[_0xb6c9('0x2e')]=_['keys'](_0x380c98[_0xb6c9('0x2e')]);_0x29f2b7[_0xb6c9('0x2f')]=_[_0xb6c9('0x30')](_0x29f2b7[_0xb6c9('0x2d')],_0x29f2b7[_0xb6c9('0x2e')]);_0x3efb1d[_0xb6c9('0x31')]=_[_0xb6c9('0x30')](_0x29f2b7[_0xb6c9('0x2d')],qs['fields'](_0x380c98['query'][_0xb6c9('0x32')]));_0x3efb1d[_0xb6c9('0x31')]=_0x3efb1d[_0xb6c9('0x31')][_0xb6c9('0x33')]?_0x3efb1d['attributes']:_0x29f2b7[_0xb6c9('0x2d')];if(!_0x380c98[_0xb6c9('0x2e')][_0xb6c9('0x34')](_0xb6c9('0x35'))){_0x3efb1d[_0xb6c9('0x1d')]=qs[_0xb6c9('0x1d')](_0x380c98[_0xb6c9('0x2e')][_0xb6c9('0x1d')]);_0x3efb1d['offset']=qs[_0xb6c9('0x1c')](_0x380c98[_0xb6c9('0x2e')][_0xb6c9('0x1c')]);}_0x3efb1d[_0xb6c9('0x36')]=qs[_0xb6c9('0x37')](_0x380c98[_0xb6c9('0x2e')][_0xb6c9('0x37')]);_0x3efb1d[_0xb6c9('0x38')]=qs[_0xb6c9('0x2f')](_[_0xb6c9('0x39')](_0x380c98['query'],_0x29f2b7['filters']));if(_0x380c98[_0xb6c9('0x2e')][_0xb6c9('0x3a')]){_0x3efb1d[_0xb6c9('0x38')]=_[_0xb6c9('0x3b')](_0x3efb1d[_0xb6c9('0x38')],{'$or':_['map'](_0x7783d3,function(_0x27120d){if(_0x27120d[_0xb6c9('0x2b')]!=='VIRTUAL'){var _0x408850={};_0x408850[_0x27120d[_0xb6c9('0x3c')]]={'$like':'%'+_0x380c98[_0xb6c9('0x2e')][_0xb6c9('0x3a')]+'%'};return _0x408850;}})});}_0x3efb1d=_[_0xb6c9('0x3b')]({},_0x3efb1d,_0x380c98[_0xb6c9('0x3d')]);var _0x3a0dee={'where':_0x3efb1d[_0xb6c9('0x38')]};return db['UserProfileResource']['count'](_0x3a0dee)[_0xb6c9('0x23')](function(_0x342d8c){_0x1ac47b[_0xb6c9('0x1b')]=_0x342d8c;if(_0x380c98[_0xb6c9('0x2e')][_0xb6c9('0x3e')]){_0x3efb1d['include']=[{'all':!![]}];}return db[_0xb6c9('0x29')][_0xb6c9('0x3f')](_0x3efb1d);})[_0xb6c9('0x23')](function(_0x237d32){_0x1ac47b[_0xb6c9('0x40')]=_0x237d32;return _0x1ac47b;})[_0xb6c9('0x23')](respondWithFilteredResult(_0x4b8fd2,_0x3efb1d))['catch'](handleError(_0x4b8fd2,null));};exports[_0xb6c9('0x41')]=function(_0x3e8eb7,_0x6c7de3){var _0x2dcaa7={'raw':![],'where':{'id':_0x3e8eb7[_0xb6c9('0x42')]['id']}},_0x35cf72={};_0x35cf72['model']=_[_0xb6c9('0x43')](db[_0xb6c9('0x29')][_0xb6c9('0x44')]);_0x35cf72[_0xb6c9('0x2e')]=_['keys'](_0x3e8eb7[_0xb6c9('0x2e')]);_0x35cf72[_0xb6c9('0x2f')]=_['intersection'](_0x35cf72['model'],_0x35cf72['query']);_0x2dcaa7[_0xb6c9('0x31')]=_[_0xb6c9('0x30')](_0x35cf72[_0xb6c9('0x2d')],qs[_0xb6c9('0x32')](_0x3e8eb7[_0xb6c9('0x2e')][_0xb6c9('0x32')]));_0x2dcaa7['attributes']=_0x2dcaa7[_0xb6c9('0x31')][_0xb6c9('0x33')]?_0x2dcaa7[_0xb6c9('0x31')]:_0x35cf72['model'];if(_0x3e8eb7['query'][_0xb6c9('0x3e')]){_0x2dcaa7[_0xb6c9('0x45')]=[{'all':!![]}];}_0x2dcaa7=_[_0xb6c9('0x3b')]({},_0x2dcaa7,_0x3e8eb7[_0xb6c9('0x3d')]);return db[_0xb6c9('0x29')][_0xb6c9('0x46')](_0x2dcaa7)[_0xb6c9('0x23')](handleEntityNotFound(_0x6c7de3,null))['then'](respondWithResult(_0x6c7de3,null))['catch'](handleError(_0x6c7de3,null));};exports[_0xb6c9('0x47')]=function(_0x2d666b,_0x28f951){return db[_0xb6c9('0x29')]['create'](_0x2d666b[_0xb6c9('0x48')],{})[_0xb6c9('0x23')](respondWithResult(_0x28f951,0xc9))['catch'](handleError(_0x28f951,null));};exports[_0xb6c9('0x22')]=function(_0x56f931,_0x5b5737){if(_0x56f931[_0xb6c9('0x48')]['id']){delete _0x56f931[_0xb6c9('0x48')]['id'];}return db[_0xb6c9('0x29')][_0xb6c9('0x46')]({'where':{'id':_0x56f931[_0xb6c9('0x42')]['id']}})[_0xb6c9('0x23')](handleEntityNotFound(_0x5b5737,null))[_0xb6c9('0x23')](saveUpdates(_0x56f931['body'],null))[_0xb6c9('0x23')](respondWithResult(_0x5b5737,null))[_0xb6c9('0x49')](handleError(_0x5b5737,null));};exports['destroy']=function(_0x88109,_0x45864a){return db[_0xb6c9('0x29')][_0xb6c9('0x46')]({'where':{'id':_0x88109['params']['id']}})['then'](handleEntityNotFound(_0x45864a,null))[_0xb6c9('0x23')](removeEntity(_0x45864a,null))[_0xb6c9('0x49')](handleError(_0x45864a,null));};exports['describe']=function(_0x42d8c3,_0x4e1594){return db[_0xb6c9('0x29')][_0xb6c9('0x4a')]()[_0xb6c9('0x23')](respondWithResult(_0x4e1594,null))['catch'](handleError(_0x4e1594,null));};