Built motion from commit (unavailable).|2.5.15
[motion2.git] / server / api / tag / tag.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 _0xf569=['error','stack','name','index','map','Tag','fieldName','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','filter','merge','type','then','includeAll','include','rows','catch','params','rawAttributes','options','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','Tags','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','to-csv','ejs','lodash','squel','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/license/util','../../mysqldb','end','json','count','offset','limit','set','apply','save','update','get','UserProfileResource','destroy','status','sendStatus'];(function(_0x176259,_0x30e46f){var _0x48dc40=function(_0x3aa524){while(--_0x3aa524){_0x176259['push'](_0x176259['shift']());}};_0x48dc40(++_0x30e46f);}(_0xf569,0xbc));var _0x9f56=function(_0x35da42,_0x5c2610){_0x35da42=_0x35da42-0x0;var _0x370035=_0xf569[_0x35da42];return _0x370035;};'use strict';var pdf=require(_0x9f56('0x0'));var emlformat=require(_0x9f56('0x1'));var rimraf=require(_0x9f56('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9f56('0x3'));var rp=require(_0x9f56('0x4'));var moment=require(_0x9f56('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x9f56('0x6'));var util=require(_0x9f56('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x9f56('0x8'));var ejs=require(_0x9f56('0x9'));var fs=require('fs');var _=require(_0x9f56('0xa'));var squel=require(_0x9f56('0xb'));var crypto=require(_0x9f56('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x9f56('0xd'));var Papa=require(_0x9f56('0xe'));var Redis=require(_0x9f56('0xf'));var authService=require(_0x9f56('0x10'));var qs=require(_0x9f56('0x11'));var as=require(_0x9f56('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x9f56('0x13'))(_0x9f56('0x14'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x9f56('0x15'));var db=require(_0x9f56('0x16'))['db'];function respondWithStatusCode(_0x121479,_0x264505){_0x264505=_0x264505||0xcc;return function(_0x3b5e5a){if(_0x3b5e5a){return _0x121479['sendStatus'](_0x264505);}return _0x121479['status'](_0x264505)[_0x9f56('0x17')]();};}function respondWithResult(_0xd0cc27,_0x3b17b2){_0x3b17b2=_0x3b17b2||0xc8;return function(_0x26a530){if(_0x26a530){return _0xd0cc27['status'](_0x3b17b2)[_0x9f56('0x18')](_0x26a530);}};}function respondWithFilteredResult(_0x13c153,_0x191293){return function(_0x4f51c0){if(_0x4f51c0){var _0x16dc91=_0x4f51c0[_0x9f56('0x19')],_0xd1fd49=_0x191293[_0x9f56('0x1a')],_0x55fc65=_0x191293['offset']+_0x191293[_0x9f56('0x1b')],_0x98411d;if(_0x55fc65>=_0x16dc91){_0x55fc65=_0x16dc91;_0x98411d=0xc8;}else{_0x98411d=0xce;}_0x13c153['status'](_0x98411d);return _0x13c153[_0x9f56('0x1c')]('Content-Range',_0xd1fd49+'-'+_0x55fc65+'/'+_0x16dc91)[_0x9f56('0x18')](_0x4f51c0);}return null;};}function patchUpdates(_0x4ec6e4){return function(_0x1382d9){try{jsonpatch[_0x9f56('0x1d')](_0x1382d9,_0x4ec6e4,!![]);}catch(_0x1e6731){return BPromise['reject'](_0x1e6731);}return _0x1382d9[_0x9f56('0x1e')]();};}function saveUpdates(_0x50ae92,_0x3beaae){return function(_0x3ad414){if(_0x3ad414){return _0x3ad414[_0x9f56('0x1f')](_0x50ae92)['then'](function(_0x23abc8){return _0x23abc8;});}return null;};}function removeEntity(_0x19410f,_0x20ef8f){return function(_0x493330){if(_0x493330){return _0x493330['destroy']()['then'](function(){var _0x1a1e07=_0x493330[_0x9f56('0x20')]({'plain':!![]});var _0x5596cd='Tags';return db[_0x9f56('0x21')][_0x9f56('0x22')]({'where':{'type':_0x5596cd,'resourceId':_0x1a1e07['id']}})['then'](function(){return _0x493330;});})['then'](function(){_0x19410f[_0x9f56('0x23')](0xcc)['end']();});}};}function handleEntityNotFound(_0x206762,_0x1f8bac){return function(_0x489671){if(!_0x489671){_0x206762[_0x9f56('0x24')](0x194);}return _0x489671;};}function handleError(_0x3d3145,_0x41de12){_0x41de12=_0x41de12||0x1f4;return function(_0x445f7d){logger[_0x9f56('0x25')](_0x445f7d[_0x9f56('0x26')]);if(_0x445f7d['name']){delete _0x445f7d[_0x9f56('0x27')];}_0x3d3145[_0x9f56('0x23')](_0x41de12)['send'](_0x445f7d);};}exports[_0x9f56('0x28')]=function(_0x13058d,_0x4bd202){var _0x29922e={},_0x2dca0d={},_0x283b7a={'count':0x0,'rows':[]};var _0x1345e8=_[_0x9f56('0x29')](db[_0x9f56('0x2a')]['rawAttributes'],function(_0x35caa8){return{'name':_0x35caa8[_0x9f56('0x2b')],'type':_0x35caa8['type']['key']};});_0x2dca0d[_0x9f56('0x2c')]=_[_0x9f56('0x29')](_0x1345e8,_0x9f56('0x27'));_0x2dca0d[_0x9f56('0x2d')]=_[_0x9f56('0x2e')](_0x13058d[_0x9f56('0x2d')]);_0x2dca0d[_0x9f56('0x2f')]=_[_0x9f56('0x30')](_0x2dca0d['model'],_0x2dca0d[_0x9f56('0x2d')]);_0x29922e[_0x9f56('0x31')]=_[_0x9f56('0x30')](_0x2dca0d['model'],qs[_0x9f56('0x32')](_0x13058d[_0x9f56('0x2d')][_0x9f56('0x32')]));_0x29922e[_0x9f56('0x31')]=_0x29922e[_0x9f56('0x31')][_0x9f56('0x33')]?_0x29922e[_0x9f56('0x31')]:_0x2dca0d[_0x9f56('0x2c')];if(!_0x13058d['query'][_0x9f56('0x34')]('nolimit')){_0x29922e['limit']=qs[_0x9f56('0x1b')](_0x13058d[_0x9f56('0x2d')][_0x9f56('0x1b')]);_0x29922e[_0x9f56('0x1a')]=qs[_0x9f56('0x1a')](_0x13058d[_0x9f56('0x2d')][_0x9f56('0x1a')]);}_0x29922e['order']=qs['sort'](_0x13058d['query'][_0x9f56('0x35')]);_0x29922e[_0x9f56('0x36')]=qs[_0x9f56('0x2f')](_['pick'](_0x13058d['query'],_0x2dca0d[_0x9f56('0x2f')]),_0x1345e8);if(_0x13058d['query'][_0x9f56('0x37')]){_0x29922e[_0x9f56('0x36')]=_[_0x9f56('0x38')](_0x29922e['where'],{'$or':_[_0x9f56('0x29')](_0x1345e8,function(_0x14d215){if(_0x14d215[_0x9f56('0x39')]!=='VIRTUAL'){var _0x4b26d9={};_0x4b26d9[_0x14d215[_0x9f56('0x27')]]={'$like':'%'+_0x13058d[_0x9f56('0x2d')][_0x9f56('0x37')]+'%'};return _0x4b26d9;}})});}_0x29922e=_[_0x9f56('0x38')]({},_0x29922e,_0x13058d['options']);var _0x3724cb={'where':_0x29922e[_0x9f56('0x36')]};return db[_0x9f56('0x2a')][_0x9f56('0x19')](_0x3724cb)[_0x9f56('0x3a')](function(_0x5b23a4){_0x283b7a[_0x9f56('0x19')]=_0x5b23a4;if(_0x13058d[_0x9f56('0x2d')][_0x9f56('0x3b')]){_0x29922e[_0x9f56('0x3c')]=[{'all':!![]}];}return db[_0x9f56('0x2a')]['findAll'](_0x29922e);})[_0x9f56('0x3a')](function(_0x487078){_0x283b7a[_0x9f56('0x3d')]=_0x487078;return _0x283b7a;})[_0x9f56('0x3a')](respondWithFilteredResult(_0x4bd202,_0x29922e))[_0x9f56('0x3e')](handleError(_0x4bd202,null));};exports['show']=function(_0x3925da,_0x1a2a9b){var _0x1b7e0e={'raw':!![],'where':{'id':_0x3925da[_0x9f56('0x3f')]['id']}},_0x288919={};_0x288919['model']=_[_0x9f56('0x2e')](db[_0x9f56('0x2a')][_0x9f56('0x40')]);_0x288919[_0x9f56('0x2d')]=_[_0x9f56('0x2e')](_0x3925da['query']);_0x288919[_0x9f56('0x2f')]=_[_0x9f56('0x30')](_0x288919[_0x9f56('0x2c')],_0x288919[_0x9f56('0x2d')]);_0x1b7e0e[_0x9f56('0x31')]=_['intersection'](_0x288919[_0x9f56('0x2c')],qs[_0x9f56('0x32')](_0x3925da[_0x9f56('0x2d')][_0x9f56('0x32')]));_0x1b7e0e['attributes']=_0x1b7e0e[_0x9f56('0x31')][_0x9f56('0x33')]?_0x1b7e0e['attributes']:_0x288919[_0x9f56('0x2c')];if(_0x3925da[_0x9f56('0x2d')][_0x9f56('0x3b')]){_0x1b7e0e[_0x9f56('0x3c')]=[{'all':!![]}];}_0x1b7e0e=_[_0x9f56('0x38')]({},_0x1b7e0e,_0x3925da[_0x9f56('0x41')]);return db[_0x9f56('0x2a')][_0x9f56('0x42')](_0x1b7e0e)[_0x9f56('0x3a')](handleEntityNotFound(_0x1a2a9b,null))['then'](respondWithResult(_0x1a2a9b,null))[_0x9f56('0x3e')](handleError(_0x1a2a9b,null));};exports[_0x9f56('0x43')]=function(_0x398508,_0x56e666){return db['Tag'][_0x9f56('0x43')](_0x398508['body'],{})[_0x9f56('0x3a')](function(_0x15217e){var _0x48417e=_0x398508[_0x9f56('0x44')][_0x9f56('0x20')]({'plain':!![]});if(!_0x48417e)throw new Error(_0x9f56('0x45'));if(_0x48417e['role']==='user'){var _0x4925da=_0x15217e[_0x9f56('0x20')]({'plain':!![]});var _0x5190de=_0x9f56('0x46');return db[_0x9f56('0x47')][_0x9f56('0x42')]({'where':{'name':_0x5190de,'userProfileId':_0x48417e[_0x9f56('0x48')]},'raw':!![]})['then'](function(_0x510460){if(_0x510460&&_0x510460['autoAssociation']===0x0){return db[_0x9f56('0x21')][_0x9f56('0x43')]({'name':_0x4925da[_0x9f56('0x27')],'resourceId':_0x4925da['id'],'type':_0x510460[_0x9f56('0x27')],'sectionId':_0x510460['id']},{})[_0x9f56('0x3a')](function(){return _0x15217e;});}else{return _0x15217e;}})[_0x9f56('0x3e')](function(_0x34613c){logger[_0x9f56('0x25')](_0x9f56('0x49'),_0x34613c);throw _0x34613c;});}return _0x15217e;})[_0x9f56('0x3a')](respondWithResult(_0x56e666,0xc9))['catch'](handleError(_0x56e666,null));};exports[_0x9f56('0x1f')]=function(_0x4e0dc2,_0x48d24f){if(_0x4e0dc2['body']['id']){delete _0x4e0dc2[_0x9f56('0x4a')]['id'];}return db['Tag'][_0x9f56('0x42')]({'where':{'id':_0x4e0dc2['params']['id']}})['then'](handleEntityNotFound(_0x48d24f,null))[_0x9f56('0x3a')](saveUpdates(_0x4e0dc2[_0x9f56('0x4a')],null))[_0x9f56('0x3a')](respondWithResult(_0x48d24f,null))['catch'](handleError(_0x48d24f,null));};exports[_0x9f56('0x22')]=function(_0x443370,_0x4f1ba1){return db['Tag']['find']({'where':{'id':_0x443370['params']['id']}})[_0x9f56('0x3a')](handleEntityNotFound(_0x4f1ba1,null))[_0x9f56('0x3a')](removeEntity(_0x4f1ba1,null))[_0x9f56('0x3e')](handleError(_0x4f1ba1,null));};