Built motion from commit 97153652.|2.6.26
[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 _0x612f=['squel','crypto','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','count','Content-Range','apply','reject','update','destroy','error','stack','name','send','index','map','VtigerField','rawAttributes','fieldName','type','key','model','query','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','filters','pick','merge','VIRTUAL','filter','options','includeAll','include','findAll','then','rows','catch','show','params','keys','find','create','body','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','fs-extra'];(function(_0x403ce1,_0xc1b506){var _0x223831=function(_0x4e5f95){while(--_0x4e5f95){_0x403ce1['push'](_0x403ce1['shift']());}};_0x223831(++_0xc1b506);}(_0x612f,0x19f));var _0xf612=function(_0x45df64,_0x537b7f){_0x45df64=_0x45df64-0x0;var _0x4a0c99=_0x612f[_0x45df64];return _0x4a0c99;};'use strict';var emlformat=require(_0xf612('0x0'));var rimraf=require(_0xf612('0x1'));var zipdir=require(_0xf612('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf612('0x3'));var moment=require(_0xf612('0x4'));var BPromise=require(_0xf612('0x5'));var Mustache=require('mustache');var util=require(_0xf612('0x6'));var path=require(_0xf612('0x7'));var sox=require(_0xf612('0x8'));var csv=require(_0xf612('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf612('0xa'));var _=require('lodash');var squel=require(_0xf612('0xb'));var crypto=require(_0xf612('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf612('0x9'));var querystring=require(_0xf612('0xd'));var Papa=require('papaparse');var Redis=require(_0xf612('0xe'));var authService=require(_0xf612('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xf612('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf612('0x11'))('api');var utils=require('../../config/utils');var config=require(_0xf612('0x12'));var licenseUtil=require('../../config/license/util');var db=require(_0xf612('0x13'))['db'];function respondWithStatusCode(_0x4b38ce,_0xbbe539){_0xbbe539=_0xbbe539||0xcc;return function(_0x393184){if(_0x393184){return _0x4b38ce[_0xf612('0x14')](_0xbbe539);}return _0x4b38ce[_0xf612('0x15')](_0xbbe539)[_0xf612('0x16')]();};}function respondWithResult(_0x224535,_0x1c6b1f){_0x1c6b1f=_0x1c6b1f||0xc8;return function(_0x4758fb){if(_0x4758fb){return _0x224535[_0xf612('0x15')](_0x1c6b1f)[_0xf612('0x17')](_0x4758fb);}};}function respondWithFilteredResult(_0x305c85,_0x34b6e0){return function(_0x2ead7f){if(_0x2ead7f){var _0x56c6e6=typeof _0x34b6e0[_0xf612('0x18')]==='undefined'&&typeof _0x34b6e0[_0xf612('0x19')]==='undefined';var _0x5399b9=_0x2ead7f[_0xf612('0x1a')];var _0x4d330a=_0x56c6e6?0x0:_0x34b6e0['offset'];var _0xf47b1d=_0x56c6e6?_0x2ead7f[_0xf612('0x1a')]:_0x34b6e0[_0xf612('0x18')]+_0x34b6e0['limit'];var _0x243ec1;if(_0xf47b1d>=_0x5399b9){_0xf47b1d=_0x5399b9;_0x243ec1=0xc8;}else{_0x243ec1=0xce;}_0x305c85[_0xf612('0x15')](_0x243ec1);return _0x305c85['set'](_0xf612('0x1b'),_0x4d330a+'-'+_0xf47b1d+'/'+_0x5399b9)[_0xf612('0x17')](_0x2ead7f);}return null;};}function patchUpdates(_0x401688){return function(_0x3a6162){try{jsonpatch[_0xf612('0x1c')](_0x3a6162,_0x401688,!![]);}catch(_0x4feeeb){return BPromise[_0xf612('0x1d')](_0x4feeeb);}return _0x3a6162['save']();};}function saveUpdates(_0x4b00b9,_0x3150e6){return function(_0x2b8de4){if(_0x2b8de4){return _0x2b8de4[_0xf612('0x1e')](_0x4b00b9)['then'](function(_0xf78433){return _0xf78433;});}return null;};}function removeEntity(_0x26e1bd,_0x24f6d9){return function(_0x138409){if(_0x138409){return _0x138409[_0xf612('0x1f')]()['then'](function(){_0x26e1bd[_0xf612('0x15')](0xcc)[_0xf612('0x16')]();});}};}function handleEntityNotFound(_0x478560,_0x3e9d9e){return function(_0x117d23){if(!_0x117d23){_0x478560['sendStatus'](0x194);}return _0x117d23;};}function handleError(_0x24f621,_0x449e5c){_0x449e5c=_0x449e5c||0x1f4;return function(_0x50aa00){logger[_0xf612('0x20')](_0x50aa00[_0xf612('0x21')]);if(_0x50aa00[_0xf612('0x22')]){delete _0x50aa00['name'];}_0x24f621[_0xf612('0x15')](_0x449e5c)[_0xf612('0x23')](_0x50aa00);};}exports[_0xf612('0x24')]=function(_0x203161,_0xdefdaa){var _0x1d8432={},_0x235bf4={},_0x2a772c={'count':0x0,'rows':[]};var _0x193a54=_[_0xf612('0x25')](db[_0xf612('0x26')][_0xf612('0x27')],function(_0x1a7062){return{'name':_0x1a7062[_0xf612('0x28')],'type':_0x1a7062[_0xf612('0x29')][_0xf612('0x2a')]};});_0x235bf4[_0xf612('0x2b')]=_[_0xf612('0x25')](_0x193a54,_0xf612('0x22'));_0x235bf4[_0xf612('0x2c')]=_['keys'](_0x203161[_0xf612('0x2c')]);_0x235bf4['filters']=_[_0xf612('0x2d')](_0x235bf4[_0xf612('0x2b')],_0x235bf4[_0xf612('0x2c')]);_0x1d8432['attributes']=_[_0xf612('0x2d')](_0x235bf4[_0xf612('0x2b')],qs[_0xf612('0x2e')](_0x203161[_0xf612('0x2c')]['fields']));_0x1d8432[_0xf612('0x2f')]=_0x1d8432['attributes'][_0xf612('0x30')]?_0x1d8432[_0xf612('0x2f')]:_0x235bf4[_0xf612('0x2b')];if(!_0x203161[_0xf612('0x2c')][_0xf612('0x31')]('nolimit')){_0x1d8432[_0xf612('0x19')]=qs[_0xf612('0x19')](_0x203161['query'][_0xf612('0x19')]);_0x1d8432[_0xf612('0x18')]=qs['offset'](_0x203161[_0xf612('0x2c')][_0xf612('0x18')]);}_0x1d8432[_0xf612('0x32')]=qs[_0xf612('0x33')](_0x203161['query'][_0xf612('0x33')]);_0x1d8432[_0xf612('0x34')]=qs[_0xf612('0x35')](_[_0xf612('0x36')](_0x203161['query'],_0x235bf4[_0xf612('0x35')]),_0x193a54);if(_0x203161[_0xf612('0x2c')]['filter']){_0x1d8432[_0xf612('0x34')]=_[_0xf612('0x37')](_0x1d8432[_0xf612('0x34')],{'$or':_[_0xf612('0x25')](_0x193a54,function(_0x3294ea){if(_0x3294ea[_0xf612('0x29')]!==_0xf612('0x38')){var _0x5f31e2={};_0x5f31e2[_0x3294ea[_0xf612('0x22')]]={'$like':'%'+_0x203161[_0xf612('0x2c')][_0xf612('0x39')]+'%'};return _0x5f31e2;}})});}_0x1d8432=_['merge']({},_0x1d8432,_0x203161[_0xf612('0x3a')]);var _0x5cc17a={'where':_0x1d8432['where']};return db[_0xf612('0x26')][_0xf612('0x1a')](_0x5cc17a)['then'](function(_0x5af55b){_0x2a772c[_0xf612('0x1a')]=_0x5af55b;if(_0x203161['query'][_0xf612('0x3b')]){_0x1d8432[_0xf612('0x3c')]=[{'all':!![]}];}return db[_0xf612('0x26')][_0xf612('0x3d')](_0x1d8432);})[_0xf612('0x3e')](function(_0x16ef22){_0x2a772c[_0xf612('0x3f')]=_0x16ef22;return _0x2a772c;})[_0xf612('0x3e')](respondWithFilteredResult(_0xdefdaa,_0x1d8432))[_0xf612('0x40')](handleError(_0xdefdaa,null));};exports[_0xf612('0x41')]=function(_0xcc1075,_0x768a1d){var _0x4c7d76={'raw':!![],'where':{'id':_0xcc1075[_0xf612('0x42')]['id']}},_0x4a1f26={};_0x4a1f26[_0xf612('0x2b')]=_[_0xf612('0x43')](db[_0xf612('0x26')][_0xf612('0x27')]);_0x4a1f26[_0xf612('0x2c')]=_[_0xf612('0x43')](_0xcc1075[_0xf612('0x2c')]);_0x4a1f26['filters']=_[_0xf612('0x2d')](_0x4a1f26[_0xf612('0x2b')],_0x4a1f26[_0xf612('0x2c')]);_0x4c7d76[_0xf612('0x2f')]=_[_0xf612('0x2d')](_0x4a1f26[_0xf612('0x2b')],qs['fields'](_0xcc1075[_0xf612('0x2c')][_0xf612('0x2e')]));_0x4c7d76[_0xf612('0x2f')]=_0x4c7d76[_0xf612('0x2f')][_0xf612('0x30')]?_0x4c7d76[_0xf612('0x2f')]:_0x4a1f26['model'];if(_0xcc1075[_0xf612('0x2c')]['includeAll']){_0x4c7d76[_0xf612('0x3c')]=[{'all':!![]}];}_0x4c7d76=_['merge']({},_0x4c7d76,_0xcc1075[_0xf612('0x3a')]);return db[_0xf612('0x26')][_0xf612('0x44')](_0x4c7d76)['then'](handleEntityNotFound(_0x768a1d,null))['then'](respondWithResult(_0x768a1d,null))[_0xf612('0x40')](handleError(_0x768a1d,null));};exports[_0xf612('0x45')]=function(_0x3b3009,_0x3bbda4){return db[_0xf612('0x26')][_0xf612('0x45')](_0x3b3009[_0xf612('0x46')],{})[_0xf612('0x3e')](respondWithResult(_0x3bbda4,0xc9))[_0xf612('0x40')](handleError(_0x3bbda4,null));};exports['update']=function(_0x5373b5,_0x2350ff){if(_0x5373b5['body']['id']){delete _0x5373b5[_0xf612('0x46')]['id'];}return db[_0xf612('0x26')][_0xf612('0x44')]({'where':{'id':_0x5373b5[_0xf612('0x42')]['id']}})[_0xf612('0x3e')](handleEntityNotFound(_0x2350ff,null))[_0xf612('0x3e')](saveUpdates(_0x5373b5['body'],null))['then'](respondWithResult(_0x2350ff,null))[_0xf612('0x40')](handleError(_0x2350ff,null));};exports[_0xf612('0x1f')]=function(_0x18ca6e,_0x1d7a9e){return db[_0xf612('0x26')][_0xf612('0x44')]({'where':{'id':_0x18ca6e[_0xf612('0x42')]['id']}})[_0xf612('0x3e')](handleEntityNotFound(_0x1d7a9e,null))[_0xf612('0x3e')](removeEntity(_0x1d7a9e,null))[_0xf612('0x40')](handleError(_0x1d7a9e,null));};