Built motion from commit (unavailable).|2.5.25
[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 _0x36fb=['show','params','keys','find','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','count','set','Content-Range','save','update','destroy','then','get','Tags','UserProfileResource','end','name','send','index','map','Tag','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','offset','order','sort','where','pick','filter','merge','type','options','findAll','catch'];(function(_0x78efdd,_0x3dbdde){var _0x441726=function(_0x2875a2){while(--_0x2875a2){_0x78efdd['push'](_0x78efdd['shift']());}};_0x441726(++_0x3dbdde);}(_0x36fb,0x106));var _0xb36f=function(_0x46890c,_0x5a478c){_0x46890c=_0x46890c-0x0;var _0x1b0cde=_0x36fb[_0x46890c];return _0x1b0cde;};'use strict';var pdf=require(_0xb36f('0x0'));var emlformat=require(_0xb36f('0x1'));var rimraf=require(_0xb36f('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb36f('0x3'));var rp=require(_0xb36f('0x4'));var moment=require('moment');var BPromise=require(_0xb36f('0x5'));var Mustache=require(_0xb36f('0x6'));var util=require(_0xb36f('0x7'));var path=require(_0xb36f('0x8'));var sox=require(_0xb36f('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xb36f('0xa'));var squel=require(_0xb36f('0xb'));var crypto=require(_0xb36f('0xc'));var jsforce=require(_0xb36f('0xd'));var deskjs=require(_0xb36f('0xe'));var toCsv=require(_0xb36f('0xf'));var querystring=require(_0xb36f('0x10'));var Papa=require(_0xb36f('0x11'));var Redis=require(_0xb36f('0x12'));var authService=require(_0xb36f('0x13'));var qs=require(_0xb36f('0x14'));var as=require(_0xb36f('0x15'));var hardwareService=require(_0xb36f('0x16'));var logger=require('../../config/logger')(_0xb36f('0x17'));var utils=require('../../config/utils');var config=require(_0xb36f('0x18'));var licenseUtil=require(_0xb36f('0x19'));var db=require(_0xb36f('0x1a'))['db'];function respondWithStatusCode(_0x295269,_0xc8ea74){_0xc8ea74=_0xc8ea74||0xcc;return function(_0xca069d){if(_0xca069d){return _0x295269[_0xb36f('0x1b')](_0xc8ea74);}return _0x295269[_0xb36f('0x1c')](_0xc8ea74)['end']();};}function respondWithResult(_0x4e090f,_0x43effc){_0x43effc=_0x43effc||0xc8;return function(_0x117335){if(_0x117335){return _0x4e090f['status'](_0x43effc)[_0xb36f('0x1d')](_0x117335);}};}function respondWithFilteredResult(_0x22d880,_0x351ebb){return function(_0xe02926){if(_0xe02926){var _0x323188=_0xe02926[_0xb36f('0x1e')],_0x13e075=_0x351ebb['offset'],_0x1c61a3=_0x351ebb['offset']+_0x351ebb['limit'],_0x50fca4;if(_0x1c61a3>=_0x323188){_0x1c61a3=_0x323188;_0x50fca4=0xc8;}else{_0x50fca4=0xce;}_0x22d880[_0xb36f('0x1c')](_0x50fca4);return _0x22d880[_0xb36f('0x1f')](_0xb36f('0x20'),_0x13e075+'-'+_0x1c61a3+'/'+_0x323188)[_0xb36f('0x1d')](_0xe02926);}return null;};}function patchUpdates(_0x1b392d){return function(_0x2ab3fb){try{jsonpatch['apply'](_0x2ab3fb,_0x1b392d,!![]);}catch(_0x4ebd06){return BPromise['reject'](_0x4ebd06);}return _0x2ab3fb[_0xb36f('0x21')]();};}function saveUpdates(_0x1cf62b,_0x255997){return function(_0x597c8b){if(_0x597c8b){return _0x597c8b[_0xb36f('0x22')](_0x1cf62b)['then'](function(_0x9bbdbf){return _0x9bbdbf;});}return null;};}function removeEntity(_0x2242bb,_0x52efc4){return function(_0xbf7dd6){if(_0xbf7dd6){return _0xbf7dd6[_0xb36f('0x23')]()[_0xb36f('0x24')](function(){var _0x3703c7=_0xbf7dd6[_0xb36f('0x25')]({'plain':!![]});var _0x3a05a1=_0xb36f('0x26');return db[_0xb36f('0x27')][_0xb36f('0x23')]({'where':{'type':_0x3a05a1,'resourceId':_0x3703c7['id']}})[_0xb36f('0x24')](function(){return _0xbf7dd6;});})['then'](function(){_0x2242bb[_0xb36f('0x1c')](0xcc)[_0xb36f('0x28')]();});}};}function handleEntityNotFound(_0x31153e,_0x33048d){return function(_0x4c2e27){if(!_0x4c2e27){_0x31153e[_0xb36f('0x1b')](0x194);}return _0x4c2e27;};}function handleError(_0x413b15,_0x9ce6f5){_0x9ce6f5=_0x9ce6f5||0x1f4;return function(_0x445671){logger['error'](_0x445671['stack']);if(_0x445671[_0xb36f('0x29')]){delete _0x445671[_0xb36f('0x29')];}_0x413b15['status'](_0x9ce6f5)[_0xb36f('0x2a')](_0x445671);};}exports[_0xb36f('0x2b')]=function(_0x298756,_0x314150){var _0x5059a8={},_0x28880d={},_0x27f034={'count':0x0,'rows':[]};var _0x1d76b9=_[_0xb36f('0x2c')](db[_0xb36f('0x2d')][_0xb36f('0x2e')],function(_0x348725){return{'name':_0x348725[_0xb36f('0x2f')],'type':_0x348725['type'][_0xb36f('0x30')]};});_0x28880d[_0xb36f('0x31')]=_['map'](_0x1d76b9,_0xb36f('0x29'));_0x28880d[_0xb36f('0x32')]=_['keys'](_0x298756['query']);_0x28880d[_0xb36f('0x33')]=_[_0xb36f('0x34')](_0x28880d[_0xb36f('0x31')],_0x28880d[_0xb36f('0x32')]);_0x5059a8[_0xb36f('0x35')]=_[_0xb36f('0x34')](_0x28880d[_0xb36f('0x31')],qs[_0xb36f('0x36')](_0x298756[_0xb36f('0x32')][_0xb36f('0x36')]));_0x5059a8[_0xb36f('0x35')]=_0x5059a8['attributes'][_0xb36f('0x37')]?_0x5059a8['attributes']:_0x28880d[_0xb36f('0x31')];if(!_0x298756['query'][_0xb36f('0x38')](_0xb36f('0x39'))){_0x5059a8[_0xb36f('0x3a')]=qs[_0xb36f('0x3a')](_0x298756[_0xb36f('0x32')]['limit']);_0x5059a8[_0xb36f('0x3b')]=qs[_0xb36f('0x3b')](_0x298756[_0xb36f('0x32')]['offset']);}_0x5059a8[_0xb36f('0x3c')]=qs[_0xb36f('0x3d')](_0x298756[_0xb36f('0x32')]['sort']);_0x5059a8[_0xb36f('0x3e')]=qs[_0xb36f('0x33')](_[_0xb36f('0x3f')](_0x298756[_0xb36f('0x32')],_0x28880d[_0xb36f('0x33')]),_0x1d76b9);if(_0x298756[_0xb36f('0x32')][_0xb36f('0x40')]){_0x5059a8[_0xb36f('0x3e')]=_[_0xb36f('0x41')](_0x5059a8[_0xb36f('0x3e')],{'$or':_[_0xb36f('0x2c')](_0x1d76b9,function(_0x46d3ab){if(_0x46d3ab[_0xb36f('0x42')]!=='VIRTUAL'){var _0x25df48={};_0x25df48[_0x46d3ab[_0xb36f('0x29')]]={'$like':'%'+_0x298756['query']['filter']+'%'};return _0x25df48;}})});}_0x5059a8=_[_0xb36f('0x41')]({},_0x5059a8,_0x298756[_0xb36f('0x43')]);var _0x25c112={'where':_0x5059a8[_0xb36f('0x3e')]};return db[_0xb36f('0x2d')][_0xb36f('0x1e')](_0x25c112)[_0xb36f('0x24')](function(_0x481961){_0x27f034[_0xb36f('0x1e')]=_0x481961;if(_0x298756[_0xb36f('0x32')]['includeAll']){_0x5059a8['include']=[{'all':!![]}];}return db[_0xb36f('0x2d')][_0xb36f('0x44')](_0x5059a8);})[_0xb36f('0x24')](function(_0x35036e){_0x27f034['rows']=_0x35036e;return _0x27f034;})[_0xb36f('0x24')](respondWithFilteredResult(_0x314150,_0x5059a8))[_0xb36f('0x45')](handleError(_0x314150,null));};exports[_0xb36f('0x46')]=function(_0x340beb,_0x34aeb2){var _0x11a66b={'raw':!![],'where':{'id':_0x340beb[_0xb36f('0x47')]['id']}},_0x3b133c={};_0x3b133c[_0xb36f('0x31')]=_[_0xb36f('0x48')](db[_0xb36f('0x2d')][_0xb36f('0x2e')]);_0x3b133c[_0xb36f('0x32')]=_[_0xb36f('0x48')](_0x340beb[_0xb36f('0x32')]);_0x3b133c[_0xb36f('0x33')]=_[_0xb36f('0x34')](_0x3b133c[_0xb36f('0x31')],_0x3b133c[_0xb36f('0x32')]);_0x11a66b[_0xb36f('0x35')]=_[_0xb36f('0x34')](_0x3b133c[_0xb36f('0x31')],qs[_0xb36f('0x36')](_0x340beb['query'][_0xb36f('0x36')]));_0x11a66b[_0xb36f('0x35')]=_0x11a66b[_0xb36f('0x35')][_0xb36f('0x37')]?_0x11a66b['attributes']:_0x3b133c[_0xb36f('0x31')];if(_0x340beb[_0xb36f('0x32')]['includeAll']){_0x11a66b['include']=[{'all':!![]}];}_0x11a66b=_[_0xb36f('0x41')]({},_0x11a66b,_0x340beb[_0xb36f('0x43')]);return db[_0xb36f('0x2d')][_0xb36f('0x49')](_0x11a66b)[_0xb36f('0x24')](handleEntityNotFound(_0x34aeb2,null))['then'](respondWithResult(_0x34aeb2,null))['catch'](handleError(_0x34aeb2,null));};exports[_0xb36f('0x4a')]=function(_0x180b84,_0x6d8b61){return db[_0xb36f('0x2d')][_0xb36f('0x4a')](_0x180b84[_0xb36f('0x4b')],{})[_0xb36f('0x24')](function(_0x35e82d){var _0x5c2bd4=_0x180b84[_0xb36f('0x4c')][_0xb36f('0x25')]({'plain':!![]});if(!_0x5c2bd4)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5c2bd4[_0xb36f('0x4d')]==='user'){var _0x15ddde=_0x35e82d['get']({'plain':!![]});var _0x22ebc0=_0xb36f('0x26');return db[_0xb36f('0x4e')][_0xb36f('0x49')]({'where':{'name':_0x22ebc0,'userProfileId':_0x5c2bd4[_0xb36f('0x4f')]},'raw':!![]})['then'](function(_0x47dffb){if(_0x47dffb&&_0x47dffb[_0xb36f('0x50')]===0x0){return db[_0xb36f('0x27')]['create']({'name':_0x15ddde['name'],'resourceId':_0x15ddde['id'],'type':_0x47dffb[_0xb36f('0x29')],'sectionId':_0x47dffb['id']},{})[_0xb36f('0x24')](function(){return _0x35e82d;});}else{return _0x35e82d;}})['catch'](function(_0x439342){logger[_0xb36f('0x51')](_0xb36f('0x52'),_0x439342);throw _0x439342;});}return _0x35e82d;})[_0xb36f('0x24')](respondWithResult(_0x6d8b61,0xc9))[_0xb36f('0x45')](handleError(_0x6d8b61,null));};exports[_0xb36f('0x22')]=function(_0x5569f1,_0x10de0a){if(_0x5569f1[_0xb36f('0x4b')]['id']){delete _0x5569f1['body']['id'];}return db[_0xb36f('0x2d')][_0xb36f('0x49')]({'where':{'id':_0x5569f1[_0xb36f('0x47')]['id']}})[_0xb36f('0x24')](handleEntityNotFound(_0x10de0a,null))[_0xb36f('0x24')](saveUpdates(_0x5569f1[_0xb36f('0x4b')],null))['then'](respondWithResult(_0x10de0a,null))[_0xb36f('0x45')](handleError(_0x10de0a,null));};exports[_0xb36f('0x23')]=function(_0x4fe390,_0x1fef87){return db[_0xb36f('0x2d')][_0xb36f('0x49')]({'where':{'id':_0x4fe390[_0xb36f('0x47')]['id']}})['then'](handleEntityNotFound(_0x1fef87,null))[_0xb36f('0x24')](removeEntity(_0x1fef87,null))['catch'](handleError(_0x1fef87,null));};