Built motion from commit d5e4af8c.|2.6.23
[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 _0x65f6=['../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','stack','name','index','map','VtigerField','rawAttributes','keys','filters','intersection','model','query','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filter','merge','type','options','include','findAll','rows','catch','show','find','create','body','params','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util'];(function(_0x199572,_0x33e667){var _0x13cfa3=function(_0x53c075){while(--_0x53c075){_0x199572['push'](_0x199572['shift']());}};_0x13cfa3(++_0x33e667);}(_0x65f6,0x77));var _0x665f=function(_0x532c54,_0x54f860){_0x532c54=_0x532c54-0x0;var _0x5887e5=_0x65f6[_0x532c54];return _0x5887e5;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x665f('0x0'));var zipdir=require(_0x665f('0x1'));var jsonpatch=require(_0x665f('0x2'));var rp=require(_0x665f('0x3'));var moment=require(_0x665f('0x4'));var BPromise=require(_0x665f('0x5'));var Mustache=require('mustache');var util=require(_0x665f('0x6'));var path=require('path');var sox=require(_0x665f('0x7'));var csv=require(_0x665f('0x8'));var ejs=require(_0x665f('0x9'));var fs=require('fs');var fs_extra=require(_0x665f('0xa'));var _=require('lodash');var squel=require(_0x665f('0xb'));var crypto=require(_0x665f('0xc'));var jsforce=require(_0x665f('0xd'));var deskjs=require(_0x665f('0xe'));var toCsv=require(_0x665f('0x8'));var querystring=require(_0x665f('0xf'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x665f('0x10'));var as=require(_0x665f('0x11'));var hardwareService=require(_0x665f('0x12'));var logger=require(_0x665f('0x13'))(_0x665f('0x14'));var utils=require(_0x665f('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x665f('0x16'));var db=require(_0x665f('0x17'))['db'];function respondWithStatusCode(_0x2b64d5,_0x4e7286){_0x4e7286=_0x4e7286||0xcc;return function(_0x2cc1f8){if(_0x2cc1f8){return _0x2b64d5[_0x665f('0x18')](_0x4e7286);}return _0x2b64d5[_0x665f('0x19')](_0x4e7286)[_0x665f('0x1a')]();};}function respondWithResult(_0x2ff680,_0x16f677){_0x16f677=_0x16f677||0xc8;return function(_0x58f48c){if(_0x58f48c){return _0x2ff680[_0x665f('0x19')](_0x16f677)[_0x665f('0x1b')](_0x58f48c);}};}function respondWithFilteredResult(_0x5ff7e0,_0x43960a){return function(_0x2fe036){if(_0x2fe036){var _0x13bb64=typeof _0x43960a[_0x665f('0x1c')]===_0x665f('0x1d')&&typeof _0x43960a[_0x665f('0x1e')]==='undefined';var _0x498c9b=_0x2fe036[_0x665f('0x1f')];var _0xfd7b35=_0x13bb64?0x0:_0x43960a[_0x665f('0x1c')];var _0x28ea1e=_0x13bb64?_0x2fe036['count']:_0x43960a[_0x665f('0x1c')]+_0x43960a[_0x665f('0x1e')];var _0x5a9715;if(_0x28ea1e>=_0x498c9b){_0x28ea1e=_0x498c9b;_0x5a9715=0xc8;}else{_0x5a9715=0xce;}_0x5ff7e0[_0x665f('0x19')](_0x5a9715);return _0x5ff7e0[_0x665f('0x20')](_0x665f('0x21'),_0xfd7b35+'-'+_0x28ea1e+'/'+_0x498c9b)[_0x665f('0x1b')](_0x2fe036);}return null;};}function patchUpdates(_0x389516){return function(_0x44afde){try{jsonpatch[_0x665f('0x22')](_0x44afde,_0x389516,!![]);}catch(_0x45b448){return BPromise[_0x665f('0x23')](_0x45b448);}return _0x44afde[_0x665f('0x24')]();};}function saveUpdates(_0x4ad07e,_0x32eb12){return function(_0x2c0370){if(_0x2c0370){return _0x2c0370[_0x665f('0x25')](_0x4ad07e)[_0x665f('0x26')](function(_0x4483af){return _0x4483af;});}return null;};}function removeEntity(_0x841de,_0x4cc8ec){return function(_0x270e36){if(_0x270e36){return _0x270e36[_0x665f('0x27')]()[_0x665f('0x26')](function(){_0x841de[_0x665f('0x19')](0xcc)[_0x665f('0x1a')]();});}};}function handleEntityNotFound(_0x9d1e8d,_0x40ff2b){return function(_0x538529){if(!_0x538529){_0x9d1e8d[_0x665f('0x18')](0x194);}return _0x538529;};}function handleError(_0x4d685c,_0x462bcd){_0x462bcd=_0x462bcd||0x1f4;return function(_0x1e2f6d){logger['error'](_0x1e2f6d[_0x665f('0x28')]);if(_0x1e2f6d['name']){delete _0x1e2f6d[_0x665f('0x29')];}_0x4d685c['status'](_0x462bcd)['send'](_0x1e2f6d);};}exports[_0x665f('0x2a')]=function(_0x5bc5a4,_0x2e8ff3){var _0x4b94f4={},_0x2bff02={},_0x3abc91={'count':0x0,'rows':[]};var _0x5b1821=_[_0x665f('0x2b')](db[_0x665f('0x2c')][_0x665f('0x2d')],function(_0x1c2cfc){return{'name':_0x1c2cfc['fieldName'],'type':_0x1c2cfc['type']['key']};});_0x2bff02['model']=_[_0x665f('0x2b')](_0x5b1821,_0x665f('0x29'));_0x2bff02['query']=_[_0x665f('0x2e')](_0x5bc5a4['query']);_0x2bff02[_0x665f('0x2f')]=_[_0x665f('0x30')](_0x2bff02[_0x665f('0x31')],_0x2bff02[_0x665f('0x32')]);_0x4b94f4['attributes']=_['intersection'](_0x2bff02[_0x665f('0x31')],qs[_0x665f('0x33')](_0x5bc5a4['query'][_0x665f('0x33')]));_0x4b94f4['attributes']=_0x4b94f4[_0x665f('0x34')][_0x665f('0x35')]?_0x4b94f4['attributes']:_0x2bff02[_0x665f('0x31')];if(!_0x5bc5a4[_0x665f('0x32')][_0x665f('0x36')](_0x665f('0x37'))){_0x4b94f4[_0x665f('0x1e')]=qs[_0x665f('0x1e')](_0x5bc5a4[_0x665f('0x32')][_0x665f('0x1e')]);_0x4b94f4[_0x665f('0x1c')]=qs[_0x665f('0x1c')](_0x5bc5a4['query'][_0x665f('0x1c')]);}_0x4b94f4['order']=qs[_0x665f('0x38')](_0x5bc5a4[_0x665f('0x32')][_0x665f('0x38')]);_0x4b94f4[_0x665f('0x39')]=qs['filters'](_['pick'](_0x5bc5a4[_0x665f('0x32')],_0x2bff02[_0x665f('0x2f')]),_0x5b1821);if(_0x5bc5a4[_0x665f('0x32')][_0x665f('0x3a')]){_0x4b94f4['where']=_[_0x665f('0x3b')](_0x4b94f4['where'],{'$or':_['map'](_0x5b1821,function(_0x2b2017){if(_0x2b2017[_0x665f('0x3c')]!=='VIRTUAL'){var _0x10b286={};_0x10b286[_0x2b2017['name']]={'$like':'%'+_0x5bc5a4[_0x665f('0x32')][_0x665f('0x3a')]+'%'};return _0x10b286;}})});}_0x4b94f4=_['merge']({},_0x4b94f4,_0x5bc5a4[_0x665f('0x3d')]);var _0x30be9d={'where':_0x4b94f4[_0x665f('0x39')]};return db[_0x665f('0x2c')]['count'](_0x30be9d)[_0x665f('0x26')](function(_0x15aeb5){_0x3abc91[_0x665f('0x1f')]=_0x15aeb5;if(_0x5bc5a4[_0x665f('0x32')]['includeAll']){_0x4b94f4[_0x665f('0x3e')]=[{'all':!![]}];}return db[_0x665f('0x2c')][_0x665f('0x3f')](_0x4b94f4);})[_0x665f('0x26')](function(_0x2232fd){_0x3abc91[_0x665f('0x40')]=_0x2232fd;return _0x3abc91;})['then'](respondWithFilteredResult(_0x2e8ff3,_0x4b94f4))[_0x665f('0x41')](handleError(_0x2e8ff3,null));};exports[_0x665f('0x42')]=function(_0x64ebb4,_0x624023){var _0x4e32b4={'raw':!![],'where':{'id':_0x64ebb4['params']['id']}},_0x576772={};_0x576772[_0x665f('0x31')]=_[_0x665f('0x2e')](db['VtigerField']['rawAttributes']);_0x576772['query']=_[_0x665f('0x2e')](_0x64ebb4['query']);_0x576772[_0x665f('0x2f')]=_['intersection'](_0x576772['model'],_0x576772[_0x665f('0x32')]);_0x4e32b4[_0x665f('0x34')]=_['intersection'](_0x576772[_0x665f('0x31')],qs['fields'](_0x64ebb4[_0x665f('0x32')][_0x665f('0x33')]));_0x4e32b4[_0x665f('0x34')]=_0x4e32b4[_0x665f('0x34')][_0x665f('0x35')]?_0x4e32b4[_0x665f('0x34')]:_0x576772['model'];if(_0x64ebb4[_0x665f('0x32')]['includeAll']){_0x4e32b4[_0x665f('0x3e')]=[{'all':!![]}];}_0x4e32b4=_['merge']({},_0x4e32b4,_0x64ebb4[_0x665f('0x3d')]);return db[_0x665f('0x2c')][_0x665f('0x43')](_0x4e32b4)[_0x665f('0x26')](handleEntityNotFound(_0x624023,null))[_0x665f('0x26')](respondWithResult(_0x624023,null))[_0x665f('0x41')](handleError(_0x624023,null));};exports['create']=function(_0x110527,_0x3df1ca){return db[_0x665f('0x2c')][_0x665f('0x44')](_0x110527['body'],{})[_0x665f('0x26')](respondWithResult(_0x3df1ca,0xc9))['catch'](handleError(_0x3df1ca,null));};exports[_0x665f('0x25')]=function(_0x359bb8,_0x5874d7){if(_0x359bb8[_0x665f('0x45')]['id']){delete _0x359bb8[_0x665f('0x45')]['id'];}return db[_0x665f('0x2c')]['find']({'where':{'id':_0x359bb8[_0x665f('0x46')]['id']}})['then'](handleEntityNotFound(_0x5874d7,null))[_0x665f('0x26')](saveUpdates(_0x359bb8['body'],null))[_0x665f('0x26')](respondWithResult(_0x5874d7,null))[_0x665f('0x41')](handleError(_0x5874d7,null));};exports[_0x665f('0x27')]=function(_0x4714b0,_0x51077b){return db[_0x665f('0x2c')][_0x665f('0x43')]({'where':{'id':_0x4714b0[_0x665f('0x46')]['id']}})[_0x665f('0x26')](handleEntityNotFound(_0x51077b,null))[_0x665f('0x26')](removeEntity(_0x51077b,null))[_0x665f('0x41')](handleError(_0x51077b,null));};