Built motion from commit (unavailable).|2.5.2
[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 _0x4f2f=['zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','json','count','offset','set','Content-Range','apply','reject','save','update','destroy','then','get','Tags','UserProfileResource','end','stack','name','send','index','map','Tag','rawAttributes','key','query','intersection','model','attributes','fields','hasOwnProperty','nolimit','limit','order','sort','filters','pick','where','merge','type','VIRTUAL','filter','options','include','findAll','show','params','length','includeAll','find','create','body','role','user','UserProfileSection','userProfileId','catch','html-pdf','eml-format','rimraf'];(function(_0x2bcd23,_0x4ef510){var _0x22aeff=function(_0x2dddf4){while(--_0x2dddf4){_0x2bcd23['push'](_0x2bcd23['shift']());}};_0x22aeff(++_0x4ef510);}(_0x4f2f,0xa1));var _0xf4f2=function(_0x38ced4,_0x24263f){_0x38ced4=_0x38ced4-0x0;var _0x547c07=_0x4f2f[_0x38ced4];return _0x547c07;};'use strict';var pdf=require(_0xf4f2('0x0'));var emlformat=require(_0xf4f2('0x1'));var rimraf=require(_0xf4f2('0x2'));var zipdir=require(_0xf4f2('0x3'));var jsonpatch=require(_0xf4f2('0x4'));var rp=require('request-promise');var moment=require(_0xf4f2('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xf4f2('0x6'));var util=require(_0xf4f2('0x7'));var path=require(_0xf4f2('0x8'));var sox=require(_0xf4f2('0x9'));var csv=require(_0xf4f2('0xa'));var ejs=require(_0xf4f2('0xb'));var fs=require('fs');var _=require(_0xf4f2('0xc'));var squel=require(_0xf4f2('0xd'));var crypto=require(_0xf4f2('0xe'));var jsforce=require(_0xf4f2('0xf'));var deskjs=require(_0xf4f2('0x10'));var toCsv=require(_0xf4f2('0xa'));var querystring=require(_0xf4f2('0x11'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xf4f2('0x12'));var qs=require(_0xf4f2('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf4f2('0x14'));var logger=require(_0xf4f2('0x15'))(_0xf4f2('0x16'));var utils=require(_0xf4f2('0x17'));var config=require(_0xf4f2('0x18'));var db=require(_0xf4f2('0x19'))['db'];function respondWithStatusCode(_0x21a2c4,_0x4761fa){_0x4761fa=_0x4761fa||0xcc;return function(_0x16ed04){if(_0x16ed04){return _0x21a2c4['sendStatus'](_0x4761fa);}return _0x21a2c4[_0xf4f2('0x1a')](_0x4761fa)['end']();};}function respondWithResult(_0x4cc379,_0x917536){_0x917536=_0x917536||0xc8;return function(_0x25ffea){if(_0x25ffea){return _0x4cc379[_0xf4f2('0x1a')](_0x917536)[_0xf4f2('0x1b')](_0x25ffea);}};}function respondWithFilteredResult(_0x14c6be,_0x18e28b){return function(_0x4bf27c){if(_0x4bf27c){var _0x594ed4=_0x4bf27c[_0xf4f2('0x1c')],_0x3dd1f7=_0x18e28b[_0xf4f2('0x1d')],_0x22c5dc=_0x18e28b[_0xf4f2('0x1d')]+_0x18e28b['limit'],_0x48c3ed;if(_0x22c5dc>=_0x594ed4){_0x22c5dc=_0x594ed4;_0x48c3ed=0xc8;}else{_0x48c3ed=0xce;}_0x14c6be[_0xf4f2('0x1a')](_0x48c3ed);return _0x14c6be[_0xf4f2('0x1e')](_0xf4f2('0x1f'),_0x3dd1f7+'-'+_0x22c5dc+'/'+_0x594ed4)[_0xf4f2('0x1b')](_0x4bf27c);}return null;};}function patchUpdates(_0x2b7ecc){return function(_0x270220){try{jsonpatch[_0xf4f2('0x20')](_0x270220,_0x2b7ecc,!![]);}catch(_0x57223f){return BPromise[_0xf4f2('0x21')](_0x57223f);}return _0x270220[_0xf4f2('0x22')]();};}function saveUpdates(_0x3f9d88,_0x29b60a){return function(_0x489478){if(_0x489478){return _0x489478[_0xf4f2('0x23')](_0x3f9d88)['then'](function(_0x4af10c){return _0x4af10c;});}return null;};}function removeEntity(_0x7bd55d,_0x90dbef){return function(_0x507047){if(_0x507047){return _0x507047[_0xf4f2('0x24')]()[_0xf4f2('0x25')](function(){var _0x583723=_0x507047[_0xf4f2('0x26')]({'plain':!![]});var _0x191cee=_0xf4f2('0x27');return db[_0xf4f2('0x28')]['destroy']({'where':{'type':_0x191cee,'resourceId':_0x583723['id']}})['then'](function(){return _0x507047;});})[_0xf4f2('0x25')](function(){_0x7bd55d['status'](0xcc)[_0xf4f2('0x29')]();});}};}function handleEntityNotFound(_0x145d6e,_0xd759e4){return function(_0x56dc0f){if(!_0x56dc0f){_0x145d6e['sendStatus'](0x194);}return _0x56dc0f;};}function handleError(_0xbc81e5,_0x1c796d){_0x1c796d=_0x1c796d||0x1f4;return function(_0x2b9178){logger['error'](_0x2b9178[_0xf4f2('0x2a')]);if(_0x2b9178[_0xf4f2('0x2b')]){delete _0x2b9178[_0xf4f2('0x2b')];}_0xbc81e5[_0xf4f2('0x1a')](_0x1c796d)[_0xf4f2('0x2c')](_0x2b9178);};}exports[_0xf4f2('0x2d')]=function(_0x33c306,_0x51df30){var _0x4e72d8={},_0x2f6720={},_0xfb7739={'count':0x0,'rows':[]};var _0x33e15c=_[_0xf4f2('0x2e')](db[_0xf4f2('0x2f')][_0xf4f2('0x30')],function(_0x54a7aa){return{'name':_0x54a7aa['fieldName'],'type':_0x54a7aa['type'][_0xf4f2('0x31')]};});_0x2f6720['model']=_[_0xf4f2('0x2e')](_0x33e15c,_0xf4f2('0x2b'));_0x2f6720[_0xf4f2('0x32')]=_['keys'](_0x33c306[_0xf4f2('0x32')]);_0x2f6720['filters']=_[_0xf4f2('0x33')](_0x2f6720[_0xf4f2('0x34')],_0x2f6720['query']);_0x4e72d8[_0xf4f2('0x35')]=_[_0xf4f2('0x33')](_0x2f6720[_0xf4f2('0x34')],qs[_0xf4f2('0x36')](_0x33c306[_0xf4f2('0x32')][_0xf4f2('0x36')]));_0x4e72d8['attributes']=_0x4e72d8[_0xf4f2('0x35')]['length']?_0x4e72d8['attributes']:_0x2f6720['model'];if(!_0x33c306[_0xf4f2('0x32')][_0xf4f2('0x37')](_0xf4f2('0x38'))){_0x4e72d8[_0xf4f2('0x39')]=qs[_0xf4f2('0x39')](_0x33c306['query'][_0xf4f2('0x39')]);_0x4e72d8[_0xf4f2('0x1d')]=qs[_0xf4f2('0x1d')](_0x33c306[_0xf4f2('0x32')]['offset']);}_0x4e72d8[_0xf4f2('0x3a')]=qs[_0xf4f2('0x3b')](_0x33c306[_0xf4f2('0x32')][_0xf4f2('0x3b')]);_0x4e72d8['where']=qs[_0xf4f2('0x3c')](_[_0xf4f2('0x3d')](_0x33c306[_0xf4f2('0x32')],_0x2f6720['filters']),_0x33e15c);if(_0x33c306[_0xf4f2('0x32')]['filter']){_0x4e72d8[_0xf4f2('0x3e')]=_[_0xf4f2('0x3f')](_0x4e72d8[_0xf4f2('0x3e')],{'$or':_[_0xf4f2('0x2e')](_0x33e15c,function(_0x1c1202){if(_0x1c1202[_0xf4f2('0x40')]!==_0xf4f2('0x41')){var _0x1b1881={};_0x1b1881[_0x1c1202[_0xf4f2('0x2b')]]={'$like':'%'+_0x33c306['query'][_0xf4f2('0x42')]+'%'};return _0x1b1881;}})});}_0x4e72d8=_['merge']({},_0x4e72d8,_0x33c306[_0xf4f2('0x43')]);var _0x1c0e08={'where':_0x4e72d8[_0xf4f2('0x3e')]};return db[_0xf4f2('0x2f')]['count'](_0x1c0e08)[_0xf4f2('0x25')](function(_0x54ae89){_0xfb7739['count']=_0x54ae89;if(_0x33c306[_0xf4f2('0x32')]['includeAll']){_0x4e72d8[_0xf4f2('0x44')]=[{'all':!![]}];}return db['Tag'][_0xf4f2('0x45')](_0x4e72d8);})[_0xf4f2('0x25')](function(_0x15e5b8){_0xfb7739['rows']=_0x15e5b8;return _0xfb7739;})[_0xf4f2('0x25')](respondWithFilteredResult(_0x51df30,_0x4e72d8))['catch'](handleError(_0x51df30,null));};exports[_0xf4f2('0x46')]=function(_0x2047f4,_0x41398c){var _0xdcecbd={'raw':!![],'where':{'id':_0x2047f4[_0xf4f2('0x47')]['id']}},_0x51adf1={};_0x51adf1[_0xf4f2('0x34')]=_['keys'](db[_0xf4f2('0x2f')][_0xf4f2('0x30')]);_0x51adf1[_0xf4f2('0x32')]=_['keys'](_0x2047f4['query']);_0x51adf1[_0xf4f2('0x3c')]=_[_0xf4f2('0x33')](_0x51adf1[_0xf4f2('0x34')],_0x51adf1['query']);_0xdcecbd[_0xf4f2('0x35')]=_[_0xf4f2('0x33')](_0x51adf1[_0xf4f2('0x34')],qs[_0xf4f2('0x36')](_0x2047f4[_0xf4f2('0x32')][_0xf4f2('0x36')]));_0xdcecbd[_0xf4f2('0x35')]=_0xdcecbd[_0xf4f2('0x35')][_0xf4f2('0x48')]?_0xdcecbd[_0xf4f2('0x35')]:_0x51adf1[_0xf4f2('0x34')];if(_0x2047f4[_0xf4f2('0x32')][_0xf4f2('0x49')]){_0xdcecbd['include']=[{'all':!![]}];}_0xdcecbd=_[_0xf4f2('0x3f')]({},_0xdcecbd,_0x2047f4[_0xf4f2('0x43')]);return db['Tag'][_0xf4f2('0x4a')](_0xdcecbd)[_0xf4f2('0x25')](handleEntityNotFound(_0x41398c,null))[_0xf4f2('0x25')](respondWithResult(_0x41398c,null))['catch'](handleError(_0x41398c,null));};exports[_0xf4f2('0x4b')]=function(_0xad09ec,_0x1bdc4a){return db[_0xf4f2('0x2f')][_0xf4f2('0x4b')](_0xad09ec[_0xf4f2('0x4c')],{})[_0xf4f2('0x25')](function(_0x446466){var _0x3330b8=_0xad09ec['user']['get']({'plain':!![]});if(!_0x3330b8)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3330b8[_0xf4f2('0x4d')]===_0xf4f2('0x4e')){var _0x3965ea=_0x446466['get']({'plain':!![]});var _0x210da0=_0xf4f2('0x27');return db[_0xf4f2('0x4f')][_0xf4f2('0x4a')]({'where':{'name':_0x210da0,'userProfileId':_0x3330b8[_0xf4f2('0x50')]},'raw':!![]})[_0xf4f2('0x25')](function(_0x394f84){if(_0x394f84&&_0x394f84['autoAssociation']===0x0){return db['UserProfileResource'][_0xf4f2('0x4b')]({'name':_0x3965ea[_0xf4f2('0x2b')],'resourceId':_0x3965ea['id'],'type':_0x394f84[_0xf4f2('0x2b')],'sectionId':_0x394f84['id']},{})[_0xf4f2('0x25')](function(){return _0x446466;});}else{return _0x446466;}})[_0xf4f2('0x51')](function(_0x1e3950){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x1e3950);throw _0x1e3950;});}return _0x446466;})[_0xf4f2('0x25')](respondWithResult(_0x1bdc4a,0xc9))[_0xf4f2('0x51')](handleError(_0x1bdc4a,null));};exports['update']=function(_0x1e59e0,_0x532113){if(_0x1e59e0[_0xf4f2('0x4c')]['id']){delete _0x1e59e0[_0xf4f2('0x4c')]['id'];}return db[_0xf4f2('0x2f')][_0xf4f2('0x4a')]({'where':{'id':_0x1e59e0[_0xf4f2('0x47')]['id']}})[_0xf4f2('0x25')](handleEntityNotFound(_0x532113,null))[_0xf4f2('0x25')](saveUpdates(_0x1e59e0[_0xf4f2('0x4c')],null))[_0xf4f2('0x25')](respondWithResult(_0x532113,null))[_0xf4f2('0x51')](handleError(_0x532113,null));};exports[_0xf4f2('0x24')]=function(_0x42da62,_0x3ee43a){return db['Tag'][_0xf4f2('0x4a')]({'where':{'id':_0x42da62[_0xf4f2('0x47')]['id']}})[_0xf4f2('0x25')](handleEntityNotFound(_0x3ee43a,null))[_0xf4f2('0x25')](removeEntity(_0x3ee43a,null))[_0xf4f2('0x51')](handleError(_0x3ee43a,null));};