Built motion from commit (unavailable).|2.5.0
[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 _0xc86f=['save','update','then','UserProfileResource','destroy','error','name','send','index','map','Tag','fieldName','type','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','params','rawAttributes','fields','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','find','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','ejs','lodash','squel','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','status','end','json','count','offset','limit','set','apply','reject'];(function(_0x44dcc8,_0x5815a6){var _0x2c4c12=function(_0x4126ef){while(--_0x4126ef){_0x44dcc8['push'](_0x44dcc8['shift']());}};_0x2c4c12(++_0x5815a6);}(_0xc86f,0x1ba));var _0xfc86=function(_0x38fcbb,_0xd2b478){_0x38fcbb=_0x38fcbb-0x0;var _0x4bbb75=_0xc86f[_0x38fcbb];return _0x4bbb75;};'use strict';var pdf=require(_0xfc86('0x0'));var emlformat=require(_0xfc86('0x1'));var rimraf=require(_0xfc86('0x2'));var zipdir=require(_0xfc86('0x3'));var jsonpatch=require(_0xfc86('0x4'));var rp=require(_0xfc86('0x5'));var moment=require(_0xfc86('0x6'));var BPromise=require(_0xfc86('0x7'));var Mustache=require(_0xfc86('0x8'));var util=require(_0xfc86('0x9'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xfc86('0xa'));var fs=require('fs');var _=require(_0xfc86('0xb'));var squel=require(_0xfc86('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xfc86('0xd'));var toCsv=require(_0xfc86('0xe'));var querystring=require('querystring');var Papa=require(_0xfc86('0xf'));var Redis=require(_0xfc86('0x10'));var authService=require(_0xfc86('0x11'));var qs=require(_0xfc86('0x12'));var as=require(_0xfc86('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xfc86('0x14'))(_0xfc86('0x15'));var utils=require('../../config/utils');var config=require(_0xfc86('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x15cdbc,_0x34a9ad){_0x34a9ad=_0x34a9ad||0xcc;return function(_0x1c0f80){if(_0x1c0f80){return _0x15cdbc['sendStatus'](_0x34a9ad);}return _0x15cdbc[_0xfc86('0x17')](_0x34a9ad)[_0xfc86('0x18')]();};}function respondWithResult(_0x360112,_0x10e0fe){_0x10e0fe=_0x10e0fe||0xc8;return function(_0x11611b){if(_0x11611b){return _0x360112['status'](_0x10e0fe)[_0xfc86('0x19')](_0x11611b);}};}function respondWithFilteredResult(_0x1764fc,_0x4b82a1){return function(_0x3c134b){if(_0x3c134b){var _0x4aad03=_0x3c134b[_0xfc86('0x1a')],_0x54a0a1=_0x4b82a1[_0xfc86('0x1b')],_0x3a1d45=_0x4b82a1[_0xfc86('0x1b')]+_0x4b82a1[_0xfc86('0x1c')],_0x1f4abc;if(_0x3a1d45>=_0x4aad03){_0x3a1d45=_0x4aad03;_0x1f4abc=0xc8;}else{_0x1f4abc=0xce;}_0x1764fc['status'](_0x1f4abc);return _0x1764fc[_0xfc86('0x1d')]('Content-Range',_0x54a0a1+'-'+_0x3a1d45+'/'+_0x4aad03)[_0xfc86('0x19')](_0x3c134b);}return null;};}function patchUpdates(_0x1738e4){return function(_0x5c2877){try{jsonpatch[_0xfc86('0x1e')](_0x5c2877,_0x1738e4,!![]);}catch(_0x48624d){return BPromise[_0xfc86('0x1f')](_0x48624d);}return _0x5c2877[_0xfc86('0x20')]();};}function saveUpdates(_0x3297e0,_0x5d3066){return function(_0x47d396){if(_0x47d396){return _0x47d396[_0xfc86('0x21')](_0x3297e0)[_0xfc86('0x22')](function(_0x3676a3){return _0x3676a3;});}return null;};}function removeEntity(_0x22305e,_0x12e191){return function(_0x4a300c){if(_0x4a300c){return _0x4a300c['destroy']()[_0xfc86('0x22')](function(){var _0x50c833=_0x4a300c['get']({'plain':!![]});var _0x9a5914='Tags';return db[_0xfc86('0x23')][_0xfc86('0x24')]({'where':{'type':_0x9a5914,'resourceId':_0x50c833['id']}})[_0xfc86('0x22')](function(){return _0x4a300c;});})[_0xfc86('0x22')](function(){_0x22305e['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x21418d,_0x1bc111){return function(_0x418891){if(!_0x418891){_0x21418d['sendStatus'](0x194);}return _0x418891;};}function handleError(_0x1f4b1e,_0x5378c8){_0x5378c8=_0x5378c8||0x1f4;return function(_0x49484b){logger[_0xfc86('0x25')](_0x49484b['stack']);if(_0x49484b[_0xfc86('0x26')]){delete _0x49484b[_0xfc86('0x26')];}_0x1f4b1e[_0xfc86('0x17')](_0x5378c8)[_0xfc86('0x27')](_0x49484b);};}exports[_0xfc86('0x28')]=function(_0x247696,_0x24a6e3){var _0x29532f={},_0x299932={},_0x4879d5={'count':0x0,'rows':[]};var _0x138663=_[_0xfc86('0x29')](db[_0xfc86('0x2a')]['rawAttributes'],function(_0x54f582){return{'name':_0x54f582[_0xfc86('0x2b')],'type':_0x54f582[_0xfc86('0x2c')][_0xfc86('0x2d')]};});_0x299932[_0xfc86('0x2e')]=_[_0xfc86('0x29')](_0x138663,'name');_0x299932[_0xfc86('0x2f')]=_[_0xfc86('0x30')](_0x247696[_0xfc86('0x2f')]);_0x299932[_0xfc86('0x31')]=_[_0xfc86('0x32')](_0x299932['model'],_0x299932[_0xfc86('0x2f')]);_0x29532f[_0xfc86('0x33')]=_[_0xfc86('0x32')](_0x299932[_0xfc86('0x2e')],qs['fields'](_0x247696[_0xfc86('0x2f')]['fields']));_0x29532f[_0xfc86('0x33')]=_0x29532f[_0xfc86('0x33')][_0xfc86('0x34')]?_0x29532f[_0xfc86('0x33')]:_0x299932[_0xfc86('0x2e')];if(!_0x247696[_0xfc86('0x2f')][_0xfc86('0x35')](_0xfc86('0x36'))){_0x29532f[_0xfc86('0x1c')]=qs[_0xfc86('0x1c')](_0x247696[_0xfc86('0x2f')]['limit']);_0x29532f[_0xfc86('0x1b')]=qs['offset'](_0x247696[_0xfc86('0x2f')][_0xfc86('0x1b')]);}_0x29532f[_0xfc86('0x37')]=qs[_0xfc86('0x38')](_0x247696[_0xfc86('0x2f')][_0xfc86('0x38')]);_0x29532f[_0xfc86('0x39')]=qs[_0xfc86('0x31')](_['pick'](_0x247696['query'],_0x299932[_0xfc86('0x31')]));if(_0x247696['query'][_0xfc86('0x3a')]){_0x29532f[_0xfc86('0x39')]=_[_0xfc86('0x3b')](_0x29532f[_0xfc86('0x39')],{'$or':_[_0xfc86('0x29')](_0x138663,function(_0x12ee4a){if(_0x12ee4a[_0xfc86('0x2c')]!==_0xfc86('0x3c')){var _0x4a40ec={};_0x4a40ec[_0x12ee4a[_0xfc86('0x26')]]={'$like':'%'+_0x247696['query'][_0xfc86('0x3a')]+'%'};return _0x4a40ec;}})});}_0x29532f=_[_0xfc86('0x3b')]({},_0x29532f,_0x247696[_0xfc86('0x3d')]);var _0x4cf05e={'where':_0x29532f[_0xfc86('0x39')]};return db[_0xfc86('0x2a')][_0xfc86('0x1a')](_0x4cf05e)['then'](function(_0x362dd5){_0x4879d5[_0xfc86('0x1a')]=_0x362dd5;if(_0x247696[_0xfc86('0x2f')][_0xfc86('0x3e')]){_0x29532f[_0xfc86('0x3f')]=[{'all':!![]}];}return db['Tag'][_0xfc86('0x40')](_0x29532f);})[_0xfc86('0x22')](function(_0x2c71e6){_0x4879d5['rows']=_0x2c71e6;return _0x4879d5;})[_0xfc86('0x22')](respondWithFilteredResult(_0x24a6e3,_0x29532f))[_0xfc86('0x41')](handleError(_0x24a6e3,null));};exports['show']=function(_0x2e784e,_0x6b4e8e){var _0x2e0c05={'raw':!![],'where':{'id':_0x2e784e[_0xfc86('0x42')]['id']}},_0x341f7f={};_0x341f7f[_0xfc86('0x2e')]=_[_0xfc86('0x30')](db[_0xfc86('0x2a')][_0xfc86('0x43')]);_0x341f7f[_0xfc86('0x2f')]=_[_0xfc86('0x30')](_0x2e784e[_0xfc86('0x2f')]);_0x341f7f['filters']=_[_0xfc86('0x32')](_0x341f7f[_0xfc86('0x2e')],_0x341f7f[_0xfc86('0x2f')]);_0x2e0c05[_0xfc86('0x33')]=_[_0xfc86('0x32')](_0x341f7f[_0xfc86('0x2e')],qs[_0xfc86('0x44')](_0x2e784e['query'][_0xfc86('0x44')]));_0x2e0c05[_0xfc86('0x33')]=_0x2e0c05[_0xfc86('0x33')][_0xfc86('0x34')]?_0x2e0c05[_0xfc86('0x33')]:_0x341f7f[_0xfc86('0x2e')];if(_0x2e784e[_0xfc86('0x2f')]['includeAll']){_0x2e0c05[_0xfc86('0x3f')]=[{'all':!![]}];}_0x2e0c05=_[_0xfc86('0x3b')]({},_0x2e0c05,_0x2e784e['options']);return db[_0xfc86('0x2a')]['find'](_0x2e0c05)[_0xfc86('0x22')](handleEntityNotFound(_0x6b4e8e,null))['then'](respondWithResult(_0x6b4e8e,null))[_0xfc86('0x41')](handleError(_0x6b4e8e,null));};exports['create']=function(_0x472e55,_0x279064){return db['Tag'][_0xfc86('0x45')](_0x472e55['body'],{})['then'](function(_0x3ed48e){var _0x22ceb4=_0x472e55[_0xfc86('0x46')]['get']({'plain':!![]});if(!_0x22ceb4)throw new Error(_0xfc86('0x47'));if(_0x22ceb4[_0xfc86('0x48')]===_0xfc86('0x46')){var _0x255d84=_0x3ed48e['get']({'plain':!![]});var _0x564a5e='Tags';return db[_0xfc86('0x49')]['find']({'where':{'name':_0x564a5e,'userProfileId':_0x22ceb4[_0xfc86('0x4a')]},'raw':!![]})[_0xfc86('0x22')](function(_0x5b9816){if(_0x5b9816&&_0x5b9816[_0xfc86('0x4b')]===0x0){return db[_0xfc86('0x23')][_0xfc86('0x45')]({'name':_0x255d84[_0xfc86('0x26')],'resourceId':_0x255d84['id'],'type':_0x5b9816[_0xfc86('0x26')],'sectionId':_0x5b9816['id']},{})[_0xfc86('0x22')](function(){return _0x3ed48e;});}else{return _0x3ed48e;}})['catch'](function(_0x305c75){logger['error'](_0xfc86('0x4c'),_0x305c75);throw _0x305c75;});}return _0x3ed48e;})[_0xfc86('0x22')](respondWithResult(_0x279064,0xc9))['catch'](handleError(_0x279064,null));};exports[_0xfc86('0x21')]=function(_0x5a7dc4,_0x4fb97b){if(_0x5a7dc4[_0xfc86('0x4d')]['id']){delete _0x5a7dc4[_0xfc86('0x4d')]['id'];}return db[_0xfc86('0x2a')][_0xfc86('0x4e')]({'where':{'id':_0x5a7dc4['params']['id']}})['then'](handleEntityNotFound(_0x4fb97b,null))['then'](saveUpdates(_0x5a7dc4[_0xfc86('0x4d')],null))[_0xfc86('0x22')](respondWithResult(_0x4fb97b,null))['catch'](handleError(_0x4fb97b,null));};exports['destroy']=function(_0x3c67b0,_0x582e23){return db[_0xfc86('0x2a')][_0xfc86('0x4e')]({'where':{'id':_0x3c67b0['params']['id']}})['then'](handleEntityNotFound(_0x582e23,null))[_0xfc86('0x22')](removeEntity(_0x582e23,null))[_0xfc86('0x41')](handleError(_0x582e23,null));};