Built motion from commit 538092ac.|2.6.10
[motion2.git] / server / api / intDeskField / intDeskField.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 _0x81f8=['rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','include','findAll','rows','catch','params','options','find','create','body','destroy','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','reject','save','update','then','error','name','send','index','map','DeskField'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x81f8,0x186));var _0x881f=function(_0xe454c8,_0x3486d4){_0xe454c8=_0xe454c8-0x0;var _0x5724dd=_0x81f8[_0xe454c8];return _0x5724dd;};'use strict';var emlformat=require(_0x881f('0x0'));var rimraf=require(_0x881f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x881f('0x2'));var rp=require(_0x881f('0x3'));var moment=require(_0x881f('0x4'));var BPromise=require(_0x881f('0x5'));var Mustache=require(_0x881f('0x6'));var util=require('util');var path=require(_0x881f('0x7'));var sox=require(_0x881f('0x8'));var csv=require(_0x881f('0x9'));var ejs=require(_0x881f('0xa'));var fs=require('fs');var fs_extra=require(_0x881f('0xb'));var _=require(_0x881f('0xc'));var squel=require(_0x881f('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x881f('0xe'));var toCsv=require(_0x881f('0x9'));var querystring=require('querystring');var Papa=require(_0x881f('0xf'));var Redis=require(_0x881f('0x10'));var authService=require(_0x881f('0x11'));var qs=require(_0x881f('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x881f('0x13'))(_0x881f('0x14'));var utils=require(_0x881f('0x15'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x881f('0x16'))['db'];function respondWithStatusCode(_0x422ee5,_0x5ca80e){_0x5ca80e=_0x5ca80e||0xcc;return function(_0x5184bc){if(_0x5184bc){return _0x422ee5[_0x881f('0x17')](_0x5ca80e);}return _0x422ee5[_0x881f('0x18')](_0x5ca80e)[_0x881f('0x19')]();};}function respondWithResult(_0x52c140,_0x20036f){_0x20036f=_0x20036f||0xc8;return function(_0x1f51aa){if(_0x1f51aa){return _0x52c140['status'](_0x20036f)[_0x881f('0x1a')](_0x1f51aa);}};}function respondWithFilteredResult(_0x3d9e50,_0x4b7378){return function(_0x301d66){if(_0x301d66){var _0x167107=typeof _0x4b7378[_0x881f('0x1b')]===_0x881f('0x1c')&&typeof _0x4b7378[_0x881f('0x1d')]===_0x881f('0x1c');var _0x5e897f=_0x301d66[_0x881f('0x1e')];var _0x4f0540=_0x167107?0x0:_0x4b7378['offset'];var _0x1ed77=_0x167107?_0x301d66[_0x881f('0x1e')]:_0x4b7378[_0x881f('0x1b')]+_0x4b7378['limit'];var _0x49c605;if(_0x1ed77>=_0x5e897f){_0x1ed77=_0x5e897f;_0x49c605=0xc8;}else{_0x49c605=0xce;}_0x3d9e50[_0x881f('0x18')](_0x49c605);return _0x3d9e50['set'](_0x881f('0x1f'),_0x4f0540+'-'+_0x1ed77+'/'+_0x5e897f)[_0x881f('0x1a')](_0x301d66);}return null;};}function patchUpdates(_0x2f66d8){return function(_0x537c77){try{jsonpatch['apply'](_0x537c77,_0x2f66d8,!![]);}catch(_0x38f7a7){return BPromise[_0x881f('0x20')](_0x38f7a7);}return _0x537c77[_0x881f('0x21')]();};}function saveUpdates(_0x3fbbd1,_0x4f43ee){return function(_0x1b434d){if(_0x1b434d){return _0x1b434d[_0x881f('0x22')](_0x3fbbd1)[_0x881f('0x23')](function(_0x59c60e){return _0x59c60e;});}return null;};}function removeEntity(_0x16392b,_0x51bbb2){return function(_0x30d73b){if(_0x30d73b){return _0x30d73b['destroy']()[_0x881f('0x23')](function(){_0x16392b[_0x881f('0x18')](0xcc)[_0x881f('0x19')]();});}};}function handleEntityNotFound(_0x341e3c,_0x5f39cc){return function(_0x666de5){if(!_0x666de5){_0x341e3c[_0x881f('0x17')](0x194);}return _0x666de5;};}function handleError(_0x6f6a7e,_0xdcb6b7){_0xdcb6b7=_0xdcb6b7||0x1f4;return function(_0x393433){logger[_0x881f('0x24')](_0x393433['stack']);if(_0x393433[_0x881f('0x25')]){delete _0x393433[_0x881f('0x25')];}_0x6f6a7e[_0x881f('0x18')](_0xdcb6b7)[_0x881f('0x26')](_0x393433);};}exports[_0x881f('0x27')]=function(_0x518ddb,_0x56cc05){var _0x40d75b={},_0x11f353={},_0x2a5c8f={'count':0x0,'rows':[]};var _0x51f20f=_[_0x881f('0x28')](db[_0x881f('0x29')][_0x881f('0x2a')],function(_0x42ba3b){return{'name':_0x42ba3b[_0x881f('0x2b')],'type':_0x42ba3b[_0x881f('0x2c')][_0x881f('0x2d')]};});_0x11f353[_0x881f('0x2e')]=_[_0x881f('0x28')](_0x51f20f,_0x881f('0x25'));_0x11f353[_0x881f('0x2f')]=_[_0x881f('0x30')](_0x518ddb[_0x881f('0x2f')]);_0x11f353['filters']=_[_0x881f('0x31')](_0x11f353[_0x881f('0x2e')],_0x11f353[_0x881f('0x2f')]);_0x40d75b['attributes']=_[_0x881f('0x31')](_0x11f353[_0x881f('0x2e')],qs['fields'](_0x518ddb[_0x881f('0x2f')][_0x881f('0x32')]));_0x40d75b[_0x881f('0x33')]=_0x40d75b[_0x881f('0x33')][_0x881f('0x34')]?_0x40d75b[_0x881f('0x33')]:_0x11f353[_0x881f('0x2e')];if(!_0x518ddb[_0x881f('0x2f')][_0x881f('0x35')](_0x881f('0x36'))){_0x40d75b[_0x881f('0x1d')]=qs['limit'](_0x518ddb[_0x881f('0x2f')][_0x881f('0x1d')]);_0x40d75b['offset']=qs[_0x881f('0x1b')](_0x518ddb[_0x881f('0x2f')][_0x881f('0x1b')]);}_0x40d75b[_0x881f('0x37')]=qs[_0x881f('0x38')](_0x518ddb['query']['sort']);_0x40d75b[_0x881f('0x39')]=qs[_0x881f('0x3a')](_['pick'](_0x518ddb[_0x881f('0x2f')],_0x11f353['filters']),_0x51f20f);if(_0x518ddb[_0x881f('0x2f')][_0x881f('0x3b')]){_0x40d75b[_0x881f('0x39')]=_[_0x881f('0x3c')](_0x40d75b[_0x881f('0x39')],{'$or':_[_0x881f('0x28')](_0x51f20f,function(_0x5bab6b){if(_0x5bab6b[_0x881f('0x2c')]!==_0x881f('0x3d')){var _0x202e93={};_0x202e93[_0x5bab6b['name']]={'$like':'%'+_0x518ddb[_0x881f('0x2f')][_0x881f('0x3b')]+'%'};return _0x202e93;}})});}_0x40d75b=_[_0x881f('0x3c')]({},_0x40d75b,_0x518ddb['options']);var _0x47ff69={'where':_0x40d75b[_0x881f('0x39')]};return db[_0x881f('0x29')][_0x881f('0x1e')](_0x47ff69)[_0x881f('0x23')](function(_0x1557f2){_0x2a5c8f[_0x881f('0x1e')]=_0x1557f2;if(_0x518ddb['query']['includeAll']){_0x40d75b[_0x881f('0x3e')]=[{'all':!![]}];}return db['DeskField'][_0x881f('0x3f')](_0x40d75b);})['then'](function(_0x430a5e){_0x2a5c8f[_0x881f('0x40')]=_0x430a5e;return _0x2a5c8f;})[_0x881f('0x23')](respondWithFilteredResult(_0x56cc05,_0x40d75b))[_0x881f('0x41')](handleError(_0x56cc05,null));};exports['show']=function(_0x29369b,_0x506939){var _0x5a6aa8={'raw':!![],'where':{'id':_0x29369b[_0x881f('0x42')]['id']}},_0x2aa0aa={};_0x2aa0aa['model']=_[_0x881f('0x30')](db[_0x881f('0x29')][_0x881f('0x2a')]);_0x2aa0aa[_0x881f('0x2f')]=_[_0x881f('0x30')](_0x29369b['query']);_0x2aa0aa['filters']=_['intersection'](_0x2aa0aa[_0x881f('0x2e')],_0x2aa0aa[_0x881f('0x2f')]);_0x5a6aa8[_0x881f('0x33')]=_[_0x881f('0x31')](_0x2aa0aa[_0x881f('0x2e')],qs[_0x881f('0x32')](_0x29369b[_0x881f('0x2f')][_0x881f('0x32')]));_0x5a6aa8['attributes']=_0x5a6aa8[_0x881f('0x33')][_0x881f('0x34')]?_0x5a6aa8['attributes']:_0x2aa0aa[_0x881f('0x2e')];if(_0x29369b[_0x881f('0x2f')]['includeAll']){_0x5a6aa8['include']=[{'all':!![]}];}_0x5a6aa8=_[_0x881f('0x3c')]({},_0x5a6aa8,_0x29369b[_0x881f('0x43')]);return db['DeskField'][_0x881f('0x44')](_0x5a6aa8)['then'](handleEntityNotFound(_0x506939,null))['then'](respondWithResult(_0x506939,null))['catch'](handleError(_0x506939,null));};exports[_0x881f('0x45')]=function(_0x4db36c,_0xa3a79e){return db[_0x881f('0x29')][_0x881f('0x45')](_0x4db36c[_0x881f('0x46')],{})[_0x881f('0x23')](respondWithResult(_0xa3a79e,0xc9))[_0x881f('0x41')](handleError(_0xa3a79e,null));};exports[_0x881f('0x22')]=function(_0x3d7229,_0x13bee8){if(_0x3d7229[_0x881f('0x46')]['id']){delete _0x3d7229[_0x881f('0x46')]['id'];}return db[_0x881f('0x29')][_0x881f('0x44')]({'where':{'id':_0x3d7229[_0x881f('0x42')]['id']}})[_0x881f('0x23')](handleEntityNotFound(_0x13bee8,null))['then'](saveUpdates(_0x3d7229[_0x881f('0x46')],null))[_0x881f('0x23')](respondWithResult(_0x13bee8,null))['catch'](handleError(_0x13bee8,null));};exports[_0x881f('0x47')]=function(_0x3e051c,_0x424104){return db[_0x881f('0x29')][_0x881f('0x44')]({'where':{'id':_0x3e051c[_0x881f('0x42')]['id']}})[_0x881f('0x23')](handleEntityNotFound(_0x424104,null))[_0x881f('0x23')](removeEntity(_0x424104,null))[_0x881f('0x41')](handleError(_0x424104,null));};