Built motion from commit (unavailable).|2.5.0
[motion2.git] / server / api / variable / variable.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 _0x6c2f=['../../mysqldb','sendStatus','status','end','json','count','set','Content-Range','apply','save','update','destroy','get','Variables','UserProfileResource','then','error','stack','name','send','index','map','rawAttributes','fieldName','query','keys','filters','intersection','model','attributes','length','hasOwnProperty','nolimit','limit','offset','order','sort','filter','where','merge','VIRTUAL','options','Variable','include','findAll','rows','catch','show','params','fields','includeAll','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment'];(function(_0x13c70c,_0x546b34){var _0x50f0f2=function(_0x2a2991){while(--_0x2a2991){_0x13c70c['push'](_0x13c70c['shift']());}};_0x50f0f2(++_0x546b34);}(_0x6c2f,0x95));var _0xf6c2=function(_0x1dab11,_0x3ada05){_0x1dab11=_0x1dab11-0x0;var _0x2d6221=_0x6c2f[_0x1dab11];return _0x2d6221;};'use strict';var pdf=require(_0xf6c2('0x0'));var emlformat=require(_0xf6c2('0x1'));var rimraf=require(_0xf6c2('0x2'));var zipdir=require(_0xf6c2('0x3'));var jsonpatch=require(_0xf6c2('0x4'));var rp=require('request-promise');var moment=require(_0xf6c2('0x5'));var BPromise=require(_0xf6c2('0x6'));var Mustache=require(_0xf6c2('0x7'));var util=require(_0xf6c2('0x8'));var path=require(_0xf6c2('0x9'));var sox=require(_0xf6c2('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xf6c2('0xb'));var squel=require(_0xf6c2('0xc'));var crypto=require(_0xf6c2('0xd'));var jsforce=require(_0xf6c2('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xf6c2('0xf'));var querystring=require(_0xf6c2('0x10'));var Papa=require(_0xf6c2('0x11'));var Redis=require(_0xf6c2('0x12'));var authService=require(_0xf6c2('0x13'));var qs=require(_0xf6c2('0x14'));var as=require(_0xf6c2('0x15'));var hardwareService=require(_0xf6c2('0x16'));var logger=require(_0xf6c2('0x17'))(_0xf6c2('0x18'));var utils=require(_0xf6c2('0x19'));var config=require(_0xf6c2('0x1a'));var db=require(_0xf6c2('0x1b'))['db'];function respondWithStatusCode(_0x5c5ea1,_0x5bb786){_0x5bb786=_0x5bb786||0xcc;return function(_0x38bd81){if(_0x38bd81){return _0x5c5ea1[_0xf6c2('0x1c')](_0x5bb786);}return _0x5c5ea1[_0xf6c2('0x1d')](_0x5bb786)[_0xf6c2('0x1e')]();};}function respondWithResult(_0x57a876,_0x2c91af){_0x2c91af=_0x2c91af||0xc8;return function(_0x1279f0){if(_0x1279f0){return _0x57a876['status'](_0x2c91af)[_0xf6c2('0x1f')](_0x1279f0);}};}function respondWithFilteredResult(_0x5bd903,_0x4b445e){return function(_0x9a1883){if(_0x9a1883){var _0x5180e2=_0x9a1883[_0xf6c2('0x20')],_0x3423a2=_0x4b445e['offset'],_0x332018=_0x4b445e['offset']+_0x4b445e['limit'],_0x11f7ba;if(_0x332018>=_0x5180e2){_0x332018=_0x5180e2;_0x11f7ba=0xc8;}else{_0x11f7ba=0xce;}_0x5bd903['status'](_0x11f7ba);return _0x5bd903[_0xf6c2('0x21')](_0xf6c2('0x22'),_0x3423a2+'-'+_0x332018+'/'+_0x5180e2)['json'](_0x9a1883);}return null;};}function patchUpdates(_0x3aaf5f){return function(_0x14be98){try{jsonpatch[_0xf6c2('0x23')](_0x14be98,_0x3aaf5f,!![]);}catch(_0x540b8f){return BPromise['reject'](_0x540b8f);}return _0x14be98[_0xf6c2('0x24')]();};}function saveUpdates(_0x430afc,_0x445347){return function(_0x1947c3){if(_0x1947c3){return _0x1947c3[_0xf6c2('0x25')](_0x430afc)['then'](function(_0x4fee83){return _0x4fee83;});}return null;};}function removeEntity(_0x36c5e7,_0x27f1ca){return function(_0x45f350){if(_0x45f350){return _0x45f350[_0xf6c2('0x26')]()['then'](function(){var _0x541edb=_0x45f350[_0xf6c2('0x27')]({'plain':!![]});var _0x1449a8=_0xf6c2('0x28');return db[_0xf6c2('0x29')][_0xf6c2('0x26')]({'where':{'type':_0x1449a8,'resourceId':_0x541edb['id']}})['then'](function(){return _0x45f350;});})[_0xf6c2('0x2a')](function(){_0x36c5e7['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x375c00,_0x4f141d){return function(_0x101b2b){if(!_0x101b2b){_0x375c00[_0xf6c2('0x1c')](0x194);}return _0x101b2b;};}function handleError(_0xfc3ef9,_0x3b08c8){_0x3b08c8=_0x3b08c8||0x1f4;return function(_0x4fcd46){logger[_0xf6c2('0x2b')](_0x4fcd46[_0xf6c2('0x2c')]);if(_0x4fcd46[_0xf6c2('0x2d')]){delete _0x4fcd46['name'];}_0xfc3ef9['status'](_0x3b08c8)[_0xf6c2('0x2e')](_0x4fcd46);};}exports[_0xf6c2('0x2f')]=function(_0x554447,_0x16d184){var _0x3d1689={},_0x259f0c={},_0x3e1dd0={'count':0x0,'rows':[]};var _0x303d44=_[_0xf6c2('0x30')](db['Variable'][_0xf6c2('0x31')],function(_0x158fbc){return{'name':_0x158fbc[_0xf6c2('0x32')],'type':_0x158fbc['type']['key']};});_0x259f0c['model']=_['map'](_0x303d44,'name');_0x259f0c[_0xf6c2('0x33')]=_[_0xf6c2('0x34')](_0x554447[_0xf6c2('0x33')]);_0x259f0c[_0xf6c2('0x35')]=_['intersection'](_0x259f0c['model'],_0x259f0c[_0xf6c2('0x33')]);_0x3d1689['attributes']=_[_0xf6c2('0x36')](_0x259f0c[_0xf6c2('0x37')],qs['fields'](_0x554447['query']['fields']));_0x3d1689[_0xf6c2('0x38')]=_0x3d1689[_0xf6c2('0x38')][_0xf6c2('0x39')]?_0x3d1689['attributes']:_0x259f0c['model'];if(!_0x554447[_0xf6c2('0x33')][_0xf6c2('0x3a')](_0xf6c2('0x3b'))){_0x3d1689[_0xf6c2('0x3c')]=qs[_0xf6c2('0x3c')](_0x554447[_0xf6c2('0x33')][_0xf6c2('0x3c')]);_0x3d1689[_0xf6c2('0x3d')]=qs[_0xf6c2('0x3d')](_0x554447[_0xf6c2('0x33')]['offset']);}_0x3d1689[_0xf6c2('0x3e')]=qs['sort'](_0x554447[_0xf6c2('0x33')][_0xf6c2('0x3f')]);_0x3d1689['where']=qs['filters'](_['pick'](_0x554447[_0xf6c2('0x33')],_0x259f0c[_0xf6c2('0x35')]));if(_0x554447[_0xf6c2('0x33')][_0xf6c2('0x40')]){_0x3d1689[_0xf6c2('0x41')]=_[_0xf6c2('0x42')](_0x3d1689[_0xf6c2('0x41')],{'$or':_[_0xf6c2('0x30')](_0x303d44,function(_0x23331b){if(_0x23331b['type']!==_0xf6c2('0x43')){var _0x4c4765={};_0x4c4765[_0x23331b['name']]={'$like':'%'+_0x554447['query']['filter']+'%'};return _0x4c4765;}})});}_0x3d1689=_[_0xf6c2('0x42')]({},_0x3d1689,_0x554447[_0xf6c2('0x44')]);var _0x2c86f1={'where':_0x3d1689[_0xf6c2('0x41')]};return db[_0xf6c2('0x45')][_0xf6c2('0x20')](_0x2c86f1)[_0xf6c2('0x2a')](function(_0x1e988e){_0x3e1dd0['count']=_0x1e988e;if(_0x554447[_0xf6c2('0x33')]['includeAll']){_0x3d1689[_0xf6c2('0x46')]=[{'all':!![]}];}return db[_0xf6c2('0x45')][_0xf6c2('0x47')](_0x3d1689);})[_0xf6c2('0x2a')](function(_0x573935){_0x3e1dd0[_0xf6c2('0x48')]=_0x573935;return _0x3e1dd0;})['then'](respondWithFilteredResult(_0x16d184,_0x3d1689))[_0xf6c2('0x49')](handleError(_0x16d184,null));};exports[_0xf6c2('0x4a')]=function(_0x113356,_0x2f8ab6){var _0xebd839={'raw':!![],'where':{'id':_0x113356[_0xf6c2('0x4b')]['id']}},_0x6b427a={};_0x6b427a[_0xf6c2('0x37')]=_['keys'](db[_0xf6c2('0x45')][_0xf6c2('0x31')]);_0x6b427a[_0xf6c2('0x33')]=_[_0xf6c2('0x34')](_0x113356[_0xf6c2('0x33')]);_0x6b427a[_0xf6c2('0x35')]=_[_0xf6c2('0x36')](_0x6b427a[_0xf6c2('0x37')],_0x6b427a[_0xf6c2('0x33')]);_0xebd839[_0xf6c2('0x38')]=_[_0xf6c2('0x36')](_0x6b427a[_0xf6c2('0x37')],qs[_0xf6c2('0x4c')](_0x113356[_0xf6c2('0x33')][_0xf6c2('0x4c')]));_0xebd839['attributes']=_0xebd839['attributes'][_0xf6c2('0x39')]?_0xebd839['attributes']:_0x6b427a[_0xf6c2('0x37')];if(_0x113356[_0xf6c2('0x33')][_0xf6c2('0x4d')]){_0xebd839['include']=[{'all':!![]}];}_0xebd839=_[_0xf6c2('0x42')]({},_0xebd839,_0x113356[_0xf6c2('0x44')]);return db['Variable'][_0xf6c2('0x4e')](_0xebd839)[_0xf6c2('0x2a')](handleEntityNotFound(_0x2f8ab6,null))[_0xf6c2('0x2a')](respondWithResult(_0x2f8ab6,null))[_0xf6c2('0x49')](handleError(_0x2f8ab6,null));};exports['create']=function(_0x1a4b38,_0x483c3b){return db[_0xf6c2('0x45')][_0xf6c2('0x4f')](_0x1a4b38[_0xf6c2('0x50')],{})[_0xf6c2('0x2a')](function(_0x27a055){var _0x5d7066=_0x1a4b38[_0xf6c2('0x51')][_0xf6c2('0x27')]({'plain':!![]});if(!_0x5d7066)throw new Error(_0xf6c2('0x52'));if(_0x5d7066[_0xf6c2('0x53')]===_0xf6c2('0x51')){var _0x307a9e=_0x27a055[_0xf6c2('0x27')]({'plain':!![]});var _0x271ea1=_0xf6c2('0x28');return db[_0xf6c2('0x54')][_0xf6c2('0x4e')]({'where':{'name':_0x271ea1,'userProfileId':_0x5d7066[_0xf6c2('0x55')]},'raw':!![]})[_0xf6c2('0x2a')](function(_0x1768f6){if(_0x1768f6&&_0x1768f6[_0xf6c2('0x56')]===0x0){return db[_0xf6c2('0x29')][_0xf6c2('0x4f')]({'name':_0x307a9e[_0xf6c2('0x2d')],'resourceId':_0x307a9e['id'],'type':_0x1768f6[_0xf6c2('0x2d')],'sectionId':_0x1768f6['id']},{})[_0xf6c2('0x2a')](function(){return _0x27a055;});}else{return _0x27a055;}})[_0xf6c2('0x49')](function(_0x195b69){logger[_0xf6c2('0x2b')](_0xf6c2('0x57'),_0x195b69);throw _0x195b69;});}return _0x27a055;})[_0xf6c2('0x2a')](respondWithResult(_0x483c3b,0xc9))[_0xf6c2('0x49')](handleError(_0x483c3b,null));};exports[_0xf6c2('0x25')]=function(_0x35baec,_0x4bd4ac){if(_0x35baec['body']['id']){delete _0x35baec[_0xf6c2('0x50')]['id'];}return db[_0xf6c2('0x45')][_0xf6c2('0x4e')]({'where':{'id':_0x35baec[_0xf6c2('0x4b')]['id']}})[_0xf6c2('0x2a')](handleEntityNotFound(_0x4bd4ac,null))[_0xf6c2('0x2a')](saveUpdates(_0x35baec[_0xf6c2('0x50')],null))[_0xf6c2('0x2a')](respondWithResult(_0x4bd4ac,null))[_0xf6c2('0x49')](handleError(_0x4bd4ac,null));};exports['destroy']=function(_0x468873,_0x2dc561){return db[_0xf6c2('0x45')]['find']({'where':{'id':_0x468873['params']['id']}})['then'](handleEntityNotFound(_0x2dc561,null))['then'](removeEntity(_0x2dc561,null))[_0xf6c2('0x49')](handleError(_0x2dc561,null));};