Built motion from commit 85328c08.|2.5.50
[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 _0xf198=['jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','apply','reject','save','then','destroy','end','error','stack','name','send','index','map','DeskField','key','keys','query','filters','attributes','intersection','model','fields','length','nolimit','order','sort','where','merge','type','VIRTUAL','filter','options','include','rows','show','params','rawAttributes','includeAll','catch','create','body','find','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto'];(function(_0x53bcc3,_0x364374){var _0x47c959=function(_0x40ef7d){while(--_0x40ef7d){_0x53bcc3['push'](_0x53bcc3['shift']());}};_0x47c959(++_0x364374);}(_0xf198,0xd1));var _0x8f19=function(_0x522974,_0x4245f3){_0x522974=_0x522974-0x0;var _0x332fb4=_0xf198[_0x522974];return _0x332fb4;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8f19('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8f19('0x1'));var rp=require(_0x8f19('0x2'));var moment=require(_0x8f19('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x8f19('0x4'));var util=require(_0x8f19('0x5'));var path=require(_0x8f19('0x6'));var sox=require(_0x8f19('0x7'));var csv=require(_0x8f19('0x8'));var ejs=require(_0x8f19('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x8f19('0xa'));var squel=require(_0x8f19('0xb'));var crypto=require(_0x8f19('0xc'));var jsforce=require(_0x8f19('0xd'));var deskjs=require(_0x8f19('0xe'));var toCsv=require(_0x8f19('0x8'));var querystring=require('querystring');var Papa=require(_0x8f19('0xf'));var Redis=require(_0x8f19('0x10'));var authService=require(_0x8f19('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x8f19('0x12'));var hardwareService=require(_0x8f19('0x13'));var logger=require(_0x8f19('0x14'))(_0x8f19('0x15'));var utils=require('../../config/utils');var config=require(_0x8f19('0x16'));var licenseUtil=require(_0x8f19('0x17'));var db=require(_0x8f19('0x18'))['db'];function respondWithStatusCode(_0x1afe2f,_0x18cb33){_0x18cb33=_0x18cb33||0xcc;return function(_0xd01cf6){if(_0xd01cf6){return _0x1afe2f[_0x8f19('0x19')](_0x18cb33);}return _0x1afe2f[_0x8f19('0x1a')](_0x18cb33)['end']();};}function respondWithResult(_0x19a6f2,_0x3d4e76){_0x3d4e76=_0x3d4e76||0xc8;return function(_0x3df500){if(_0x3df500){return _0x19a6f2[_0x8f19('0x1a')](_0x3d4e76)[_0x8f19('0x1b')](_0x3df500);}};}function respondWithFilteredResult(_0x47bae1,_0x81f091){return function(_0x31d441){if(_0x31d441){var _0x43e309=typeof _0x81f091[_0x8f19('0x1c')]===_0x8f19('0x1d')&&typeof _0x81f091[_0x8f19('0x1e')]==='undefined';var _0x5ab156=_0x31d441[_0x8f19('0x1f')];var _0x578607=_0x43e309?0x0:_0x81f091['offset'];var _0x5c3b69=_0x43e309?_0x31d441[_0x8f19('0x1f')]:_0x81f091[_0x8f19('0x1c')]+_0x81f091[_0x8f19('0x1e')];var _0x15df5b;if(_0x5c3b69>=_0x5ab156){_0x5c3b69=_0x5ab156;_0x15df5b=0xc8;}else{_0x15df5b=0xce;}_0x47bae1['status'](_0x15df5b);return _0x47bae1[_0x8f19('0x20')]('Content-Range',_0x578607+'-'+_0x5c3b69+'/'+_0x5ab156)[_0x8f19('0x1b')](_0x31d441);}return null;};}function patchUpdates(_0x16d351){return function(_0x151ad7){try{jsonpatch[_0x8f19('0x21')](_0x151ad7,_0x16d351,!![]);}catch(_0x5348cf){return BPromise[_0x8f19('0x22')](_0x5348cf);}return _0x151ad7[_0x8f19('0x23')]();};}function saveUpdates(_0x5d99a0,_0x2a0ab0){return function(_0x2b5852){if(_0x2b5852){return _0x2b5852['update'](_0x5d99a0)[_0x8f19('0x24')](function(_0x5b00fe){return _0x5b00fe;});}return null;};}function removeEntity(_0xe66f7c,_0x4d340d){return function(_0x409449){if(_0x409449){return _0x409449[_0x8f19('0x25')]()[_0x8f19('0x24')](function(){_0xe66f7c[_0x8f19('0x1a')](0xcc)[_0x8f19('0x26')]();});}};}function handleEntityNotFound(_0x2a8395,_0x5854ac){return function(_0x4c2e19){if(!_0x4c2e19){_0x2a8395[_0x8f19('0x19')](0x194);}return _0x4c2e19;};}function handleError(_0x11d990,_0x41b5d5){_0x41b5d5=_0x41b5d5||0x1f4;return function(_0x59a812){logger[_0x8f19('0x27')](_0x59a812[_0x8f19('0x28')]);if(_0x59a812[_0x8f19('0x29')]){delete _0x59a812[_0x8f19('0x29')];}_0x11d990['status'](_0x41b5d5)[_0x8f19('0x2a')](_0x59a812);};}exports[_0x8f19('0x2b')]=function(_0x282980,_0x365210){var _0x4ab178={},_0x101d71={},_0x2b150e={'count':0x0,'rows':[]};var _0x38ee66=_[_0x8f19('0x2c')](db[_0x8f19('0x2d')]['rawAttributes'],function(_0x251171){return{'name':_0x251171['fieldName'],'type':_0x251171['type'][_0x8f19('0x2e')]};});_0x101d71['model']=_[_0x8f19('0x2c')](_0x38ee66,_0x8f19('0x29'));_0x101d71['query']=_[_0x8f19('0x2f')](_0x282980[_0x8f19('0x30')]);_0x101d71[_0x8f19('0x31')]=_['intersection'](_0x101d71['model'],_0x101d71[_0x8f19('0x30')]);_0x4ab178[_0x8f19('0x32')]=_[_0x8f19('0x33')](_0x101d71[_0x8f19('0x34')],qs[_0x8f19('0x35')](_0x282980[_0x8f19('0x30')][_0x8f19('0x35')]));_0x4ab178[_0x8f19('0x32')]=_0x4ab178[_0x8f19('0x32')][_0x8f19('0x36')]?_0x4ab178['attributes']:_0x101d71['model'];if(!_0x282980['query']['hasOwnProperty'](_0x8f19('0x37'))){_0x4ab178[_0x8f19('0x1e')]=qs[_0x8f19('0x1e')](_0x282980[_0x8f19('0x30')][_0x8f19('0x1e')]);_0x4ab178[_0x8f19('0x1c')]=qs['offset'](_0x282980['query'][_0x8f19('0x1c')]);}_0x4ab178[_0x8f19('0x38')]=qs['sort'](_0x282980[_0x8f19('0x30')][_0x8f19('0x39')]);_0x4ab178['where']=qs[_0x8f19('0x31')](_['pick'](_0x282980['query'],_0x101d71[_0x8f19('0x31')]),_0x38ee66);if(_0x282980[_0x8f19('0x30')]['filter']){_0x4ab178[_0x8f19('0x3a')]=_[_0x8f19('0x3b')](_0x4ab178[_0x8f19('0x3a')],{'$or':_[_0x8f19('0x2c')](_0x38ee66,function(_0x52811f){if(_0x52811f[_0x8f19('0x3c')]!==_0x8f19('0x3d')){var _0x3d9e26={};_0x3d9e26[_0x52811f[_0x8f19('0x29')]]={'$like':'%'+_0x282980[_0x8f19('0x30')][_0x8f19('0x3e')]+'%'};return _0x3d9e26;}})});}_0x4ab178=_[_0x8f19('0x3b')]({},_0x4ab178,_0x282980[_0x8f19('0x3f')]);var _0x13c77a={'where':_0x4ab178['where']};return db[_0x8f19('0x2d')][_0x8f19('0x1f')](_0x13c77a)[_0x8f19('0x24')](function(_0x53a79d){_0x2b150e[_0x8f19('0x1f')]=_0x53a79d;if(_0x282980[_0x8f19('0x30')]['includeAll']){_0x4ab178[_0x8f19('0x40')]=[{'all':!![]}];}return db[_0x8f19('0x2d')]['findAll'](_0x4ab178);})[_0x8f19('0x24')](function(_0x3377b1){_0x2b150e[_0x8f19('0x41')]=_0x3377b1;return _0x2b150e;})[_0x8f19('0x24')](respondWithFilteredResult(_0x365210,_0x4ab178))['catch'](handleError(_0x365210,null));};exports[_0x8f19('0x42')]=function(_0x4750b5,_0x49200c){var _0x53aa13={'raw':!![],'where':{'id':_0x4750b5[_0x8f19('0x43')]['id']}},_0x37d8bd={};_0x37d8bd[_0x8f19('0x34')]=_[_0x8f19('0x2f')](db['DeskField'][_0x8f19('0x44')]);_0x37d8bd[_0x8f19('0x30')]=_['keys'](_0x4750b5['query']);_0x37d8bd[_0x8f19('0x31')]=_[_0x8f19('0x33')](_0x37d8bd[_0x8f19('0x34')],_0x37d8bd[_0x8f19('0x30')]);_0x53aa13[_0x8f19('0x32')]=_[_0x8f19('0x33')](_0x37d8bd[_0x8f19('0x34')],qs[_0x8f19('0x35')](_0x4750b5[_0x8f19('0x30')][_0x8f19('0x35')]));_0x53aa13['attributes']=_0x53aa13[_0x8f19('0x32')][_0x8f19('0x36')]?_0x53aa13[_0x8f19('0x32')]:_0x37d8bd[_0x8f19('0x34')];if(_0x4750b5[_0x8f19('0x30')][_0x8f19('0x45')]){_0x53aa13['include']=[{'all':!![]}];}_0x53aa13=_['merge']({},_0x53aa13,_0x4750b5['options']);return db['DeskField']['find'](_0x53aa13)[_0x8f19('0x24')](handleEntityNotFound(_0x49200c,null))[_0x8f19('0x24')](respondWithResult(_0x49200c,null))[_0x8f19('0x46')](handleError(_0x49200c,null));};exports[_0x8f19('0x47')]=function(_0x383890,_0x57c5d6){return db['DeskField'][_0x8f19('0x47')](_0x383890['body'],{})[_0x8f19('0x24')](respondWithResult(_0x57c5d6,0xc9))[_0x8f19('0x46')](handleError(_0x57c5d6,null));};exports['update']=function(_0x3e664f,_0x3f4df5){if(_0x3e664f['body']['id']){delete _0x3e664f[_0x8f19('0x48')]['id'];}return db['DeskField'][_0x8f19('0x49')]({'where':{'id':_0x3e664f[_0x8f19('0x43')]['id']}})[_0x8f19('0x24')](handleEntityNotFound(_0x3f4df5,null))[_0x8f19('0x24')](saveUpdates(_0x3e664f[_0x8f19('0x48')],null))[_0x8f19('0x24')](respondWithResult(_0x3f4df5,null))['catch'](handleError(_0x3f4df5,null));};exports[_0x8f19('0x25')]=function(_0x36dae5,_0xe179ee){return db[_0x8f19('0x2d')][_0x8f19('0x49')]({'where':{'id':_0x36dae5[_0x8f19('0x43')]['id']}})[_0x8f19('0x24')](handleEntityNotFound(_0xe179ee,null))[_0x8f19('0x24')](removeEntity(_0xe179ee,null))[_0x8f19('0x46')](handleError(_0xe179ee,null));};