7458e01ac074f3bee0e8d870ede10d3f99c0bc43
[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 _0x09f5=['set','Content-Range','apply','then','destroy','error','stack','name','send','index','DeskField','rawAttributes','fieldName','type','key','map','query','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','keys','intersection','find','create','update','body','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','to-csv','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit'];(function(_0x56ee7e,_0x5264e7){var _0x41d6e6=function(_0x542daf){while(--_0x542daf){_0x56ee7e['push'](_0x56ee7e['shift']());}};_0x41d6e6(++_0x5264e7);}(_0x09f5,0x1ee));var _0x509f=function(_0x100528,_0x352759){_0x100528=_0x100528-0x0;var _0x2fb6a0=_0x09f5[_0x100528];return _0x2fb6a0;};'use strict';var pdf=require(_0x509f('0x0'));var emlformat=require(_0x509f('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x509f('0x2'));var jsonpatch=require(_0x509f('0x3'));var rp=require(_0x509f('0x4'));var moment=require(_0x509f('0x5'));var BPromise=require(_0x509f('0x6'));var Mustache=require(_0x509f('0x7'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0x509f('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x509f('0x9'));var squel=require('squel');var crypto=require(_0x509f('0xa'));var jsforce=require(_0x509f('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x509f('0x8'));var querystring=require(_0x509f('0xc'));var Papa=require(_0x509f('0xd'));var Redis=require(_0x509f('0xe'));var authService=require(_0x509f('0xf'));var qs=require(_0x509f('0x10'));var as=require(_0x509f('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x509f('0x12'))(_0x509f('0x13'));var utils=require(_0x509f('0x14'));var config=require(_0x509f('0x15'));var licenseUtil=require(_0x509f('0x16'));var db=require(_0x509f('0x17'))['db'];function respondWithStatusCode(_0x5022a5,_0xebb969){_0xebb969=_0xebb969||0xcc;return function(_0x4feb11){if(_0x4feb11){return _0x5022a5[_0x509f('0x18')](_0xebb969);}return _0x5022a5[_0x509f('0x19')](_0xebb969)[_0x509f('0x1a')]();};}function respondWithResult(_0x21a7b4,_0x6980fe){_0x6980fe=_0x6980fe||0xc8;return function(_0x4fa0a6){if(_0x4fa0a6){return _0x21a7b4[_0x509f('0x19')](_0x6980fe)[_0x509f('0x1b')](_0x4fa0a6);}};}function respondWithFilteredResult(_0xbb9639,_0x47a498){return function(_0xeecddb){if(_0xeecddb){var _0x40253f=_0xeecddb[_0x509f('0x1c')],_0x2f33c4=_0x47a498[_0x509f('0x1d')],_0x1dc339=_0x47a498[_0x509f('0x1d')]+_0x47a498[_0x509f('0x1e')],_0x5adc2c;if(_0x1dc339>=_0x40253f){_0x1dc339=_0x40253f;_0x5adc2c=0xc8;}else{_0x5adc2c=0xce;}_0xbb9639[_0x509f('0x19')](_0x5adc2c);return _0xbb9639[_0x509f('0x1f')](_0x509f('0x20'),_0x2f33c4+'-'+_0x1dc339+'/'+_0x40253f)['json'](_0xeecddb);}return null;};}function patchUpdates(_0xca4ceb){return function(_0x2ea22d){try{jsonpatch[_0x509f('0x21')](_0x2ea22d,_0xca4ceb,!![]);}catch(_0x469ef6){return BPromise['reject'](_0x469ef6);}return _0x2ea22d['save']();};}function saveUpdates(_0x1928cc,_0x39b501){return function(_0x8f2332){if(_0x8f2332){return _0x8f2332['update'](_0x1928cc)[_0x509f('0x22')](function(_0x4eb301){return _0x4eb301;});}return null;};}function removeEntity(_0x4ca6e6,_0x4f78ba){return function(_0xad2e13){if(_0xad2e13){return _0xad2e13[_0x509f('0x23')]()['then'](function(){_0x4ca6e6['status'](0xcc)[_0x509f('0x1a')]();});}};}function handleEntityNotFound(_0x12f83d,_0x3f3a48){return function(_0x48140c){if(!_0x48140c){_0x12f83d[_0x509f('0x18')](0x194);}return _0x48140c;};}function handleError(_0x43ce37,_0x27dd6e){_0x27dd6e=_0x27dd6e||0x1f4;return function(_0x476d3e){logger[_0x509f('0x24')](_0x476d3e[_0x509f('0x25')]);if(_0x476d3e[_0x509f('0x26')]){delete _0x476d3e[_0x509f('0x26')];}_0x43ce37['status'](_0x27dd6e)[_0x509f('0x27')](_0x476d3e);};}exports[_0x509f('0x28')]=function(_0x2c89e4,_0x5deab7){var _0x3039cf={},_0x59a486={},_0x447ec5={'count':0x0,'rows':[]};var _0x97c439=_['map'](db[_0x509f('0x29')][_0x509f('0x2a')],function(_0x401e5d){return{'name':_0x401e5d[_0x509f('0x2b')],'type':_0x401e5d[_0x509f('0x2c')][_0x509f('0x2d')]};});_0x59a486['model']=_[_0x509f('0x2e')](_0x97c439,_0x509f('0x26'));_0x59a486[_0x509f('0x2f')]=_['keys'](_0x2c89e4[_0x509f('0x2f')]);_0x59a486['filters']=_['intersection'](_0x59a486[_0x509f('0x30')],_0x59a486['query']);_0x3039cf[_0x509f('0x31')]=_['intersection'](_0x59a486[_0x509f('0x30')],qs[_0x509f('0x32')](_0x2c89e4[_0x509f('0x2f')][_0x509f('0x32')]));_0x3039cf['attributes']=_0x3039cf[_0x509f('0x31')][_0x509f('0x33')]?_0x3039cf[_0x509f('0x31')]:_0x59a486[_0x509f('0x30')];if(!_0x2c89e4[_0x509f('0x2f')][_0x509f('0x34')](_0x509f('0x35'))){_0x3039cf[_0x509f('0x1e')]=qs[_0x509f('0x1e')](_0x2c89e4['query']['limit']);_0x3039cf[_0x509f('0x1d')]=qs[_0x509f('0x1d')](_0x2c89e4[_0x509f('0x2f')][_0x509f('0x1d')]);}_0x3039cf[_0x509f('0x36')]=qs[_0x509f('0x37')](_0x2c89e4[_0x509f('0x2f')][_0x509f('0x37')]);_0x3039cf[_0x509f('0x38')]=qs['filters'](_[_0x509f('0x39')](_0x2c89e4[_0x509f('0x2f')],_0x59a486[_0x509f('0x3a')]),_0x97c439);if(_0x2c89e4[_0x509f('0x2f')][_0x509f('0x3b')]){_0x3039cf['where']=_[_0x509f('0x3c')](_0x3039cf[_0x509f('0x38')],{'$or':_[_0x509f('0x2e')](_0x97c439,function(_0x4fe4fd){if(_0x4fe4fd[_0x509f('0x2c')]!==_0x509f('0x3d')){var _0x53a63f={};_0x53a63f[_0x4fe4fd[_0x509f('0x26')]]={'$like':'%'+_0x2c89e4['query'][_0x509f('0x3b')]+'%'};return _0x53a63f;}})});}_0x3039cf=_[_0x509f('0x3c')]({},_0x3039cf,_0x2c89e4[_0x509f('0x3e')]);var _0x2f350f={'where':_0x3039cf[_0x509f('0x38')]};return db[_0x509f('0x29')][_0x509f('0x1c')](_0x2f350f)[_0x509f('0x22')](function(_0x6f6a30){_0x447ec5[_0x509f('0x1c')]=_0x6f6a30;if(_0x2c89e4[_0x509f('0x2f')][_0x509f('0x3f')]){_0x3039cf[_0x509f('0x40')]=[{'all':!![]}];}return db[_0x509f('0x29')][_0x509f('0x41')](_0x3039cf);})['then'](function(_0x2a8d3e){_0x447ec5['rows']=_0x2a8d3e;return _0x447ec5;})['then'](respondWithFilteredResult(_0x5deab7,_0x3039cf))[_0x509f('0x42')](handleError(_0x5deab7,null));};exports[_0x509f('0x43')]=function(_0x190a0a,_0x41f8bd){var _0x15f3c9={'raw':!![],'where':{'id':_0x190a0a[_0x509f('0x44')]['id']}},_0x31fe0a={};_0x31fe0a[_0x509f('0x30')]=_[_0x509f('0x45')](db['DeskField'][_0x509f('0x2a')]);_0x31fe0a[_0x509f('0x2f')]=_[_0x509f('0x45')](_0x190a0a['query']);_0x31fe0a['filters']=_[_0x509f('0x46')](_0x31fe0a[_0x509f('0x30')],_0x31fe0a[_0x509f('0x2f')]);_0x15f3c9[_0x509f('0x31')]=_[_0x509f('0x46')](_0x31fe0a[_0x509f('0x30')],qs[_0x509f('0x32')](_0x190a0a['query'][_0x509f('0x32')]));_0x15f3c9['attributes']=_0x15f3c9['attributes'][_0x509f('0x33')]?_0x15f3c9[_0x509f('0x31')]:_0x31fe0a[_0x509f('0x30')];if(_0x190a0a['query'][_0x509f('0x3f')]){_0x15f3c9[_0x509f('0x40')]=[{'all':!![]}];}_0x15f3c9=_[_0x509f('0x3c')]({},_0x15f3c9,_0x190a0a['options']);return db['DeskField'][_0x509f('0x47')](_0x15f3c9)[_0x509f('0x22')](handleEntityNotFound(_0x41f8bd,null))['then'](respondWithResult(_0x41f8bd,null))[_0x509f('0x42')](handleError(_0x41f8bd,null));};exports[_0x509f('0x48')]=function(_0x23a686,_0x3bc81e){return db[_0x509f('0x29')]['create'](_0x23a686['body'],{})['then'](respondWithResult(_0x3bc81e,0xc9))[_0x509f('0x42')](handleError(_0x3bc81e,null));};exports[_0x509f('0x49')]=function(_0x46ebe6,_0x247a4d){if(_0x46ebe6[_0x509f('0x4a')]['id']){delete _0x46ebe6['body']['id'];}return db['DeskField']['find']({'where':{'id':_0x46ebe6[_0x509f('0x44')]['id']}})['then'](handleEntityNotFound(_0x247a4d,null))['then'](saveUpdates(_0x46ebe6['body'],null))[_0x509f('0x22')](respondWithResult(_0x247a4d,null))[_0x509f('0x42')](handleError(_0x247a4d,null));};exports[_0x509f('0x23')]=function(_0x1d3248,_0x1151ce){return db['DeskField']['find']({'where':{'id':_0x1d3248[_0x509f('0x44')]['id']}})[_0x509f('0x22')](handleEntityNotFound(_0x1151ce,null))[_0x509f('0x22')](removeEntity(_0x1151ce,null))[_0x509f('0x42')](handleError(_0x1151ce,null));};