cef30aefa53a16eecbb923d950f861041560ae63
[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 _0xf853=['findAll','rows','catch','show','intersection','include','merge','find','create','body','params','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','reject','save','update','then','destroy','end','error','stack','send','map','rawAttributes','fieldName','type','key','model','name','query','keys','filters','attributes','fields','length','hasOwnProperty','order','sort','pick','filter','where','VIRTUAL','options','includeAll','VtigerField'];(function(_0x330723,_0x8de382){var _0x60c546=function(_0xd6d3fe){while(--_0xd6d3fe){_0x330723['push'](_0x330723['shift']());}};_0x60c546(++_0x8de382);}(_0xf853,0x1cd));var _0x3f85=function(_0xe896bf,_0x4f8e5e){_0xe896bf=_0xe896bf-0x0;var _0x4c7a8a=_0xf853[_0xe896bf];return _0x4c7a8a;};'use strict';var emlformat=require(_0x3f85('0x0'));var rimraf=require(_0x3f85('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x3f85('0x2'));var rp=require(_0x3f85('0x3'));var moment=require(_0x3f85('0x4'));var BPromise=require(_0x3f85('0x5'));var Mustache=require('mustache');var util=require(_0x3f85('0x6'));var path=require('path');var sox=require(_0x3f85('0x7'));var csv=require(_0x3f85('0x8'));var ejs=require(_0x3f85('0x9'));var fs=require('fs');var fs_extra=require(_0x3f85('0xa'));var _=require(_0x3f85('0xb'));var squel=require(_0x3f85('0xc'));var crypto=require(_0x3f85('0xd'));var jsforce=require(_0x3f85('0xe'));var deskjs=require(_0x3f85('0xf'));var toCsv=require(_0x3f85('0x8'));var querystring=require(_0x3f85('0x10'));var Papa=require('papaparse');var Redis=require(_0x3f85('0x11'));var authService=require(_0x3f85('0x12'));var qs=require(_0x3f85('0x13'));var as=require(_0x3f85('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x3f85('0x15'))(_0x3f85('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x3f85('0x17'))['db'];function respondWithStatusCode(_0x3c1cb7,_0x1885ae){_0x1885ae=_0x1885ae||0xcc;return function(_0x1a5474){if(_0x1a5474){return _0x3c1cb7[_0x3f85('0x18')](_0x1885ae);}return _0x3c1cb7[_0x3f85('0x19')](_0x1885ae)['end']();};}function respondWithResult(_0x4b8bc9,_0x478df6){_0x478df6=_0x478df6||0xc8;return function(_0x196a5f){if(_0x196a5f){return _0x4b8bc9[_0x3f85('0x19')](_0x478df6)[_0x3f85('0x1a')](_0x196a5f);}};}function respondWithFilteredResult(_0x274a04,_0x35ed10){return function(_0x53d27d){if(_0x53d27d){var _0x2d8927=typeof _0x35ed10[_0x3f85('0x1b')]===_0x3f85('0x1c')&&typeof _0x35ed10[_0x3f85('0x1d')]===_0x3f85('0x1c');var _0x3f3315=_0x53d27d[_0x3f85('0x1e')];var _0x3bc49a=_0x2d8927?0x0:_0x35ed10[_0x3f85('0x1b')];var _0xcdd71f=_0x2d8927?_0x53d27d[_0x3f85('0x1e')]:_0x35ed10['offset']+_0x35ed10[_0x3f85('0x1d')];var _0x4c664d;if(_0xcdd71f>=_0x3f3315){_0xcdd71f=_0x3f3315;_0x4c664d=0xc8;}else{_0x4c664d=0xce;}_0x274a04[_0x3f85('0x19')](_0x4c664d);return _0x274a04[_0x3f85('0x1f')]('Content-Range',_0x3bc49a+'-'+_0xcdd71f+'/'+_0x3f3315)['json'](_0x53d27d);}return null;};}function patchUpdates(_0x16caed){return function(_0x2bfe6e){try{jsonpatch['apply'](_0x2bfe6e,_0x16caed,!![]);}catch(_0x55fd2b){return BPromise[_0x3f85('0x20')](_0x55fd2b);}return _0x2bfe6e[_0x3f85('0x21')]();};}function saveUpdates(_0x4581dd,_0x50c473){return function(_0x4739f5){if(_0x4739f5){return _0x4739f5[_0x3f85('0x22')](_0x4581dd)[_0x3f85('0x23')](function(_0x121495){return _0x121495;});}return null;};}function removeEntity(_0x3faf6c,_0x298d06){return function(_0x4ca964){if(_0x4ca964){return _0x4ca964[_0x3f85('0x24')]()[_0x3f85('0x23')](function(){_0x3faf6c[_0x3f85('0x19')](0xcc)[_0x3f85('0x25')]();});}};}function handleEntityNotFound(_0x579158,_0xd8e991){return function(_0x21d552){if(!_0x21d552){_0x579158[_0x3f85('0x18')](0x194);}return _0x21d552;};}function handleError(_0x4f3453,_0x1b0f53){_0x1b0f53=_0x1b0f53||0x1f4;return function(_0x5e4b03){logger[_0x3f85('0x26')](_0x5e4b03[_0x3f85('0x27')]);if(_0x5e4b03['name']){delete _0x5e4b03['name'];}_0x4f3453['status'](_0x1b0f53)[_0x3f85('0x28')](_0x5e4b03);};}exports['index']=function(_0xd10ad2,_0x5657f6){var _0x47f05c={},_0x370943={},_0x24eaed={'count':0x0,'rows':[]};var _0x17e6d3=_[_0x3f85('0x29')](db['VtigerField'][_0x3f85('0x2a')],function(_0x21b893){return{'name':_0x21b893[_0x3f85('0x2b')],'type':_0x21b893[_0x3f85('0x2c')][_0x3f85('0x2d')]};});_0x370943[_0x3f85('0x2e')]=_['map'](_0x17e6d3,_0x3f85('0x2f'));_0x370943[_0x3f85('0x30')]=_[_0x3f85('0x31')](_0xd10ad2[_0x3f85('0x30')]);_0x370943[_0x3f85('0x32')]=_['intersection'](_0x370943[_0x3f85('0x2e')],_0x370943[_0x3f85('0x30')]);_0x47f05c[_0x3f85('0x33')]=_['intersection'](_0x370943[_0x3f85('0x2e')],qs[_0x3f85('0x34')](_0xd10ad2[_0x3f85('0x30')][_0x3f85('0x34')]));_0x47f05c[_0x3f85('0x33')]=_0x47f05c[_0x3f85('0x33')][_0x3f85('0x35')]?_0x47f05c[_0x3f85('0x33')]:_0x370943['model'];if(!_0xd10ad2[_0x3f85('0x30')][_0x3f85('0x36')]('nolimit')){_0x47f05c[_0x3f85('0x1d')]=qs[_0x3f85('0x1d')](_0xd10ad2['query'][_0x3f85('0x1d')]);_0x47f05c['offset']=qs[_0x3f85('0x1b')](_0xd10ad2[_0x3f85('0x30')][_0x3f85('0x1b')]);}_0x47f05c[_0x3f85('0x37')]=qs[_0x3f85('0x38')](_0xd10ad2[_0x3f85('0x30')][_0x3f85('0x38')]);_0x47f05c['where']=qs['filters'](_[_0x3f85('0x39')](_0xd10ad2[_0x3f85('0x30')],_0x370943['filters']),_0x17e6d3);if(_0xd10ad2['query'][_0x3f85('0x3a')]){_0x47f05c[_0x3f85('0x3b')]=_['merge'](_0x47f05c[_0x3f85('0x3b')],{'$or':_[_0x3f85('0x29')](_0x17e6d3,function(_0x1d9952){if(_0x1d9952['type']!==_0x3f85('0x3c')){var _0x260110={};_0x260110[_0x1d9952[_0x3f85('0x2f')]]={'$like':'%'+_0xd10ad2[_0x3f85('0x30')][_0x3f85('0x3a')]+'%'};return _0x260110;}})});}_0x47f05c=_['merge']({},_0x47f05c,_0xd10ad2[_0x3f85('0x3d')]);var _0x651768={'where':_0x47f05c[_0x3f85('0x3b')]};return db['VtigerField'][_0x3f85('0x1e')](_0x651768)[_0x3f85('0x23')](function(_0x5dda4b){_0x24eaed['count']=_0x5dda4b;if(_0xd10ad2['query'][_0x3f85('0x3e')]){_0x47f05c['include']=[{'all':!![]}];}return db[_0x3f85('0x3f')][_0x3f85('0x40')](_0x47f05c);})[_0x3f85('0x23')](function(_0x3bf47e){_0x24eaed[_0x3f85('0x41')]=_0x3bf47e;return _0x24eaed;})['then'](respondWithFilteredResult(_0x5657f6,_0x47f05c))[_0x3f85('0x42')](handleError(_0x5657f6,null));};exports[_0x3f85('0x43')]=function(_0x180399,_0xdae88c){var _0x428d21={'raw':!![],'where':{'id':_0x180399['params']['id']}},_0x226bc6={};_0x226bc6[_0x3f85('0x2e')]=_[_0x3f85('0x31')](db['VtigerField'][_0x3f85('0x2a')]);_0x226bc6[_0x3f85('0x30')]=_[_0x3f85('0x31')](_0x180399[_0x3f85('0x30')]);_0x226bc6[_0x3f85('0x32')]=_['intersection'](_0x226bc6['model'],_0x226bc6[_0x3f85('0x30')]);_0x428d21[_0x3f85('0x33')]=_[_0x3f85('0x44')](_0x226bc6[_0x3f85('0x2e')],qs[_0x3f85('0x34')](_0x180399[_0x3f85('0x30')][_0x3f85('0x34')]));_0x428d21[_0x3f85('0x33')]=_0x428d21[_0x3f85('0x33')][_0x3f85('0x35')]?_0x428d21['attributes']:_0x226bc6[_0x3f85('0x2e')];if(_0x180399[_0x3f85('0x30')][_0x3f85('0x3e')]){_0x428d21[_0x3f85('0x45')]=[{'all':!![]}];}_0x428d21=_[_0x3f85('0x46')]({},_0x428d21,_0x180399[_0x3f85('0x3d')]);return db[_0x3f85('0x3f')][_0x3f85('0x47')](_0x428d21)['then'](handleEntityNotFound(_0xdae88c,null))['then'](respondWithResult(_0xdae88c,null))['catch'](handleError(_0xdae88c,null));};exports[_0x3f85('0x48')]=function(_0x55124e,_0x40f374){return db[_0x3f85('0x3f')][_0x3f85('0x48')](_0x55124e[_0x3f85('0x49')],{})[_0x3f85('0x23')](respondWithResult(_0x40f374,0xc9))[_0x3f85('0x42')](handleError(_0x40f374,null));};exports[_0x3f85('0x22')]=function(_0x201cbc,_0x751d9f){if(_0x201cbc[_0x3f85('0x49')]['id']){delete _0x201cbc[_0x3f85('0x49')]['id'];}return db[_0x3f85('0x3f')][_0x3f85('0x47')]({'where':{'id':_0x201cbc[_0x3f85('0x4a')]['id']}})[_0x3f85('0x23')](handleEntityNotFound(_0x751d9f,null))[_0x3f85('0x23')](saveUpdates(_0x201cbc[_0x3f85('0x49')],null))['then'](respondWithResult(_0x751d9f,null))[_0x3f85('0x42')](handleError(_0x751d9f,null));};exports['destroy']=function(_0xcd64a2,_0x3a2e98){return db[_0x3f85('0x3f')][_0x3f85('0x47')]({'where':{'id':_0xcd64a2[_0x3f85('0x4a')]['id']}})[_0x3f85('0x23')](handleEntityNotFound(_0x3a2e98,null))['then'](removeEntity(_0x3a2e98,null))[_0x3f85('0x42')](handleError(_0x3a2e98,null));};