Built motion from commit 7ab0e143.|2.5.49
[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 _0xf403=['zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','undefined','count','offset','limit','Content-Range','apply','reject','update','then','destroy','error','name','send','index','Tag','rawAttributes','fieldName','type','model','map','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','includeAll','include','rows','catch','params','options','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format'];(function(_0x1815b7,_0x11b5cb){var _0x41a9d3=function(_0x22266d){while(--_0x22266d){_0x1815b7['push'](_0x1815b7['shift']());}};_0x41a9d3(++_0x11b5cb);}(_0xf403,0x1d3));var _0x3f40=function(_0x36198e,_0x443467){_0x36198e=_0x36198e-0x0;var _0xd148a8=_0xf403[_0x36198e];return _0xd148a8;};'use strict';var emlformat=require(_0x3f40('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3f40('0x1'));var jsonpatch=require(_0x3f40('0x2'));var rp=require(_0x3f40('0x3'));var moment=require(_0x3f40('0x4'));var BPromise=require(_0x3f40('0x5'));var Mustache=require(_0x3f40('0x6'));var util=require(_0x3f40('0x7'));var path=require(_0x3f40('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x3f40('0x9'));var fs=require('fs');var fs_extra=require(_0x3f40('0xa'));var _=require(_0x3f40('0xb'));var squel=require(_0x3f40('0xc'));var crypto=require('crypto');var jsforce=require(_0x3f40('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x3f40('0xe'));var Papa=require(_0x3f40('0xf'));var Redis=require(_0x3f40('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x3f40('0x11'));var hardwareService=require(_0x3f40('0x12'));var logger=require(_0x3f40('0x13'))('api');var utils=require(_0x3f40('0x14'));var config=require(_0x3f40('0x15'));var licenseUtil=require(_0x3f40('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x332635,_0x509c02){_0x509c02=_0x509c02||0xcc;return function(_0x116460){if(_0x116460){return _0x332635[_0x3f40('0x17')](_0x509c02);}return _0x332635[_0x3f40('0x18')](_0x509c02)[_0x3f40('0x19')]();};}function respondWithResult(_0x569c6e,_0x2b2bfe){_0x2b2bfe=_0x2b2bfe||0xc8;return function(_0x308e97){if(_0x308e97){return _0x569c6e[_0x3f40('0x18')](_0x2b2bfe)[_0x3f40('0x1a')](_0x308e97);}};}function respondWithFilteredResult(_0x232241,_0x4e28b9){return function(_0x2e51ed){if(_0x2e51ed){var _0x3d11c9=typeof _0x4e28b9['offset']==='undefined'&&typeof _0x4e28b9['limit']===_0x3f40('0x1b');var _0x13b950=_0x2e51ed[_0x3f40('0x1c')];var _0x131e55=_0x3d11c9?0x0:_0x4e28b9[_0x3f40('0x1d')];var _0x5b4ebc=_0x3d11c9?_0x2e51ed[_0x3f40('0x1c')]:_0x4e28b9[_0x3f40('0x1d')]+_0x4e28b9[_0x3f40('0x1e')];var _0x29405a;if(_0x5b4ebc>=_0x13b950){_0x5b4ebc=_0x13b950;_0x29405a=0xc8;}else{_0x29405a=0xce;}_0x232241[_0x3f40('0x18')](_0x29405a);return _0x232241['set'](_0x3f40('0x1f'),_0x131e55+'-'+_0x5b4ebc+'/'+_0x13b950)['json'](_0x2e51ed);}return null;};}function patchUpdates(_0x12aabf){return function(_0x32b945){try{jsonpatch[_0x3f40('0x20')](_0x32b945,_0x12aabf,!![]);}catch(_0x113293){return BPromise[_0x3f40('0x21')](_0x113293);}return _0x32b945['save']();};}function saveUpdates(_0x27f5a5,_0x379b4e){return function(_0x117823){if(_0x117823){return _0x117823[_0x3f40('0x22')](_0x27f5a5)[_0x3f40('0x23')](function(_0xa1f39d){return _0xa1f39d;});}return null;};}function removeEntity(_0x4e1f47,_0x31fc91){return function(_0x59eb32){if(_0x59eb32){return _0x59eb32[_0x3f40('0x24')]()['then'](function(){var _0x2bc437=_0x59eb32['get']({'plain':!![]});var _0x37b47e='Tags';return db['UserProfileResource']['destroy']({'where':{'type':_0x37b47e,'resourceId':_0x2bc437['id']}})[_0x3f40('0x23')](function(){return _0x59eb32;});})[_0x3f40('0x23')](function(){_0x4e1f47[_0x3f40('0x18')](0xcc)[_0x3f40('0x19')]();});}};}function handleEntityNotFound(_0x5b1079,_0x300665){return function(_0x47ec1c){if(!_0x47ec1c){_0x5b1079[_0x3f40('0x17')](0x194);}return _0x47ec1c;};}function handleError(_0xbaf5d4,_0xbd4333){_0xbd4333=_0xbd4333||0x1f4;return function(_0x5e0f25){logger[_0x3f40('0x25')](_0x5e0f25['stack']);if(_0x5e0f25[_0x3f40('0x26')]){delete _0x5e0f25['name'];}_0xbaf5d4['status'](_0xbd4333)[_0x3f40('0x27')](_0x5e0f25);};}exports[_0x3f40('0x28')]=function(_0x14fdfd,_0xb23186){var _0x357396={},_0x1056d0={},_0x40cd76={'count':0x0,'rows':[]};var _0xe70e64=_['map'](db[_0x3f40('0x29')][_0x3f40('0x2a')],function(_0x18dbb3){return{'name':_0x18dbb3[_0x3f40('0x2b')],'type':_0x18dbb3[_0x3f40('0x2c')]['key']};});_0x1056d0[_0x3f40('0x2d')]=_[_0x3f40('0x2e')](_0xe70e64,_0x3f40('0x26'));_0x1056d0['query']=_[_0x3f40('0x2f')](_0x14fdfd[_0x3f40('0x30')]);_0x1056d0[_0x3f40('0x31')]=_[_0x3f40('0x32')](_0x1056d0[_0x3f40('0x2d')],_0x1056d0[_0x3f40('0x30')]);_0x357396[_0x3f40('0x33')]=_[_0x3f40('0x32')](_0x1056d0[_0x3f40('0x2d')],qs[_0x3f40('0x34')](_0x14fdfd[_0x3f40('0x30')][_0x3f40('0x34')]));_0x357396[_0x3f40('0x33')]=_0x357396[_0x3f40('0x33')][_0x3f40('0x35')]?_0x357396[_0x3f40('0x33')]:_0x1056d0[_0x3f40('0x2d')];if(!_0x14fdfd[_0x3f40('0x30')][_0x3f40('0x36')](_0x3f40('0x37'))){_0x357396[_0x3f40('0x1e')]=qs[_0x3f40('0x1e')](_0x14fdfd[_0x3f40('0x30')][_0x3f40('0x1e')]);_0x357396[_0x3f40('0x1d')]=qs[_0x3f40('0x1d')](_0x14fdfd[_0x3f40('0x30')][_0x3f40('0x1d')]);}_0x357396[_0x3f40('0x38')]=qs[_0x3f40('0x39')](_0x14fdfd['query']['sort']);_0x357396[_0x3f40('0x3a')]=qs[_0x3f40('0x31')](_[_0x3f40('0x3b')](_0x14fdfd[_0x3f40('0x30')],_0x1056d0[_0x3f40('0x31')]),_0xe70e64);if(_0x14fdfd[_0x3f40('0x30')][_0x3f40('0x3c')]){_0x357396['where']=_[_0x3f40('0x3d')](_0x357396['where'],{'$or':_[_0x3f40('0x2e')](_0xe70e64,function(_0x3bec11){if(_0x3bec11[_0x3f40('0x2c')]!=='VIRTUAL'){var _0x37a83d={};_0x37a83d[_0x3bec11[_0x3f40('0x26')]]={'$like':'%'+_0x14fdfd['query'][_0x3f40('0x3c')]+'%'};return _0x37a83d;}})});}_0x357396=_[_0x3f40('0x3d')]({},_0x357396,_0x14fdfd['options']);var _0x192839={'where':_0x357396['where']};return db[_0x3f40('0x29')]['count'](_0x192839)['then'](function(_0x8e89a){_0x40cd76['count']=_0x8e89a;if(_0x14fdfd[_0x3f40('0x30')][_0x3f40('0x3e')]){_0x357396[_0x3f40('0x3f')]=[{'all':!![]}];}return db[_0x3f40('0x29')]['findAll'](_0x357396);})[_0x3f40('0x23')](function(_0x5b0eaa){_0x40cd76[_0x3f40('0x40')]=_0x5b0eaa;return _0x40cd76;})[_0x3f40('0x23')](respondWithFilteredResult(_0xb23186,_0x357396))[_0x3f40('0x41')](handleError(_0xb23186,null));};exports['show']=function(_0x4a198d,_0x21ba95){var _0xfddbd9={'raw':!![],'where':{'id':_0x4a198d[_0x3f40('0x42')]['id']}},_0x41bd93={};_0x41bd93[_0x3f40('0x2d')]=_[_0x3f40('0x2f')](db[_0x3f40('0x29')][_0x3f40('0x2a')]);_0x41bd93['query']=_[_0x3f40('0x2f')](_0x4a198d['query']);_0x41bd93['filters']=_[_0x3f40('0x32')](_0x41bd93[_0x3f40('0x2d')],_0x41bd93[_0x3f40('0x30')]);_0xfddbd9[_0x3f40('0x33')]=_[_0x3f40('0x32')](_0x41bd93[_0x3f40('0x2d')],qs[_0x3f40('0x34')](_0x4a198d[_0x3f40('0x30')][_0x3f40('0x34')]));_0xfddbd9[_0x3f40('0x33')]=_0xfddbd9[_0x3f40('0x33')][_0x3f40('0x35')]?_0xfddbd9[_0x3f40('0x33')]:_0x41bd93[_0x3f40('0x2d')];if(_0x4a198d['query'][_0x3f40('0x3e')]){_0xfddbd9['include']=[{'all':!![]}];}_0xfddbd9=_[_0x3f40('0x3d')]({},_0xfddbd9,_0x4a198d[_0x3f40('0x43')]);return db['Tag'][_0x3f40('0x44')](_0xfddbd9)[_0x3f40('0x23')](handleEntityNotFound(_0x21ba95,null))[_0x3f40('0x23')](respondWithResult(_0x21ba95,null))[_0x3f40('0x41')](handleError(_0x21ba95,null));};exports[_0x3f40('0x45')]=function(_0x268ae4,_0x851bfc){return db[_0x3f40('0x29')][_0x3f40('0x45')](_0x268ae4[_0x3f40('0x46')],{})[_0x3f40('0x23')](function(_0x364773){var _0x1cfe4f=_0x268ae4[_0x3f40('0x47')][_0x3f40('0x48')]({'plain':!![]});if(!_0x1cfe4f)throw new Error(_0x3f40('0x49'));if(_0x1cfe4f[_0x3f40('0x4a')]===_0x3f40('0x47')){var _0x32bd05=_0x364773[_0x3f40('0x48')]({'plain':!![]});var _0xca7210='Tags';return db[_0x3f40('0x4b')][_0x3f40('0x44')]({'where':{'name':_0xca7210,'userProfileId':_0x1cfe4f[_0x3f40('0x4c')]},'raw':!![]})[_0x3f40('0x23')](function(_0x3bfb89){if(_0x3bfb89&&_0x3bfb89['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0x32bd05[_0x3f40('0x26')],'resourceId':_0x32bd05['id'],'type':_0x3bfb89[_0x3f40('0x26')],'sectionId':_0x3bfb89['id']},{})['then'](function(){return _0x364773;});}else{return _0x364773;}})[_0x3f40('0x41')](function(_0x1e0af6){logger['error'](_0x3f40('0x4d'),_0x1e0af6);throw _0x1e0af6;});}return _0x364773;})['then'](respondWithResult(_0x851bfc,0xc9))[_0x3f40('0x41')](handleError(_0x851bfc,null));};exports[_0x3f40('0x22')]=function(_0x24ae66,_0x3a39c6){if(_0x24ae66[_0x3f40('0x46')]['id']){delete _0x24ae66[_0x3f40('0x46')]['id'];}return db[_0x3f40('0x29')][_0x3f40('0x44')]({'where':{'id':_0x24ae66[_0x3f40('0x42')]['id']}})[_0x3f40('0x23')](handleEntityNotFound(_0x3a39c6,null))[_0x3f40('0x23')](saveUpdates(_0x24ae66[_0x3f40('0x46')],null))[_0x3f40('0x23')](respondWithResult(_0x3a39c6,null))['catch'](handleError(_0x3a39c6,null));};exports[_0x3f40('0x24')]=function(_0x22beb7,_0x1c94a1){return db[_0x3f40('0x29')][_0x3f40('0x44')]({'where':{'id':_0x22beb7['params']['id']}})[_0x3f40('0x23')](handleEntityNotFound(_0x1c94a1,null))[_0x3f40('0x23')](removeEntity(_0x1c94a1,null))[_0x3f40('0x41')](handleError(_0x1c94a1,null));};