41178d155f8ce194a787708c4b4c80d87cbd6db1
[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 _0xb1b7=['params','rawAttributes','options','find','create','body','describe','eml-format','zip-dir','moment','bluebird','sox','to-csv','fs-extra','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','limit','count','offset','Content-Range','save','update','then','destroy','end','error','stack','name','send','index','map','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','UserProfileSection','includeAll','include','findAll','rows','catch','show'];(function(_0x22f8ab,_0x15d8ff){var _0x2a70e5=function(_0x5e6895){while(--_0x5e6895){_0x22f8ab['push'](_0x22f8ab['shift']());}};_0x2a70e5(++_0x15d8ff);}(_0xb1b7,0x165));var _0x7b1b=function(_0x5f08fc,_0x4f314f){_0x5f08fc=_0x5f08fc-0x0;var _0x41e94d=_0xb1b7[_0x5f08fc];return _0x41e94d;};'use strict';var emlformat=require(_0x7b1b('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x7b1b('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x7b1b('0x2'));var BPromise=require(_0x7b1b('0x3'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x7b1b('0x4'));var csv=require(_0x7b1b('0x5'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x7b1b('0x6'));var _=require('lodash');var squel=require(_0x7b1b('0x7'));var crypto=require('crypto');var jsforce=require(_0x7b1b('0x8'));var deskjs=require(_0x7b1b('0x9'));var toCsv=require('to-csv');var querystring=require(_0x7b1b('0xa'));var Papa=require(_0x7b1b('0xb'));var Redis=require(_0x7b1b('0xc'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x7b1b('0xd'));var hardwareService=require(_0x7b1b('0xe'));var logger=require(_0x7b1b('0xf'))('api');var utils=require('../../config/utils');var config=require(_0x7b1b('0x10'));var licenseUtil=require(_0x7b1b('0x11'));var db=require(_0x7b1b('0x12'))['db'];function respondWithStatusCode(_0x577067,_0x3acdc0){_0x3acdc0=_0x3acdc0||0xcc;return function(_0x21a081){if(_0x21a081){return _0x577067[_0x7b1b('0x13')](_0x3acdc0);}return _0x577067[_0x7b1b('0x14')](_0x3acdc0)['end']();};}function respondWithResult(_0x27b99d,_0x27f521){_0x27f521=_0x27f521||0xc8;return function(_0x56f839){if(_0x56f839){return _0x27b99d[_0x7b1b('0x14')](_0x27f521)[_0x7b1b('0x15')](_0x56f839);}};}function respondWithFilteredResult(_0x33e07f,_0x26c01d){return function(_0x1a3b0a){if(_0x1a3b0a){var _0x365081=typeof _0x26c01d['offset']===_0x7b1b('0x16')&&typeof _0x26c01d[_0x7b1b('0x17')]===_0x7b1b('0x16');var _0x1a7e2d=_0x1a3b0a[_0x7b1b('0x18')];var _0x11c927=_0x365081?0x0:_0x26c01d[_0x7b1b('0x19')];var _0x306b24=_0x365081?_0x1a3b0a[_0x7b1b('0x18')]:_0x26c01d['offset']+_0x26c01d[_0x7b1b('0x17')];var _0x288042;if(_0x306b24>=_0x1a7e2d){_0x306b24=_0x1a7e2d;_0x288042=0xc8;}else{_0x288042=0xce;}_0x33e07f[_0x7b1b('0x14')](_0x288042);return _0x33e07f['set'](_0x7b1b('0x1a'),_0x11c927+'-'+_0x306b24+'/'+_0x1a7e2d)[_0x7b1b('0x15')](_0x1a3b0a);}return null;};}function patchUpdates(_0x312cba){return function(_0x1a05b6){try{jsonpatch['apply'](_0x1a05b6,_0x312cba,!![]);}catch(_0x5b8569){return BPromise['reject'](_0x5b8569);}return _0x1a05b6[_0x7b1b('0x1b')]();};}function saveUpdates(_0x5af643,_0x5e72f7){return function(_0x201d91){if(_0x201d91){return _0x201d91[_0x7b1b('0x1c')](_0x5af643)[_0x7b1b('0x1d')](function(_0xf3b7e7){return _0xf3b7e7;});}return null;};}function removeEntity(_0x3a9c20,_0x4b7237){return function(_0x241044){if(_0x241044){return _0x241044[_0x7b1b('0x1e')]()[_0x7b1b('0x1d')](function(){_0x3a9c20[_0x7b1b('0x14')](0xcc)[_0x7b1b('0x1f')]();});}};}function handleEntityNotFound(_0x549429,_0x5b7f44){return function(_0x2535e5){if(!_0x2535e5){_0x549429[_0x7b1b('0x13')](0x194);}return _0x2535e5;};}function handleError(_0x15c77a,_0x27bb75){_0x27bb75=_0x27bb75||0x1f4;return function(_0x21621c){logger[_0x7b1b('0x20')](_0x21621c[_0x7b1b('0x21')]);if(_0x21621c[_0x7b1b('0x22')]){delete _0x21621c['name'];}_0x15c77a[_0x7b1b('0x14')](_0x27bb75)[_0x7b1b('0x23')](_0x21621c);};}exports[_0x7b1b('0x24')]=function(_0x3429c4,_0x1534b8){var _0x4f5c56={},_0x4f1edb={},_0x42d256={'count':0x0,'rows':[]};var _0x3f47f2=_[_0x7b1b('0x25')](db['UserProfileSection']['rawAttributes'],function(_0x338b78){return{'name':_0x338b78[_0x7b1b('0x26')],'type':_0x338b78[_0x7b1b('0x27')]['key']};});_0x4f1edb[_0x7b1b('0x28')]=_[_0x7b1b('0x25')](_0x3f47f2,_0x7b1b('0x22'));_0x4f1edb[_0x7b1b('0x29')]=_[_0x7b1b('0x2a')](_0x3429c4[_0x7b1b('0x29')]);_0x4f1edb[_0x7b1b('0x2b')]=_[_0x7b1b('0x2c')](_0x4f1edb[_0x7b1b('0x28')],_0x4f1edb[_0x7b1b('0x29')]);_0x4f5c56[_0x7b1b('0x2d')]=_['intersection'](_0x4f1edb[_0x7b1b('0x28')],qs[_0x7b1b('0x2e')](_0x3429c4['query'][_0x7b1b('0x2e')]));_0x4f5c56[_0x7b1b('0x2d')]=_0x4f5c56[_0x7b1b('0x2d')][_0x7b1b('0x2f')]?_0x4f5c56['attributes']:_0x4f1edb[_0x7b1b('0x28')];if(!_0x3429c4[_0x7b1b('0x29')][_0x7b1b('0x30')](_0x7b1b('0x31'))){_0x4f5c56['limit']=qs[_0x7b1b('0x17')](_0x3429c4[_0x7b1b('0x29')]['limit']);_0x4f5c56['offset']=qs[_0x7b1b('0x19')](_0x3429c4[_0x7b1b('0x29')][_0x7b1b('0x19')]);}_0x4f5c56[_0x7b1b('0x32')]=qs[_0x7b1b('0x33')](_0x3429c4[_0x7b1b('0x29')][_0x7b1b('0x33')]);_0x4f5c56[_0x7b1b('0x34')]=qs[_0x7b1b('0x2b')](_[_0x7b1b('0x35')](_0x3429c4[_0x7b1b('0x29')],_0x4f1edb[_0x7b1b('0x2b')]),_0x3f47f2);if(_0x3429c4[_0x7b1b('0x29')][_0x7b1b('0x36')]){_0x4f5c56[_0x7b1b('0x34')]=_[_0x7b1b('0x37')](_0x4f5c56[_0x7b1b('0x34')],{'$or':_[_0x7b1b('0x25')](_0x3f47f2,function(_0x5ded2a){if(_0x5ded2a[_0x7b1b('0x27')]!=='VIRTUAL'){var _0x4d865b={};_0x4d865b[_0x5ded2a[_0x7b1b('0x22')]]={'$like':'%'+_0x3429c4[_0x7b1b('0x29')][_0x7b1b('0x36')]+'%'};return _0x4d865b;}})});}_0x4f5c56=_[_0x7b1b('0x37')]({},_0x4f5c56,_0x3429c4['options']);var _0x11961e={'where':_0x4f5c56[_0x7b1b('0x34')]};return db[_0x7b1b('0x38')][_0x7b1b('0x18')](_0x11961e)[_0x7b1b('0x1d')](function(_0x44720a){_0x42d256['count']=_0x44720a;if(_0x3429c4[_0x7b1b('0x29')][_0x7b1b('0x39')]){_0x4f5c56[_0x7b1b('0x3a')]=[{'all':!![]}];}return db[_0x7b1b('0x38')][_0x7b1b('0x3b')](_0x4f5c56);})[_0x7b1b('0x1d')](function(_0x21d51f){_0x42d256[_0x7b1b('0x3c')]=_0x21d51f;return _0x42d256;})['then'](respondWithFilteredResult(_0x1534b8,_0x4f5c56))[_0x7b1b('0x3d')](handleError(_0x1534b8,null));};exports[_0x7b1b('0x3e')]=function(_0x596263,_0x338419){var _0x1834d6={'raw':![],'where':{'id':_0x596263[_0x7b1b('0x3f')]['id']}},_0x61d7f6={};_0x61d7f6[_0x7b1b('0x28')]=_[_0x7b1b('0x2a')](db[_0x7b1b('0x38')][_0x7b1b('0x40')]);_0x61d7f6[_0x7b1b('0x29')]=_[_0x7b1b('0x2a')](_0x596263[_0x7b1b('0x29')]);_0x61d7f6[_0x7b1b('0x2b')]=_['intersection'](_0x61d7f6['model'],_0x61d7f6[_0x7b1b('0x29')]);_0x1834d6['attributes']=_[_0x7b1b('0x2c')](_0x61d7f6[_0x7b1b('0x28')],qs[_0x7b1b('0x2e')](_0x596263[_0x7b1b('0x29')]['fields']));_0x1834d6['attributes']=_0x1834d6[_0x7b1b('0x2d')][_0x7b1b('0x2f')]?_0x1834d6[_0x7b1b('0x2d')]:_0x61d7f6[_0x7b1b('0x28')];if(_0x596263['query']['includeAll']){_0x1834d6['include']=[{'all':!![]}];}_0x1834d6=_[_0x7b1b('0x37')]({},_0x1834d6,_0x596263[_0x7b1b('0x41')]);return db[_0x7b1b('0x38')][_0x7b1b('0x42')](_0x1834d6)[_0x7b1b('0x1d')](handleEntityNotFound(_0x338419,null))[_0x7b1b('0x1d')](respondWithResult(_0x338419,null))[_0x7b1b('0x3d')](handleError(_0x338419,null));};exports[_0x7b1b('0x43')]=function(_0x56fde8,_0x4867a0){return db['UserProfileSection']['create'](_0x56fde8['body'],{})['then'](respondWithResult(_0x4867a0,0xc9))[_0x7b1b('0x3d')](handleError(_0x4867a0,null));};exports['update']=function(_0x3ba0d0,_0x365922){if(_0x3ba0d0['body']['id']){delete _0x3ba0d0[_0x7b1b('0x44')]['id'];}return db['UserProfileSection']['find']({'where':{'id':_0x3ba0d0['params']['id']}})[_0x7b1b('0x1d')](handleEntityNotFound(_0x365922,null))[_0x7b1b('0x1d')](saveUpdates(_0x3ba0d0['body'],null))['then'](respondWithResult(_0x365922,null))[_0x7b1b('0x3d')](handleError(_0x365922,null));};exports[_0x7b1b('0x1e')]=function(_0x502e82,_0x91c199){return db[_0x7b1b('0x38')][_0x7b1b('0x42')]({'where':{'id':_0x502e82[_0x7b1b('0x3f')]['id']}})[_0x7b1b('0x1d')](handleEntityNotFound(_0x91c199,null))[_0x7b1b('0x1d')](removeEntity(_0x91c199,null))[_0x7b1b('0x3d')](handleError(_0x91c199,null));};exports[_0x7b1b('0x45')]=function(_0x37b9e0,_0x5f1bc3){return db[_0x7b1b('0x38')][_0x7b1b('0x45')]()['then'](respondWithResult(_0x5f1bc3,null))[_0x7b1b('0x3d')](handleError(_0x5f1bc3,null));};