Built motion from commit 3e059bc2.|2.5.32
[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 _0xf9f3=['findAll','rows','catch','show','params','create','body','find','eml-format','rimraf','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','undefined','count','offset','set','Content-Range','apply','reject','update','then','destroy','sendStatus','error','stack','name','send','map','VtigerField','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','merge','VIRTUAL','options','includeAll','include'];(function(_0x12aaee,_0x5bf50c){var _0x37c350=function(_0x182775){while(--_0x182775){_0x12aaee['push'](_0x12aaee['shift']());}};_0x37c350(++_0x5bf50c);}(_0xf9f3,0x189));var _0x3f9f=function(_0x3bf83f,_0x181cac){_0x3bf83f=_0x3bf83f-0x0;var _0x22c4a9=_0xf9f3[_0x3bf83f];return _0x22c4a9;};'use strict';var emlformat=require(_0x3f9f('0x0'));var rimraf=require(_0x3f9f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x3f9f('0x2'));var moment=require('moment');var BPromise=require(_0x3f9f('0x3'));var Mustache=require(_0x3f9f('0x4'));var util=require(_0x3f9f('0x5'));var path=require(_0x3f9f('0x6'));var sox=require(_0x3f9f('0x7'));var csv=require('to-csv');var ejs=require(_0x3f9f('0x8'));var fs=require('fs');var fs_extra=require(_0x3f9f('0x9'));var _=require(_0x3f9f('0xa'));var squel=require(_0x3f9f('0xb'));var crypto=require(_0x3f9f('0xc'));var jsforce=require(_0x3f9f('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x3f9f('0xe'));var querystring=require('querystring');var Papa=require(_0x3f9f('0xf'));var Redis=require(_0x3f9f('0x10'));var authService=require(_0x3f9f('0x11'));var qs=require(_0x3f9f('0x12'));var as=require(_0x3f9f('0x13'));var hardwareService=require(_0x3f9f('0x14'));var logger=require(_0x3f9f('0x15'))('api');var utils=require('../../config/utils');var config=require(_0x3f9f('0x16'));var licenseUtil=require(_0x3f9f('0x17'));var db=require(_0x3f9f('0x18'))['db'];function respondWithStatusCode(_0x487dc4,_0x150c7e){_0x150c7e=_0x150c7e||0xcc;return function(_0x1daf91){if(_0x1daf91){return _0x487dc4['sendStatus'](_0x150c7e);}return _0x487dc4[_0x3f9f('0x19')](_0x150c7e)[_0x3f9f('0x1a')]();};}function respondWithResult(_0x188a10,_0x41bfdc){_0x41bfdc=_0x41bfdc||0xc8;return function(_0x31a381){if(_0x31a381){return _0x188a10[_0x3f9f('0x19')](_0x41bfdc)[_0x3f9f('0x1b')](_0x31a381);}};}function respondWithFilteredResult(_0x475769,_0x2245cb){return function(_0x57fad2){if(_0x57fad2){var _0x52fe9a=typeof _0x2245cb['offset']===_0x3f9f('0x1c')&&typeof _0x2245cb['limit']===_0x3f9f('0x1c');var _0x1fbd58=_0x57fad2[_0x3f9f('0x1d')];var _0x4b9264=_0x52fe9a?0x0:_0x2245cb['offset'];var _0x50f39b=_0x52fe9a?_0x57fad2[_0x3f9f('0x1d')]:_0x2245cb[_0x3f9f('0x1e')]+_0x2245cb['limit'];var _0x3ceef4;if(_0x50f39b>=_0x1fbd58){_0x50f39b=_0x1fbd58;_0x3ceef4=0xc8;}else{_0x3ceef4=0xce;}_0x475769[_0x3f9f('0x19')](_0x3ceef4);return _0x475769[_0x3f9f('0x1f')](_0x3f9f('0x20'),_0x4b9264+'-'+_0x50f39b+'/'+_0x1fbd58)['json'](_0x57fad2);}return null;};}function patchUpdates(_0x2a9888){return function(_0x5b6cb2){try{jsonpatch[_0x3f9f('0x21')](_0x5b6cb2,_0x2a9888,!![]);}catch(_0x3a24bf){return BPromise[_0x3f9f('0x22')](_0x3a24bf);}return _0x5b6cb2['save']();};}function saveUpdates(_0x118c0d,_0x3868d4){return function(_0x3d6fbe){if(_0x3d6fbe){return _0x3d6fbe[_0x3f9f('0x23')](_0x118c0d)[_0x3f9f('0x24')](function(_0x3064c9){return _0x3064c9;});}return null;};}function removeEntity(_0x1c5168,_0x521bb5){return function(_0x2ba9d3){if(_0x2ba9d3){return _0x2ba9d3[_0x3f9f('0x25')]()['then'](function(){_0x1c5168['status'](0xcc)[_0x3f9f('0x1a')]();});}};}function handleEntityNotFound(_0x4908f1,_0xf32900){return function(_0x76f44b){if(!_0x76f44b){_0x4908f1[_0x3f9f('0x26')](0x194);}return _0x76f44b;};}function handleError(_0x37235d,_0x839b94){_0x839b94=_0x839b94||0x1f4;return function(_0x591ae9){logger[_0x3f9f('0x27')](_0x591ae9[_0x3f9f('0x28')]);if(_0x591ae9[_0x3f9f('0x29')]){delete _0x591ae9[_0x3f9f('0x29')];}_0x37235d['status'](_0x839b94)[_0x3f9f('0x2a')](_0x591ae9);};}exports['index']=function(_0x242955,_0x506f26){var _0x47e544={},_0x499477={},_0x23c50a={'count':0x0,'rows':[]};var _0x560645=_[_0x3f9f('0x2b')](db[_0x3f9f('0x2c')][_0x3f9f('0x2d')],function(_0xc254fd){return{'name':_0xc254fd[_0x3f9f('0x2e')],'type':_0xc254fd[_0x3f9f('0x2f')][_0x3f9f('0x30')]};});_0x499477[_0x3f9f('0x31')]=_[_0x3f9f('0x2b')](_0x560645,_0x3f9f('0x29'));_0x499477[_0x3f9f('0x32')]=_[_0x3f9f('0x33')](_0x242955[_0x3f9f('0x32')]);_0x499477[_0x3f9f('0x34')]=_[_0x3f9f('0x35')](_0x499477[_0x3f9f('0x31')],_0x499477[_0x3f9f('0x32')]);_0x47e544[_0x3f9f('0x36')]=_['intersection'](_0x499477['model'],qs[_0x3f9f('0x37')](_0x242955['query'][_0x3f9f('0x37')]));_0x47e544[_0x3f9f('0x36')]=_0x47e544[_0x3f9f('0x36')][_0x3f9f('0x38')]?_0x47e544[_0x3f9f('0x36')]:_0x499477[_0x3f9f('0x31')];if(!_0x242955[_0x3f9f('0x32')][_0x3f9f('0x39')](_0x3f9f('0x3a'))){_0x47e544['limit']=qs[_0x3f9f('0x3b')](_0x242955['query'][_0x3f9f('0x3b')]);_0x47e544['offset']=qs[_0x3f9f('0x1e')](_0x242955[_0x3f9f('0x32')][_0x3f9f('0x1e')]);}_0x47e544[_0x3f9f('0x3c')]=qs[_0x3f9f('0x3d')](_0x242955['query'][_0x3f9f('0x3d')]);_0x47e544[_0x3f9f('0x3e')]=qs[_0x3f9f('0x34')](_[_0x3f9f('0x3f')](_0x242955['query'],_0x499477[_0x3f9f('0x34')]),_0x560645);if(_0x242955[_0x3f9f('0x32')]['filter']){_0x47e544[_0x3f9f('0x3e')]=_[_0x3f9f('0x40')](_0x47e544['where'],{'$or':_[_0x3f9f('0x2b')](_0x560645,function(_0x181e85){if(_0x181e85['type']!==_0x3f9f('0x41')){var _0x3305dc={};_0x3305dc[_0x181e85[_0x3f9f('0x29')]]={'$like':'%'+_0x242955[_0x3f9f('0x32')]['filter']+'%'};return _0x3305dc;}})});}_0x47e544=_[_0x3f9f('0x40')]({},_0x47e544,_0x242955[_0x3f9f('0x42')]);var _0x13bfc4={'where':_0x47e544[_0x3f9f('0x3e')]};return db[_0x3f9f('0x2c')][_0x3f9f('0x1d')](_0x13bfc4)[_0x3f9f('0x24')](function(_0x272f04){_0x23c50a[_0x3f9f('0x1d')]=_0x272f04;if(_0x242955[_0x3f9f('0x32')][_0x3f9f('0x43')]){_0x47e544[_0x3f9f('0x44')]=[{'all':!![]}];}return db[_0x3f9f('0x2c')][_0x3f9f('0x45')](_0x47e544);})[_0x3f9f('0x24')](function(_0x331693){_0x23c50a[_0x3f9f('0x46')]=_0x331693;return _0x23c50a;})[_0x3f9f('0x24')](respondWithFilteredResult(_0x506f26,_0x47e544))[_0x3f9f('0x47')](handleError(_0x506f26,null));};exports[_0x3f9f('0x48')]=function(_0x5d337c,_0x350f3d){var _0x37e1af={'raw':!![],'where':{'id':_0x5d337c[_0x3f9f('0x49')]['id']}},_0x3fa91d={};_0x3fa91d['model']=_[_0x3f9f('0x33')](db[_0x3f9f('0x2c')]['rawAttributes']);_0x3fa91d['query']=_[_0x3f9f('0x33')](_0x5d337c[_0x3f9f('0x32')]);_0x3fa91d[_0x3f9f('0x34')]=_[_0x3f9f('0x35')](_0x3fa91d['model'],_0x3fa91d[_0x3f9f('0x32')]);_0x37e1af[_0x3f9f('0x36')]=_[_0x3f9f('0x35')](_0x3fa91d[_0x3f9f('0x31')],qs[_0x3f9f('0x37')](_0x5d337c[_0x3f9f('0x32')]['fields']));_0x37e1af[_0x3f9f('0x36')]=_0x37e1af[_0x3f9f('0x36')][_0x3f9f('0x38')]?_0x37e1af[_0x3f9f('0x36')]:_0x3fa91d['model'];if(_0x5d337c['query'][_0x3f9f('0x43')]){_0x37e1af[_0x3f9f('0x44')]=[{'all':!![]}];}_0x37e1af=_[_0x3f9f('0x40')]({},_0x37e1af,_0x5d337c['options']);return db['VtigerField']['find'](_0x37e1af)[_0x3f9f('0x24')](handleEntityNotFound(_0x350f3d,null))[_0x3f9f('0x24')](respondWithResult(_0x350f3d,null))[_0x3f9f('0x47')](handleError(_0x350f3d,null));};exports['create']=function(_0x2335a5,_0x566035){return db[_0x3f9f('0x2c')][_0x3f9f('0x4a')](_0x2335a5[_0x3f9f('0x4b')],{})['then'](respondWithResult(_0x566035,0xc9))[_0x3f9f('0x47')](handleError(_0x566035,null));};exports[_0x3f9f('0x23')]=function(_0x45f37a,_0x3cafb5){if(_0x45f37a[_0x3f9f('0x4b')]['id']){delete _0x45f37a[_0x3f9f('0x4b')]['id'];}return db[_0x3f9f('0x2c')][_0x3f9f('0x4c')]({'where':{'id':_0x45f37a[_0x3f9f('0x49')]['id']}})[_0x3f9f('0x24')](handleEntityNotFound(_0x3cafb5,null))[_0x3f9f('0x24')](saveUpdates(_0x45f37a['body'],null))[_0x3f9f('0x24')](respondWithResult(_0x3cafb5,null))['catch'](handleError(_0x3cafb5,null));};exports[_0x3f9f('0x25')]=function(_0x4becf2,_0x174679){return db[_0x3f9f('0x2c')][_0x3f9f('0x4c')]({'where':{'id':_0x4becf2[_0x3f9f('0x49')]['id']}})[_0x3f9f('0x24')](handleEntityNotFound(_0x174679,null))[_0x3f9f('0x24')](removeEntity(_0x174679,null))['catch'](handleError(_0x174679,null));};