73ac9593353dc23662bb4aae44800396a4003191
[motion2.git] / server / api / intVtigerField / intVtigerField.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 _0xb4b6=['../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','json','count','offset','limit','Content-Range','apply','save','then','status','stack','name','VtigerField','rawAttributes','type','key','model','map','query','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','options','include','rows','catch','show','params','keys','fields','includeAll','find','create','update','body','destroy','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service'];(function(_0x1ac697,_0x2aa0f1){var _0x49792b=function(_0x2936ce){while(--_0x2936ce){_0x1ac697['push'](_0x1ac697['shift']());}};_0x49792b(++_0x2aa0f1);}(_0xb4b6,0x7e));var _0x6b4b=function(_0x4e4431,_0x5c699f){_0x4e4431=_0x4e4431-0x0;var _0x95bd75=_0xb4b6[_0x4e4431];return _0x95bd75;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x6b4b('0x0'));var rimraf=require(_0x6b4b('0x1'));var zipdir=require(_0x6b4b('0x2'));var jsonpatch=require(_0x6b4b('0x3'));var rp=require(_0x6b4b('0x4'));var moment=require(_0x6b4b('0x5'));var BPromise=require(_0x6b4b('0x6'));var Mustache=require(_0x6b4b('0x7'));var util=require(_0x6b4b('0x8'));var path=require('path');var sox=require(_0x6b4b('0x9'));var csv=require('to-csv');var ejs=require(_0x6b4b('0xa'));var fs=require('fs');var _=require(_0x6b4b('0xb'));var squel=require(_0x6b4b('0xc'));var crypto=require(_0x6b4b('0xd'));var jsforce=require(_0x6b4b('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x6b4b('0xf'));var querystring=require(_0x6b4b('0x10'));var Papa=require(_0x6b4b('0x11'));var Redis=require(_0x6b4b('0x12'));var authService=require(_0x6b4b('0x13'));var qs=require(_0x6b4b('0x14'));var as=require(_0x6b4b('0x15'));var hardwareService=require(_0x6b4b('0x16'));var logger=require('../../config/logger')(_0x6b4b('0x17'));var utils=require('../../config/utils');var config=require(_0x6b4b('0x18'));var licenseUtil=require(_0x6b4b('0x19'));var db=require(_0x6b4b('0x1a'))['db'];function respondWithStatusCode(_0x2ba8a0,_0x476d20){_0x476d20=_0x476d20||0xcc;return function(_0xa50ae5){if(_0xa50ae5){return _0x2ba8a0[_0x6b4b('0x1b')](_0x476d20);}return _0x2ba8a0['status'](_0x476d20)[_0x6b4b('0x1c')]();};}function respondWithResult(_0x2acc64,_0x3b99db){_0x3b99db=_0x3b99db||0xc8;return function(_0x587ed1){if(_0x587ed1){return _0x2acc64['status'](_0x3b99db)[_0x6b4b('0x1d')](_0x587ed1);}};}function respondWithFilteredResult(_0x2bf3fe,_0x5bf378){return function(_0x21ab38){if(_0x21ab38){var _0x3842a6=_0x21ab38[_0x6b4b('0x1e')],_0x26ac10=_0x5bf378[_0x6b4b('0x1f')],_0x3954d9=_0x5bf378[_0x6b4b('0x1f')]+_0x5bf378[_0x6b4b('0x20')],_0x22a176;if(_0x3954d9>=_0x3842a6){_0x3954d9=_0x3842a6;_0x22a176=0xc8;}else{_0x22a176=0xce;}_0x2bf3fe['status'](_0x22a176);return _0x2bf3fe['set'](_0x6b4b('0x21'),_0x26ac10+'-'+_0x3954d9+'/'+_0x3842a6)['json'](_0x21ab38);}return null;};}function patchUpdates(_0x22f142){return function(_0x44c5f6){try{jsonpatch[_0x6b4b('0x22')](_0x44c5f6,_0x22f142,!![]);}catch(_0x9106ac){return BPromise['reject'](_0x9106ac);}return _0x44c5f6[_0x6b4b('0x23')]();};}function saveUpdates(_0x6235eb,_0x5f2224){return function(_0x5ecffb){if(_0x5ecffb){return _0x5ecffb['update'](_0x6235eb)[_0x6b4b('0x24')](function(_0x42d10d){return _0x42d10d;});}return null;};}function removeEntity(_0x203f2a,_0x222e23){return function(_0x1a9fba){if(_0x1a9fba){return _0x1a9fba['destroy']()[_0x6b4b('0x24')](function(){_0x203f2a[_0x6b4b('0x25')](0xcc)[_0x6b4b('0x1c')]();});}};}function handleEntityNotFound(_0xef64c9,_0x595f33){return function(_0x571920){if(!_0x571920){_0xef64c9['sendStatus'](0x194);}return _0x571920;};}function handleError(_0x4c4ecc,_0x17f017){_0x17f017=_0x17f017||0x1f4;return function(_0x526f6d){logger['error'](_0x526f6d[_0x6b4b('0x26')]);if(_0x526f6d[_0x6b4b('0x27')]){delete _0x526f6d[_0x6b4b('0x27')];}_0x4c4ecc[_0x6b4b('0x25')](_0x17f017)['send'](_0x526f6d);};}exports['index']=function(_0x19f977,_0x3ce6b8){var _0x2973f={},_0x17a0c1={},_0x5e7c75={'count':0x0,'rows':[]};var _0x364b29=_['map'](db[_0x6b4b('0x28')][_0x6b4b('0x29')],function(_0x334cf8){return{'name':_0x334cf8['fieldName'],'type':_0x334cf8[_0x6b4b('0x2a')][_0x6b4b('0x2b')]};});_0x17a0c1[_0x6b4b('0x2c')]=_[_0x6b4b('0x2d')](_0x364b29,_0x6b4b('0x27'));_0x17a0c1[_0x6b4b('0x2e')]=_['keys'](_0x19f977['query']);_0x17a0c1['filters']=_[_0x6b4b('0x2f')](_0x17a0c1[_0x6b4b('0x2c')],_0x17a0c1[_0x6b4b('0x2e')]);_0x2973f[_0x6b4b('0x30')]=_[_0x6b4b('0x2f')](_0x17a0c1[_0x6b4b('0x2c')],qs['fields'](_0x19f977['query']['fields']));_0x2973f[_0x6b4b('0x30')]=_0x2973f['attributes'][_0x6b4b('0x31')]?_0x2973f['attributes']:_0x17a0c1['model'];if(!_0x19f977['query'][_0x6b4b('0x32')](_0x6b4b('0x33'))){_0x2973f[_0x6b4b('0x20')]=qs[_0x6b4b('0x20')](_0x19f977[_0x6b4b('0x2e')]['limit']);_0x2973f[_0x6b4b('0x1f')]=qs['offset'](_0x19f977[_0x6b4b('0x2e')]['offset']);}_0x2973f[_0x6b4b('0x34')]=qs[_0x6b4b('0x35')](_0x19f977[_0x6b4b('0x2e')]['sort']);_0x2973f[_0x6b4b('0x36')]=qs[_0x6b4b('0x37')](_[_0x6b4b('0x38')](_0x19f977['query'],_0x17a0c1['filters']),_0x364b29);if(_0x19f977[_0x6b4b('0x2e')][_0x6b4b('0x39')]){_0x2973f[_0x6b4b('0x36')]=_[_0x6b4b('0x3a')](_0x2973f[_0x6b4b('0x36')],{'$or':_[_0x6b4b('0x2d')](_0x364b29,function(_0x4a8af8){if(_0x4a8af8[_0x6b4b('0x2a')]!=='VIRTUAL'){var _0x287ba8={};_0x287ba8[_0x4a8af8[_0x6b4b('0x27')]]={'$like':'%'+_0x19f977['query']['filter']+'%'};return _0x287ba8;}})});}_0x2973f=_['merge']({},_0x2973f,_0x19f977[_0x6b4b('0x3b')]);var _0xda8ef3={'where':_0x2973f[_0x6b4b('0x36')]};return db[_0x6b4b('0x28')][_0x6b4b('0x1e')](_0xda8ef3)[_0x6b4b('0x24')](function(_0x2a5a3d){_0x5e7c75[_0x6b4b('0x1e')]=_0x2a5a3d;if(_0x19f977[_0x6b4b('0x2e')]['includeAll']){_0x2973f[_0x6b4b('0x3c')]=[{'all':!![]}];}return db[_0x6b4b('0x28')]['findAll'](_0x2973f);})['then'](function(_0x4213e7){_0x5e7c75[_0x6b4b('0x3d')]=_0x4213e7;return _0x5e7c75;})[_0x6b4b('0x24')](respondWithFilteredResult(_0x3ce6b8,_0x2973f))[_0x6b4b('0x3e')](handleError(_0x3ce6b8,null));};exports[_0x6b4b('0x3f')]=function(_0x28ca5b,_0x561716){var _0x55cd0f={'raw':!![],'where':{'id':_0x28ca5b[_0x6b4b('0x40')]['id']}},_0x3a709c={};_0x3a709c[_0x6b4b('0x2c')]=_[_0x6b4b('0x41')](db[_0x6b4b('0x28')][_0x6b4b('0x29')]);_0x3a709c['query']=_[_0x6b4b('0x41')](_0x28ca5b[_0x6b4b('0x2e')]);_0x3a709c[_0x6b4b('0x37')]=_[_0x6b4b('0x2f')](_0x3a709c[_0x6b4b('0x2c')],_0x3a709c[_0x6b4b('0x2e')]);_0x55cd0f[_0x6b4b('0x30')]=_[_0x6b4b('0x2f')](_0x3a709c['model'],qs[_0x6b4b('0x42')](_0x28ca5b[_0x6b4b('0x2e')][_0x6b4b('0x42')]));_0x55cd0f['attributes']=_0x55cd0f['attributes'][_0x6b4b('0x31')]?_0x55cd0f[_0x6b4b('0x30')]:_0x3a709c[_0x6b4b('0x2c')];if(_0x28ca5b['query'][_0x6b4b('0x43')]){_0x55cd0f['include']=[{'all':!![]}];}_0x55cd0f=_[_0x6b4b('0x3a')]({},_0x55cd0f,_0x28ca5b[_0x6b4b('0x3b')]);return db['VtigerField'][_0x6b4b('0x44')](_0x55cd0f)['then'](handleEntityNotFound(_0x561716,null))[_0x6b4b('0x24')](respondWithResult(_0x561716,null))['catch'](handleError(_0x561716,null));};exports['create']=function(_0xab4836,_0x387078){return db[_0x6b4b('0x28')][_0x6b4b('0x45')](_0xab4836['body'],{})[_0x6b4b('0x24')](respondWithResult(_0x387078,0xc9))[_0x6b4b('0x3e')](handleError(_0x387078,null));};exports[_0x6b4b('0x46')]=function(_0x596147,_0x580eda){if(_0x596147[_0x6b4b('0x47')]['id']){delete _0x596147['body']['id'];}return db['VtigerField'][_0x6b4b('0x44')]({'where':{'id':_0x596147[_0x6b4b('0x40')]['id']}})[_0x6b4b('0x24')](handleEntityNotFound(_0x580eda,null))[_0x6b4b('0x24')](saveUpdates(_0x596147['body'],null))[_0x6b4b('0x24')](respondWithResult(_0x580eda,null))[_0x6b4b('0x3e')](handleError(_0x580eda,null));};exports[_0x6b4b('0x48')]=function(_0x3a5424,_0x2e8009){return db[_0x6b4b('0x28')][_0x6b4b('0x44')]({'where':{'id':_0x3a5424[_0x6b4b('0x40')]['id']}})[_0x6b4b('0x24')](handleEntityNotFound(_0x2e8009,null))[_0x6b4b('0x24')](removeEntity(_0x2e8009,null))[_0x6b4b('0x3e')](handleError(_0x2e8009,null));};