Built motion from commit (unavailable).|2.5.3
[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 _0x0cdb=['model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','pick','filter','merge','where','VIRTUAL','findAll','rows','catch','show','params','options','find','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','zip-dir','request-promise','moment','bluebird','util','path','ejs','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','sendStatus','end','status','json','count','offset','limit','Content-Range','apply','reject','save','update','then','destroy','get','Tags','UserProfileResource','error','stack','name','send','map','Tag','rawAttributes','fieldName','type','key'];(function(_0x57b54c,_0x54ce0d){var _0x59cc19=function(_0xa33bc6){while(--_0xa33bc6){_0x57b54c['push'](_0x57b54c['shift']());}};_0x59cc19(++_0x54ce0d);}(_0x0cdb,0x1aa));var _0xb0cd=function(_0x53f608,_0x256def){_0x53f608=_0x53f608-0x0;var _0x495b7d=_0x0cdb[_0x53f608];return _0x495b7d;};'use strict';var pdf=require(_0xb0cd('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xb0cd('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb0cd('0x2'));var moment=require(_0xb0cd('0x3'));var BPromise=require(_0xb0cd('0x4'));var Mustache=require('mustache');var util=require(_0xb0cd('0x5'));var path=require(_0xb0cd('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xb0cd('0x7'));var fs=require('fs');var _=require('lodash');var squel=require(_0xb0cd('0x8'));var crypto=require(_0xb0cd('0x9'));var jsforce=require(_0xb0cd('0xa'));var deskjs=require(_0xb0cd('0xb'));var toCsv=require(_0xb0cd('0xc'));var querystring=require(_0xb0cd('0xd'));var Papa=require(_0xb0cd('0xe'));var Redis=require(_0xb0cd('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xb0cd('0x10'));var as=require(_0xb0cd('0x11'));var hardwareService=require(_0xb0cd('0x12'));var logger=require(_0xb0cd('0x13'))('api');var utils=require(_0xb0cd('0x14'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1d71ea,_0x491eaa){_0x491eaa=_0x491eaa||0xcc;return function(_0x2d9298){if(_0x2d9298){return _0x1d71ea[_0xb0cd('0x15')](_0x491eaa);}return _0x1d71ea['status'](_0x491eaa)[_0xb0cd('0x16')]();};}function respondWithResult(_0x1742e0,_0x3da0d2){_0x3da0d2=_0x3da0d2||0xc8;return function(_0x1ab0be){if(_0x1ab0be){return _0x1742e0[_0xb0cd('0x17')](_0x3da0d2)[_0xb0cd('0x18')](_0x1ab0be);}};}function respondWithFilteredResult(_0x43d2e4,_0x2a9ac0){return function(_0x2f234d){if(_0x2f234d){var _0x59ccb6=_0x2f234d[_0xb0cd('0x19')],_0x3db6d6=_0x2a9ac0['offset'],_0x3528fd=_0x2a9ac0[_0xb0cd('0x1a')]+_0x2a9ac0[_0xb0cd('0x1b')],_0xbe8ee9;if(_0x3528fd>=_0x59ccb6){_0x3528fd=_0x59ccb6;_0xbe8ee9=0xc8;}else{_0xbe8ee9=0xce;}_0x43d2e4[_0xb0cd('0x17')](_0xbe8ee9);return _0x43d2e4['set'](_0xb0cd('0x1c'),_0x3db6d6+'-'+_0x3528fd+'/'+_0x59ccb6)[_0xb0cd('0x18')](_0x2f234d);}return null;};}function patchUpdates(_0x5eb0da){return function(_0x18c9e5){try{jsonpatch[_0xb0cd('0x1d')](_0x18c9e5,_0x5eb0da,!![]);}catch(_0xd275cf){return BPromise[_0xb0cd('0x1e')](_0xd275cf);}return _0x18c9e5[_0xb0cd('0x1f')]();};}function saveUpdates(_0x29c667,_0x342f21){return function(_0x419e1b){if(_0x419e1b){return _0x419e1b[_0xb0cd('0x20')](_0x29c667)[_0xb0cd('0x21')](function(_0x4b952e){return _0x4b952e;});}return null;};}function removeEntity(_0x5e5341,_0x153996){return function(_0x134479){if(_0x134479){return _0x134479[_0xb0cd('0x22')]()[_0xb0cd('0x21')](function(){var _0x31c5bd=_0x134479[_0xb0cd('0x23')]({'plain':!![]});var _0x341e52=_0xb0cd('0x24');return db[_0xb0cd('0x25')]['destroy']({'where':{'type':_0x341e52,'resourceId':_0x31c5bd['id']}})[_0xb0cd('0x21')](function(){return _0x134479;});})[_0xb0cd('0x21')](function(){_0x5e5341['status'](0xcc)[_0xb0cd('0x16')]();});}};}function handleEntityNotFound(_0xaa0b89,_0x393472){return function(_0x24fb25){if(!_0x24fb25){_0xaa0b89[_0xb0cd('0x15')](0x194);}return _0x24fb25;};}function handleError(_0x5cfb80,_0x4d021e){_0x4d021e=_0x4d021e||0x1f4;return function(_0x483c4b){logger[_0xb0cd('0x26')](_0x483c4b[_0xb0cd('0x27')]);if(_0x483c4b[_0xb0cd('0x28')]){delete _0x483c4b[_0xb0cd('0x28')];}_0x5cfb80[_0xb0cd('0x17')](_0x4d021e)[_0xb0cd('0x29')](_0x483c4b);};}exports['index']=function(_0x58ee02,_0x52ee74){var _0x1eb0d3={},_0x714652={},_0x4820ff={'count':0x0,'rows':[]};var _0x2672ae=_[_0xb0cd('0x2a')](db[_0xb0cd('0x2b')][_0xb0cd('0x2c')],function(_0x3cce9e){return{'name':_0x3cce9e[_0xb0cd('0x2d')],'type':_0x3cce9e[_0xb0cd('0x2e')][_0xb0cd('0x2f')]};});_0x714652[_0xb0cd('0x30')]=_[_0xb0cd('0x2a')](_0x2672ae,_0xb0cd('0x28'));_0x714652[_0xb0cd('0x31')]=_[_0xb0cd('0x32')](_0x58ee02['query']);_0x714652[_0xb0cd('0x33')]=_[_0xb0cd('0x34')](_0x714652[_0xb0cd('0x30')],_0x714652[_0xb0cd('0x31')]);_0x1eb0d3['attributes']=_[_0xb0cd('0x34')](_0x714652[_0xb0cd('0x30')],qs[_0xb0cd('0x35')](_0x58ee02['query'][_0xb0cd('0x35')]));_0x1eb0d3[_0xb0cd('0x36')]=_0x1eb0d3['attributes'][_0xb0cd('0x37')]?_0x1eb0d3['attributes']:_0x714652[_0xb0cd('0x30')];if(!_0x58ee02[_0xb0cd('0x31')][_0xb0cd('0x38')](_0xb0cd('0x39'))){_0x1eb0d3[_0xb0cd('0x1b')]=qs[_0xb0cd('0x1b')](_0x58ee02[_0xb0cd('0x31')][_0xb0cd('0x1b')]);_0x1eb0d3[_0xb0cd('0x1a')]=qs[_0xb0cd('0x1a')](_0x58ee02['query'][_0xb0cd('0x1a')]);}_0x1eb0d3['order']=qs[_0xb0cd('0x3a')](_0x58ee02['query'][_0xb0cd('0x3a')]);_0x1eb0d3['where']=qs[_0xb0cd('0x33')](_[_0xb0cd('0x3b')](_0x58ee02['query'],_0x714652[_0xb0cd('0x33')]),_0x2672ae);if(_0x58ee02[_0xb0cd('0x31')][_0xb0cd('0x3c')]){_0x1eb0d3['where']=_[_0xb0cd('0x3d')](_0x1eb0d3[_0xb0cd('0x3e')],{'$or':_[_0xb0cd('0x2a')](_0x2672ae,function(_0x179826){if(_0x179826['type']!==_0xb0cd('0x3f')){var _0x226b7d={};_0x226b7d[_0x179826[_0xb0cd('0x28')]]={'$like':'%'+_0x58ee02[_0xb0cd('0x31')][_0xb0cd('0x3c')]+'%'};return _0x226b7d;}})});}_0x1eb0d3=_[_0xb0cd('0x3d')]({},_0x1eb0d3,_0x58ee02['options']);var _0x208523={'where':_0x1eb0d3[_0xb0cd('0x3e')]};return db[_0xb0cd('0x2b')][_0xb0cd('0x19')](_0x208523)['then'](function(_0x36e05b){_0x4820ff[_0xb0cd('0x19')]=_0x36e05b;if(_0x58ee02['query']['includeAll']){_0x1eb0d3['include']=[{'all':!![]}];}return db[_0xb0cd('0x2b')][_0xb0cd('0x40')](_0x1eb0d3);})[_0xb0cd('0x21')](function(_0x14fbe5){_0x4820ff[_0xb0cd('0x41')]=_0x14fbe5;return _0x4820ff;})['then'](respondWithFilteredResult(_0x52ee74,_0x1eb0d3))[_0xb0cd('0x42')](handleError(_0x52ee74,null));};exports[_0xb0cd('0x43')]=function(_0xb1c7d5,_0x154245){var _0x3d4090={'raw':!![],'where':{'id':_0xb1c7d5[_0xb0cd('0x44')]['id']}},_0x291a9a={};_0x291a9a[_0xb0cd('0x30')]=_[_0xb0cd('0x32')](db[_0xb0cd('0x2b')][_0xb0cd('0x2c')]);_0x291a9a['query']=_['keys'](_0xb1c7d5[_0xb0cd('0x31')]);_0x291a9a[_0xb0cd('0x33')]=_[_0xb0cd('0x34')](_0x291a9a[_0xb0cd('0x30')],_0x291a9a['query']);_0x3d4090['attributes']=_[_0xb0cd('0x34')](_0x291a9a['model'],qs[_0xb0cd('0x35')](_0xb1c7d5[_0xb0cd('0x31')]['fields']));_0x3d4090[_0xb0cd('0x36')]=_0x3d4090[_0xb0cd('0x36')]['length']?_0x3d4090[_0xb0cd('0x36')]:_0x291a9a[_0xb0cd('0x30')];if(_0xb1c7d5[_0xb0cd('0x31')]['includeAll']){_0x3d4090['include']=[{'all':!![]}];}_0x3d4090=_[_0xb0cd('0x3d')]({},_0x3d4090,_0xb1c7d5[_0xb0cd('0x45')]);return db[_0xb0cd('0x2b')][_0xb0cd('0x46')](_0x3d4090)[_0xb0cd('0x21')](handleEntityNotFound(_0x154245,null))[_0xb0cd('0x21')](respondWithResult(_0x154245,null))[_0xb0cd('0x42')](handleError(_0x154245,null));};exports[_0xb0cd('0x47')]=function(_0x15321c,_0x39b915){return db[_0xb0cd('0x2b')][_0xb0cd('0x47')](_0x15321c[_0xb0cd('0x48')],{})[_0xb0cd('0x21')](function(_0x356a5b){var _0x595125=_0x15321c[_0xb0cd('0x49')][_0xb0cd('0x23')]({'plain':!![]});if(!_0x595125)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x595125[_0xb0cd('0x4a')]===_0xb0cd('0x49')){var _0x5e3131=_0x356a5b[_0xb0cd('0x23')]({'plain':!![]});var _0x4794c8=_0xb0cd('0x24');return db[_0xb0cd('0x4b')]['find']({'where':{'name':_0x4794c8,'userProfileId':_0x595125[_0xb0cd('0x4c')]},'raw':!![]})[_0xb0cd('0x21')](function(_0x419f34){if(_0x419f34&&_0x419f34[_0xb0cd('0x4d')]===0x0){return db[_0xb0cd('0x25')][_0xb0cd('0x47')]({'name':_0x5e3131['name'],'resourceId':_0x5e3131['id'],'type':_0x419f34[_0xb0cd('0x28')],'sectionId':_0x419f34['id']},{})[_0xb0cd('0x21')](function(){return _0x356a5b;});}else{return _0x356a5b;}})[_0xb0cd('0x42')](function(_0x4d26e7){logger[_0xb0cd('0x26')](_0xb0cd('0x4e'),_0x4d26e7);throw _0x4d26e7;});}return _0x356a5b;})[_0xb0cd('0x21')](respondWithResult(_0x39b915,0xc9))[_0xb0cd('0x42')](handleError(_0x39b915,null));};exports['update']=function(_0x57d828,_0x178005){if(_0x57d828[_0xb0cd('0x48')]['id']){delete _0x57d828[_0xb0cd('0x48')]['id'];}return db[_0xb0cd('0x2b')]['find']({'where':{'id':_0x57d828[_0xb0cd('0x44')]['id']}})['then'](handleEntityNotFound(_0x178005,null))[_0xb0cd('0x21')](saveUpdates(_0x57d828[_0xb0cd('0x48')],null))[_0xb0cd('0x21')](respondWithResult(_0x178005,null))[_0xb0cd('0x42')](handleError(_0x178005,null));};exports['destroy']=function(_0x3c404f,_0x476eb7){return db['Tag'][_0xb0cd('0x46')]({'where':{'id':_0x3c404f[_0xb0cd('0x44')]['id']}})['then'](handleEntityNotFound(_0x476eb7,null))[_0xb0cd('0x21')](removeEntity(_0x476eb7,null))[_0xb0cd('0x42')](handleError(_0x476eb7,null));};