Built motion from commit ab870f9e.|2.5.44
[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 _0x0b3d=['status','end','json','offset','limit','undefined','count','set','apply','reject','save','then','error','stack','name','send','DeskField','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filters','pick','filter','merge','map','VIRTUAL','options','includeAll','include','findAll','rows','find','catch','create','body','update','params','destroy','eml-format','zip-dir','request-promise','bluebird','util','sox','to-csv','fs-extra','squel','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','sendStatus'];(function(_0x23ed5d,_0x25c460){var _0x12fbdd=function(_0x8dc30){while(--_0x8dc30){_0x23ed5d['push'](_0x23ed5d['shift']());}};_0x12fbdd(++_0x25c460);}(_0x0b3d,0x76));var _0xd0b3=function(_0x3bb954,_0x5173dd){_0x3bb954=_0x3bb954-0x0;var _0x3d96a3=_0x0b3d[_0x3bb954];return _0x3d96a3;};'use strict';var emlformat=require(_0xd0b3('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xd0b3('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xd0b3('0x2'));var moment=require('moment');var BPromise=require(_0xd0b3('0x3'));var Mustache=require('mustache');var util=require(_0xd0b3('0x4'));var path=require('path');var sox=require(_0xd0b3('0x5'));var csv=require(_0xd0b3('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xd0b3('0x7'));var _=require('lodash');var squel=require(_0xd0b3('0x8'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xd0b3('0x9'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xd0b3('0xa'));var Redis=require('ioredis');var authService=require(_0xd0b3('0xb'));var qs=require(_0xd0b3('0xc'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xd0b3('0xd'))(_0xd0b3('0xe'));var utils=require(_0xd0b3('0xf'));var config=require(_0xd0b3('0x10'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x97ca75,_0x2202ec){_0x2202ec=_0x2202ec||0xcc;return function(_0x43af8d){if(_0x43af8d){return _0x97ca75[_0xd0b3('0x11')](_0x2202ec);}return _0x97ca75[_0xd0b3('0x12')](_0x2202ec)[_0xd0b3('0x13')]();};}function respondWithResult(_0x2e4734,_0x5af82f){_0x5af82f=_0x5af82f||0xc8;return function(_0x2d1376){if(_0x2d1376){return _0x2e4734[_0xd0b3('0x12')](_0x5af82f)[_0xd0b3('0x14')](_0x2d1376);}};}function respondWithFilteredResult(_0x28d379,_0x49bfde){return function(_0xd7a36e){if(_0xd7a36e){var _0x1426cc=typeof _0x49bfde[_0xd0b3('0x15')]==='undefined'&&typeof _0x49bfde[_0xd0b3('0x16')]===_0xd0b3('0x17');var _0x50ea99=_0xd7a36e[_0xd0b3('0x18')];var _0x232e6a=_0x1426cc?0x0:_0x49bfde['offset'];var _0x4ed917=_0x1426cc?_0xd7a36e[_0xd0b3('0x18')]:_0x49bfde[_0xd0b3('0x15')]+_0x49bfde['limit'];var _0x8176e2;if(_0x4ed917>=_0x50ea99){_0x4ed917=_0x50ea99;_0x8176e2=0xc8;}else{_0x8176e2=0xce;}_0x28d379[_0xd0b3('0x12')](_0x8176e2);return _0x28d379[_0xd0b3('0x19')]('Content-Range',_0x232e6a+'-'+_0x4ed917+'/'+_0x50ea99)['json'](_0xd7a36e);}return null;};}function patchUpdates(_0xbd82dc){return function(_0x4f755f){try{jsonpatch[_0xd0b3('0x1a')](_0x4f755f,_0xbd82dc,!![]);}catch(_0x1d023d){return BPromise[_0xd0b3('0x1b')](_0x1d023d);}return _0x4f755f[_0xd0b3('0x1c')]();};}function saveUpdates(_0x155add,_0x553c27){return function(_0x55261e){if(_0x55261e){return _0x55261e['update'](_0x155add)[_0xd0b3('0x1d')](function(_0x40a637){return _0x40a637;});}return null;};}function removeEntity(_0x1a84a5,_0x1bfe7b){return function(_0x1ac0cd){if(_0x1ac0cd){return _0x1ac0cd['destroy']()[_0xd0b3('0x1d')](function(){_0x1a84a5[_0xd0b3('0x12')](0xcc)[_0xd0b3('0x13')]();});}};}function handleEntityNotFound(_0x2e0dcc,_0x550d35){return function(_0x259e05){if(!_0x259e05){_0x2e0dcc[_0xd0b3('0x11')](0x194);}return _0x259e05;};}function handleError(_0x1a1d36,_0x52606c){_0x52606c=_0x52606c||0x1f4;return function(_0x48fb43){logger[_0xd0b3('0x1e')](_0x48fb43[_0xd0b3('0x1f')]);if(_0x48fb43[_0xd0b3('0x20')]){delete _0x48fb43['name'];}_0x1a1d36[_0xd0b3('0x12')](_0x52606c)[_0xd0b3('0x21')](_0x48fb43);};}exports['index']=function(_0x1e4c8f,_0x43bfe7){var _0x52f324={},_0x2b2d05={},_0x47cc10={'count':0x0,'rows':[]};var _0x400a9d=_['map'](db[_0xd0b3('0x22')][_0xd0b3('0x23')],function(_0xbb9663){return{'name':_0xbb9663[_0xd0b3('0x24')],'type':_0xbb9663[_0xd0b3('0x25')][_0xd0b3('0x26')]};});_0x2b2d05[_0xd0b3('0x27')]=_['map'](_0x400a9d,_0xd0b3('0x20'));_0x2b2d05[_0xd0b3('0x28')]=_[_0xd0b3('0x29')](_0x1e4c8f[_0xd0b3('0x28')]);_0x2b2d05['filters']=_[_0xd0b3('0x2a')](_0x2b2d05[_0xd0b3('0x27')],_0x2b2d05[_0xd0b3('0x28')]);_0x52f324[_0xd0b3('0x2b')]=_['intersection'](_0x2b2d05[_0xd0b3('0x27')],qs[_0xd0b3('0x2c')](_0x1e4c8f[_0xd0b3('0x28')][_0xd0b3('0x2c')]));_0x52f324[_0xd0b3('0x2b')]=_0x52f324[_0xd0b3('0x2b')][_0xd0b3('0x2d')]?_0x52f324[_0xd0b3('0x2b')]:_0x2b2d05[_0xd0b3('0x27')];if(!_0x1e4c8f[_0xd0b3('0x28')][_0xd0b3('0x2e')](_0xd0b3('0x2f'))){_0x52f324[_0xd0b3('0x16')]=qs[_0xd0b3('0x16')](_0x1e4c8f['query'][_0xd0b3('0x16')]);_0x52f324[_0xd0b3('0x15')]=qs[_0xd0b3('0x15')](_0x1e4c8f[_0xd0b3('0x28')]['offset']);}_0x52f324['order']=qs['sort'](_0x1e4c8f[_0xd0b3('0x28')][_0xd0b3('0x30')]);_0x52f324[_0xd0b3('0x31')]=qs[_0xd0b3('0x32')](_[_0xd0b3('0x33')](_0x1e4c8f[_0xd0b3('0x28')],_0x2b2d05['filters']),_0x400a9d);if(_0x1e4c8f[_0xd0b3('0x28')][_0xd0b3('0x34')]){_0x52f324[_0xd0b3('0x31')]=_[_0xd0b3('0x35')](_0x52f324[_0xd0b3('0x31')],{'$or':_[_0xd0b3('0x36')](_0x400a9d,function(_0x34477e){if(_0x34477e[_0xd0b3('0x25')]!==_0xd0b3('0x37')){var _0x536e23={};_0x536e23[_0x34477e[_0xd0b3('0x20')]]={'$like':'%'+_0x1e4c8f['query']['filter']+'%'};return _0x536e23;}})});}_0x52f324=_[_0xd0b3('0x35')]({},_0x52f324,_0x1e4c8f[_0xd0b3('0x38')]);var _0x2c402c={'where':_0x52f324[_0xd0b3('0x31')]};return db[_0xd0b3('0x22')][_0xd0b3('0x18')](_0x2c402c)['then'](function(_0x463749){_0x47cc10['count']=_0x463749;if(_0x1e4c8f[_0xd0b3('0x28')][_0xd0b3('0x39')]){_0x52f324[_0xd0b3('0x3a')]=[{'all':!![]}];}return db[_0xd0b3('0x22')][_0xd0b3('0x3b')](_0x52f324);})['then'](function(_0x54b345){_0x47cc10[_0xd0b3('0x3c')]=_0x54b345;return _0x47cc10;})[_0xd0b3('0x1d')](respondWithFilteredResult(_0x43bfe7,_0x52f324))['catch'](handleError(_0x43bfe7,null));};exports['show']=function(_0x47b367,_0x3f852f){var _0x175caa={'raw':!![],'where':{'id':_0x47b367['params']['id']}},_0x2fe65={};_0x2fe65['model']=_[_0xd0b3('0x29')](db[_0xd0b3('0x22')][_0xd0b3('0x23')]);_0x2fe65[_0xd0b3('0x28')]=_['keys'](_0x47b367[_0xd0b3('0x28')]);_0x2fe65['filters']=_[_0xd0b3('0x2a')](_0x2fe65['model'],_0x2fe65[_0xd0b3('0x28')]);_0x175caa[_0xd0b3('0x2b')]=_['intersection'](_0x2fe65['model'],qs['fields'](_0x47b367[_0xd0b3('0x28')][_0xd0b3('0x2c')]));_0x175caa[_0xd0b3('0x2b')]=_0x175caa['attributes'][_0xd0b3('0x2d')]?_0x175caa[_0xd0b3('0x2b')]:_0x2fe65[_0xd0b3('0x27')];if(_0x47b367[_0xd0b3('0x28')][_0xd0b3('0x39')]){_0x175caa[_0xd0b3('0x3a')]=[{'all':!![]}];}_0x175caa=_['merge']({},_0x175caa,_0x47b367[_0xd0b3('0x38')]);return db['DeskField'][_0xd0b3('0x3d')](_0x175caa)[_0xd0b3('0x1d')](handleEntityNotFound(_0x3f852f,null))[_0xd0b3('0x1d')](respondWithResult(_0x3f852f,null))[_0xd0b3('0x3e')](handleError(_0x3f852f,null));};exports[_0xd0b3('0x3f')]=function(_0x3e666e,_0x31860b){return db[_0xd0b3('0x22')]['create'](_0x3e666e[_0xd0b3('0x40')],{})[_0xd0b3('0x1d')](respondWithResult(_0x31860b,0xc9))[_0xd0b3('0x3e')](handleError(_0x31860b,null));};exports[_0xd0b3('0x41')]=function(_0x29eaf2,_0x1478cc){if(_0x29eaf2[_0xd0b3('0x40')]['id']){delete _0x29eaf2[_0xd0b3('0x40')]['id'];}return db['DeskField']['find']({'where':{'id':_0x29eaf2[_0xd0b3('0x42')]['id']}})['then'](handleEntityNotFound(_0x1478cc,null))['then'](saveUpdates(_0x29eaf2[_0xd0b3('0x40')],null))[_0xd0b3('0x1d')](respondWithResult(_0x1478cc,null))[_0xd0b3('0x3e')](handleError(_0x1478cc,null));};exports[_0xd0b3('0x43')]=function(_0x474f37,_0x292d2b){return db[_0xd0b3('0x22')][_0xd0b3('0x3d')]({'where':{'id':_0x474f37[_0xd0b3('0x42')]['id']}})['then'](handleEntityNotFound(_0x292d2b,null))['then'](removeEntity(_0x292d2b,null))['catch'](handleError(_0x292d2b,null));};