Built motion from commit (unavailable).|2.4.4
[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 _0x053f=['sendStatus','end','status','json','count','offset','limit','set','Content-Range','reject','save','update','then','destroy','Tags','UserProfileResource','name','send','model','keys','query','filters','intersection','attributes','fields','length','order','sort','where','filter','merge','type','key','field','Tag','includeAll','include','rows','params','rawAttributes','options','find','catch','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','rimraf','zip-dir','fast-json-patch','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','api','../../config/utils'];(function(_0x4d4b14,_0x159755){var _0x400a89=function(_0x3186d4){while(--_0x3186d4){_0x4d4b14['push'](_0x4d4b14['shift']());}};_0x400a89(++_0x159755);}(_0x053f,0x7d));var _0xf053=function(_0x47bb71,_0x4da94f){_0x47bb71=_0x47bb71-0x0;var _0x46005c=_0x053f[_0x47bb71];return _0x46005c;};'use strict';var pdf=require(_0xf053('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xf053('0x1'));var zipdir=require(_0xf053('0x2'));var jsonpatch=require(_0xf053('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf053('0x4'));var util=require(_0xf053('0x5'));var path=require(_0xf053('0x6'));var sox=require(_0xf053('0x7'));var csv=require('to-csv');var ejs=require(_0xf053('0x8'));var fs=require('fs');var _=require(_0xf053('0x9'));var squel=require(_0xf053('0xa'));var crypto=require(_0xf053('0xb'));var jsforce=require(_0xf053('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xf053('0xd'));var querystring=require(_0xf053('0xe'));var Papa=require(_0xf053('0xf'));var Redis=require(_0xf053('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf053('0x11'));var utils=require(_0xf053('0x12'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5f2a0c,_0x4bd8ba){_0x4bd8ba=_0x4bd8ba||0xcc;return function(_0x3b40d2){if(_0x3b40d2){return _0x5f2a0c[_0xf053('0x13')](_0x4bd8ba);}return _0x5f2a0c['status'](_0x4bd8ba)[_0xf053('0x14')]();};}function respondWithResult(_0x15d94c,_0x1e6711){_0x1e6711=_0x1e6711||0xc8;return function(_0x573b4c){if(_0x573b4c){return _0x15d94c[_0xf053('0x15')](_0x1e6711)[_0xf053('0x16')](_0x573b4c);}};}function respondWithFilteredResult(_0x188464,_0x114f63){return function(_0x4688ae){if(_0x4688ae){var _0x2a798a=_0x4688ae[_0xf053('0x17')],_0x3204c2=_0x114f63[_0xf053('0x18')],_0x5e97f6=_0x114f63[_0xf053('0x18')]+_0x114f63[_0xf053('0x19')],_0x1aab71;if(_0x5e97f6>=_0x2a798a){_0x5e97f6=_0x2a798a;_0x1aab71=0xc8;}else{_0x1aab71=0xce;}_0x188464['status'](_0x1aab71);return _0x188464[_0xf053('0x1a')](_0xf053('0x1b'),_0x3204c2+'-'+_0x5e97f6+'/'+_0x2a798a)['json'](_0x4688ae);}return null;};}function patchUpdates(_0x2b6efa){return function(_0x5b0bd7){try{jsonpatch['apply'](_0x5b0bd7,_0x2b6efa,!![]);}catch(_0xf1bf25){return BPromise[_0xf053('0x1c')](_0xf1bf25);}return _0x5b0bd7[_0xf053('0x1d')]();};}function saveUpdates(_0x13d3a9,_0xcdb29a){return function(_0x3901b0){if(_0x3901b0){return _0x3901b0[_0xf053('0x1e')](_0x13d3a9)[_0xf053('0x1f')](function(_0x3abe34){return _0x3abe34;});}return null;};}function removeEntity(_0x11b3d,_0x1fbf35){return function(_0x179dcc){if(_0x179dcc){return _0x179dcc[_0xf053('0x20')]()[_0xf053('0x1f')](function(){var _0x45c3e0=_0x179dcc['get']({'plain':!![]});var _0x378c1a=_0xf053('0x21');return db[_0xf053('0x22')]['destroy']({'where':{'type':_0x378c1a,'resourceId':_0x45c3e0['id']}})[_0xf053('0x1f')](function(){return _0x179dcc;});})['then'](function(){_0x11b3d[_0xf053('0x15')](0xcc)[_0xf053('0x14')]();});}};}function handleEntityNotFound(_0x2f8813,_0x23adc9){return function(_0x23bc0a){if(!_0x23bc0a){_0x2f8813[_0xf053('0x13')](0x194);}return _0x23bc0a;};}function handleError(_0x2d6e50,_0x247484){_0x247484=_0x247484||0x1f4;return function(_0x24f86f){logger['error'](_0x24f86f['stack']);if(_0x24f86f['name']){delete _0x24f86f[_0xf053('0x23')];}_0x2d6e50[_0xf053('0x15')](_0x247484)[_0xf053('0x24')](_0x24f86f);};}exports['index']=function(_0x108d3f,_0x206878){var _0x2bdad4={},_0x131021={},_0x44cdf7={'count':0x0,'rows':[]};var _0x5d728d=db['Tag']['rawAttributes'];_0x131021[_0xf053('0x25')]=_[_0xf053('0x26')](_0x5d728d);_0x131021[_0xf053('0x27')]=_[_0xf053('0x26')](_0x108d3f[_0xf053('0x27')]);_0x131021[_0xf053('0x28')]=_[_0xf053('0x29')](_0x131021[_0xf053('0x25')],_0x131021[_0xf053('0x27')]);_0x2bdad4[_0xf053('0x2a')]=_[_0xf053('0x29')](_0x131021[_0xf053('0x25')],qs['fields'](_0x108d3f[_0xf053('0x27')][_0xf053('0x2b')]));_0x2bdad4[_0xf053('0x2a')]=_0x2bdad4[_0xf053('0x2a')][_0xf053('0x2c')]?_0x2bdad4[_0xf053('0x2a')]:_0x131021[_0xf053('0x25')];if(!_0x108d3f['query']['hasOwnProperty']('nolimit')){_0x2bdad4[_0xf053('0x19')]=qs['limit'](_0x108d3f['query'][_0xf053('0x19')]);_0x2bdad4['offset']=qs[_0xf053('0x18')](_0x108d3f[_0xf053('0x27')]['offset']);}_0x2bdad4[_0xf053('0x2d')]=qs[_0xf053('0x2e')](_0x108d3f['query']['sort']);_0x2bdad4[_0xf053('0x2f')]=qs[_0xf053('0x28')](_['pick'](_0x108d3f[_0xf053('0x27')],_0x131021[_0xf053('0x28')]));if(_0x108d3f[_0xf053('0x27')][_0xf053('0x30')]){_0x2bdad4[_0xf053('0x2f')]=_[_0xf053('0x31')](_0x2bdad4[_0xf053('0x2f')],{'$or':_['map'](_0x5d728d,function(_0x62d308){if(_0x62d308[_0xf053('0x32')][_0xf053('0x33')]!=='VIRTUAL'){var _0x3f4c47={};_0x3f4c47[_0x62d308[_0xf053('0x34')]]={'$like':'%'+_0x108d3f[_0xf053('0x27')]['filter']+'%'};return _0x3f4c47;}})});}_0x2bdad4=_['merge']({},_0x2bdad4,_0x108d3f['options']);var _0x5de38b={'where':_0x2bdad4[_0xf053('0x2f')]};return db[_0xf053('0x35')][_0xf053('0x17')](_0x5de38b)[_0xf053('0x1f')](function(_0x479104){_0x44cdf7[_0xf053('0x17')]=_0x479104;if(_0x108d3f['query'][_0xf053('0x36')]){_0x2bdad4[_0xf053('0x37')]=[{'all':!![]}];}return db[_0xf053('0x35')]['findAll'](_0x2bdad4);})[_0xf053('0x1f')](function(_0x3bf2fb){_0x44cdf7[_0xf053('0x38')]=_0x3bf2fb;return _0x44cdf7;})[_0xf053('0x1f')](respondWithFilteredResult(_0x206878,_0x2bdad4))['catch'](handleError(_0x206878,null));};exports['show']=function(_0x261c34,_0x5332b4){var _0x3f60ec={'raw':!![],'where':{'id':_0x261c34[_0xf053('0x39')]['id']}},_0x4c7d0c={};_0x4c7d0c[_0xf053('0x25')]=_['keys'](db[_0xf053('0x35')][_0xf053('0x3a')]);_0x4c7d0c[_0xf053('0x27')]=_[_0xf053('0x26')](_0x261c34['query']);_0x4c7d0c[_0xf053('0x28')]=_['intersection'](_0x4c7d0c['model'],_0x4c7d0c['query']);_0x3f60ec[_0xf053('0x2a')]=_[_0xf053('0x29')](_0x4c7d0c[_0xf053('0x25')],qs[_0xf053('0x2b')](_0x261c34['query']['fields']));_0x3f60ec[_0xf053('0x2a')]=_0x3f60ec[_0xf053('0x2a')][_0xf053('0x2c')]?_0x3f60ec[_0xf053('0x2a')]:_0x4c7d0c[_0xf053('0x25')];if(_0x261c34['query'][_0xf053('0x36')]){_0x3f60ec[_0xf053('0x37')]=[{'all':!![]}];}_0x3f60ec=_[_0xf053('0x31')]({},_0x3f60ec,_0x261c34[_0xf053('0x3b')]);return db[_0xf053('0x35')][_0xf053('0x3c')](_0x3f60ec)[_0xf053('0x1f')](handleEntityNotFound(_0x5332b4,null))[_0xf053('0x1f')](respondWithResult(_0x5332b4,null))[_0xf053('0x3d')](handleError(_0x5332b4,null));};exports[_0xf053('0x3e')]=function(_0x5084cd,_0x235358){return db['Tag'][_0xf053('0x3e')](_0x5084cd[_0xf053('0x3f')],{})['then'](function(_0xcf1b33){var _0x216118=_0x5084cd[_0xf053('0x40')][_0xf053('0x41')]({'plain':!![]});if(!_0x216118)throw new Error(_0xf053('0x42'));if(_0x216118[_0xf053('0x43')]===_0xf053('0x40')){var _0x277239=_0xcf1b33[_0xf053('0x41')]({'plain':!![]});var _0x414477=_0xf053('0x21');return db[_0xf053('0x44')][_0xf053('0x3c')]({'where':{'name':_0x414477,'userProfileId':_0x216118[_0xf053('0x45')]},'raw':!![]})[_0xf053('0x1f')](function(_0x2df0a2){if(_0x2df0a2&&_0x2df0a2['autoAssociation']===0x0){return db[_0xf053('0x22')][_0xf053('0x3e')]({'name':_0x277239[_0xf053('0x23')],'resourceId':_0x277239['id'],'type':_0x2df0a2[_0xf053('0x23')],'sectionId':_0x2df0a2['id']},{})[_0xf053('0x1f')](function(){return _0xcf1b33;});}else{return _0xcf1b33;}})['catch'](function(_0x265e00){logger[_0xf053('0x46')](_0xf053('0x47'),_0x265e00);throw _0x265e00;});}return _0xcf1b33;})[_0xf053('0x1f')](respondWithResult(_0x235358,0xc9))[_0xf053('0x3d')](handleError(_0x235358,null));};exports[_0xf053('0x1e')]=function(_0x342cde,_0x2ebdcb){if(_0x342cde['body']['id']){delete _0x342cde[_0xf053('0x3f')]['id'];}return db[_0xf053('0x35')][_0xf053('0x3c')]({'where':{'id':_0x342cde['params']['id']}})[_0xf053('0x1f')](handleEntityNotFound(_0x2ebdcb,null))[_0xf053('0x1f')](saveUpdates(_0x342cde[_0xf053('0x3f')],null))['then'](respondWithResult(_0x2ebdcb,null))['catch'](handleError(_0x2ebdcb,null));};exports[_0xf053('0x20')]=function(_0x5cbf21,_0x57e7d3){return db[_0xf053('0x35')][_0xf053('0x3c')]({'where':{'id':_0x5cbf21[_0xf053('0x39')]['id']}})[_0xf053('0x1f')](handleEntityNotFound(_0x57e7d3,null))[_0xf053('0x1f')](removeEntity(_0x57e7d3,null))[_0xf053('0x3d')](handleError(_0x57e7d3,null));};