Built motion from commit (unavailable).|2.5.6
[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 _0x923f=['findAll','rows','catch','show','params','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','json','offset','limit','status','set','Content-Range','apply','reject','update','then','get','Tags','destroy','error','name','send','map','Tag','rawAttributes','type','key','keys','query','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','options','count','includeAll','include'];(function(_0x192b66,_0x46cd6a){var _0xc13db5=function(_0x2af8d8){while(--_0x2af8d8){_0x192b66['push'](_0x192b66['shift']());}};_0xc13db5(++_0x46cd6a);}(_0x923f,0x1b8));var _0xf923=function(_0x4e2ad1,_0x469a4f){_0x4e2ad1=_0x4e2ad1-0x0;var _0x207cd3=_0x923f[_0x4e2ad1];return _0x207cd3;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf923('0x0'));var rimraf=require(_0xf923('0x1'));var zipdir=require(_0xf923('0x2'));var jsonpatch=require(_0xf923('0x3'));var rp=require(_0xf923('0x4'));var moment=require(_0xf923('0x5'));var BPromise=require(_0xf923('0x6'));var Mustache=require(_0xf923('0x7'));var util=require(_0xf923('0x8'));var path=require(_0xf923('0x9'));var sox=require('sox');var csv=require(_0xf923('0xa'));var ejs=require(_0xf923('0xb'));var fs=require('fs');var _=require(_0xf923('0xc'));var squel=require(_0xf923('0xd'));var crypto=require('crypto');var jsforce=require(_0xf923('0xe'));var deskjs=require(_0xf923('0xf'));var toCsv=require(_0xf923('0xa'));var querystring=require(_0xf923('0x10'));var Papa=require(_0xf923('0x11'));var Redis=require(_0xf923('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xf923('0x13'));var as=require(_0xf923('0x14'));var hardwareService=require(_0xf923('0x15'));var logger=require(_0xf923('0x16'))(_0xf923('0x17'));var utils=require(_0xf923('0x18'));var config=require(_0xf923('0x19'));var licenseUtil=require(_0xf923('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4f0bea,_0x6ed51a){_0x6ed51a=_0x6ed51a||0xcc;return function(_0x44ab85){if(_0x44ab85){return _0x4f0bea[_0xf923('0x1b')](_0x6ed51a);}return _0x4f0bea['status'](_0x6ed51a)[_0xf923('0x1c')]();};}function respondWithResult(_0x595a7e,_0x2442a7){_0x2442a7=_0x2442a7||0xc8;return function(_0x28deac){if(_0x28deac){return _0x595a7e['status'](_0x2442a7)[_0xf923('0x1d')](_0x28deac);}};}function respondWithFilteredResult(_0x3ed7a9,_0x4c9441){return function(_0xeb2fb0){if(_0xeb2fb0){var _0x293c05=_0xeb2fb0['count'],_0x57844f=_0x4c9441[_0xf923('0x1e')],_0xfc3933=_0x4c9441[_0xf923('0x1e')]+_0x4c9441[_0xf923('0x1f')],_0x410fd8;if(_0xfc3933>=_0x293c05){_0xfc3933=_0x293c05;_0x410fd8=0xc8;}else{_0x410fd8=0xce;}_0x3ed7a9[_0xf923('0x20')](_0x410fd8);return _0x3ed7a9[_0xf923('0x21')](_0xf923('0x22'),_0x57844f+'-'+_0xfc3933+'/'+_0x293c05)[_0xf923('0x1d')](_0xeb2fb0);}return null;};}function patchUpdates(_0x3b5c23){return function(_0x12131e){try{jsonpatch[_0xf923('0x23')](_0x12131e,_0x3b5c23,!![]);}catch(_0x44ecad){return BPromise[_0xf923('0x24')](_0x44ecad);}return _0x12131e['save']();};}function saveUpdates(_0xd5fde4,_0x2b56f3){return function(_0x254285){if(_0x254285){return _0x254285[_0xf923('0x25')](_0xd5fde4)[_0xf923('0x26')](function(_0x52c7e0){return _0x52c7e0;});}return null;};}function removeEntity(_0x18424a,_0x13cf22){return function(_0x55bb3d){if(_0x55bb3d){return _0x55bb3d['destroy']()[_0xf923('0x26')](function(){var _0x8c3232=_0x55bb3d[_0xf923('0x27')]({'plain':!![]});var _0x4526bf=_0xf923('0x28');return db['UserProfileResource'][_0xf923('0x29')]({'where':{'type':_0x4526bf,'resourceId':_0x8c3232['id']}})[_0xf923('0x26')](function(){return _0x55bb3d;});})['then'](function(){_0x18424a[_0xf923('0x20')](0xcc)[_0xf923('0x1c')]();});}};}function handleEntityNotFound(_0x2a3090,_0x3824a1){return function(_0x2452b4){if(!_0x2452b4){_0x2a3090[_0xf923('0x1b')](0x194);}return _0x2452b4;};}function handleError(_0x26b234,_0x4146c9){_0x4146c9=_0x4146c9||0x1f4;return function(_0xe05a17){logger[_0xf923('0x2a')](_0xe05a17['stack']);if(_0xe05a17['name']){delete _0xe05a17[_0xf923('0x2b')];}_0x26b234['status'](_0x4146c9)[_0xf923('0x2c')](_0xe05a17);};}exports['index']=function(_0x19243b,_0x20104d){var _0x504ca6={},_0x45d9f9={},_0xcaaf07={'count':0x0,'rows':[]};var _0xfc33b3=_[_0xf923('0x2d')](db[_0xf923('0x2e')][_0xf923('0x2f')],function(_0x53011a){return{'name':_0x53011a['fieldName'],'type':_0x53011a[_0xf923('0x30')][_0xf923('0x31')]};});_0x45d9f9['model']=_[_0xf923('0x2d')](_0xfc33b3,_0xf923('0x2b'));_0x45d9f9['query']=_[_0xf923('0x32')](_0x19243b[_0xf923('0x33')]);_0x45d9f9[_0xf923('0x34')]=_[_0xf923('0x35')](_0x45d9f9[_0xf923('0x36')],_0x45d9f9['query']);_0x504ca6['attributes']=_['intersection'](_0x45d9f9[_0xf923('0x36')],qs['fields'](_0x19243b['query'][_0xf923('0x37')]));_0x504ca6[_0xf923('0x38')]=_0x504ca6[_0xf923('0x38')][_0xf923('0x39')]?_0x504ca6[_0xf923('0x38')]:_0x45d9f9[_0xf923('0x36')];if(!_0x19243b[_0xf923('0x33')][_0xf923('0x3a')](_0xf923('0x3b'))){_0x504ca6['limit']=qs[_0xf923('0x1f')](_0x19243b['query']['limit']);_0x504ca6[_0xf923('0x1e')]=qs[_0xf923('0x1e')](_0x19243b[_0xf923('0x33')]['offset']);}_0x504ca6[_0xf923('0x3c')]=qs[_0xf923('0x3d')](_0x19243b[_0xf923('0x33')]['sort']);_0x504ca6[_0xf923('0x3e')]=qs[_0xf923('0x34')](_[_0xf923('0x3f')](_0x19243b[_0xf923('0x33')],_0x45d9f9[_0xf923('0x34')]),_0xfc33b3);if(_0x19243b['query']['filter']){_0x504ca6['where']=_[_0xf923('0x40')](_0x504ca6[_0xf923('0x3e')],{'$or':_[_0xf923('0x2d')](_0xfc33b3,function(_0x522a6b){if(_0x522a6b['type']!==_0xf923('0x41')){var _0x54d233={};_0x54d233[_0x522a6b[_0xf923('0x2b')]]={'$like':'%'+_0x19243b[_0xf923('0x33')]['filter']+'%'};return _0x54d233;}})});}_0x504ca6=_[_0xf923('0x40')]({},_0x504ca6,_0x19243b[_0xf923('0x42')]);var _0x258490={'where':_0x504ca6[_0xf923('0x3e')]};return db[_0xf923('0x2e')][_0xf923('0x43')](_0x258490)[_0xf923('0x26')](function(_0x5284c2){_0xcaaf07[_0xf923('0x43')]=_0x5284c2;if(_0x19243b[_0xf923('0x33')][_0xf923('0x44')]){_0x504ca6[_0xf923('0x45')]=[{'all':!![]}];}return db['Tag'][_0xf923('0x46')](_0x504ca6);})['then'](function(_0x39c729){_0xcaaf07[_0xf923('0x47')]=_0x39c729;return _0xcaaf07;})['then'](respondWithFilteredResult(_0x20104d,_0x504ca6))[_0xf923('0x48')](handleError(_0x20104d,null));};exports[_0xf923('0x49')]=function(_0x3ea881,_0x538785){var _0x4e02c4={'raw':!![],'where':{'id':_0x3ea881[_0xf923('0x4a')]['id']}},_0x12d741={};_0x12d741[_0xf923('0x36')]=_[_0xf923('0x32')](db['Tag'][_0xf923('0x2f')]);_0x12d741[_0xf923('0x33')]=_[_0xf923('0x32')](_0x3ea881['query']);_0x12d741['filters']=_[_0xf923('0x35')](_0x12d741[_0xf923('0x36')],_0x12d741[_0xf923('0x33')]);_0x4e02c4['attributes']=_[_0xf923('0x35')](_0x12d741[_0xf923('0x36')],qs['fields'](_0x3ea881['query'][_0xf923('0x37')]));_0x4e02c4['attributes']=_0x4e02c4[_0xf923('0x38')][_0xf923('0x39')]?_0x4e02c4['attributes']:_0x12d741[_0xf923('0x36')];if(_0x3ea881['query'][_0xf923('0x44')]){_0x4e02c4[_0xf923('0x45')]=[{'all':!![]}];}_0x4e02c4=_[_0xf923('0x40')]({},_0x4e02c4,_0x3ea881[_0xf923('0x42')]);return db[_0xf923('0x2e')][_0xf923('0x4b')](_0x4e02c4)[_0xf923('0x26')](handleEntityNotFound(_0x538785,null))[_0xf923('0x26')](respondWithResult(_0x538785,null))['catch'](handleError(_0x538785,null));};exports[_0xf923('0x4c')]=function(_0x2e112f,_0x5b2ffa){return db[_0xf923('0x2e')]['create'](_0x2e112f[_0xf923('0x4d')],{})[_0xf923('0x26')](function(_0x2e4b58){var _0x22eac5=_0x2e112f[_0xf923('0x4e')][_0xf923('0x27')]({'plain':!![]});if(!_0x22eac5)throw new Error(_0xf923('0x4f'));if(_0x22eac5[_0xf923('0x50')]==='user'){var _0x39a1ec=_0x2e4b58[_0xf923('0x27')]({'plain':!![]});var _0x43a13f=_0xf923('0x28');return db[_0xf923('0x51')][_0xf923('0x4b')]({'where':{'name':_0x43a13f,'userProfileId':_0x22eac5[_0xf923('0x52')]},'raw':!![]})[_0xf923('0x26')](function(_0x55a2b8){if(_0x55a2b8&&_0x55a2b8[_0xf923('0x53')]===0x0){return db[_0xf923('0x54')][_0xf923('0x4c')]({'name':_0x39a1ec[_0xf923('0x2b')],'resourceId':_0x39a1ec['id'],'type':_0x55a2b8[_0xf923('0x2b')],'sectionId':_0x55a2b8['id']},{})[_0xf923('0x26')](function(){return _0x2e4b58;});}else{return _0x2e4b58;}})[_0xf923('0x48')](function(_0x51006f){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x51006f);throw _0x51006f;});}return _0x2e4b58;})['then'](respondWithResult(_0x5b2ffa,0xc9))[_0xf923('0x48')](handleError(_0x5b2ffa,null));};exports['update']=function(_0x4b37e3,_0x3e3818){if(_0x4b37e3[_0xf923('0x4d')]['id']){delete _0x4b37e3[_0xf923('0x4d')]['id'];}return db[_0xf923('0x2e')][_0xf923('0x4b')]({'where':{'id':_0x4b37e3['params']['id']}})[_0xf923('0x26')](handleEntityNotFound(_0x3e3818,null))[_0xf923('0x26')](saveUpdates(_0x4b37e3[_0xf923('0x4d')],null))['then'](respondWithResult(_0x3e3818,null))[_0xf923('0x48')](handleError(_0x3e3818,null));};exports[_0xf923('0x29')]=function(_0x50679b,_0x49ecf2){return db[_0xf923('0x2e')][_0xf923('0x4b')]({'where':{'id':_0x50679b['params']['id']}})[_0xf923('0x26')](handleEntityNotFound(_0x49ecf2,null))['then'](removeEntity(_0x49ecf2,null))[_0xf923('0x48')](handleError(_0x49ecf2,null));};