e8f64d0857ce479bb68300c82e0b3ae2aa187c8e
[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 _0xf845=['find','create','body','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','json','offset','undefined','count','limit','status','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','VtigerField','rawAttributes','fieldName','type','model','map','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','includeAll','findAll','rows','catch','show','params'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xf845,0x13f));var _0x5f84=function(_0x4758b3,_0x4b9cf8){_0x4758b3=_0x4758b3-0x0;var _0x3110d4=_0xf845[_0x4758b3];return _0x3110d4;};'use strict';var emlformat=require(_0x5f84('0x0'));var rimraf=require(_0x5f84('0x1'));var zipdir=require(_0x5f84('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x5f84('0x3'));var moment=require(_0x5f84('0x4'));var BPromise=require(_0x5f84('0x5'));var Mustache=require(_0x5f84('0x6'));var util=require('util');var path=require(_0x5f84('0x7'));var sox=require(_0x5f84('0x8'));var csv=require(_0x5f84('0x9'));var ejs=require(_0x5f84('0xa'));var fs=require('fs');var fs_extra=require(_0x5f84('0xb'));var _=require(_0x5f84('0xc'));var squel=require(_0x5f84('0xd'));var crypto=require(_0x5f84('0xe'));var jsforce=require(_0x5f84('0xf'));var deskjs=require(_0x5f84('0x10'));var toCsv=require(_0x5f84('0x9'));var querystring=require('querystring');var Papa=require(_0x5f84('0x11'));var Redis=require(_0x5f84('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x5f84('0x13'));var as=require(_0x5f84('0x14'));var hardwareService=require(_0x5f84('0x15'));var logger=require(_0x5f84('0x16'))('api');var utils=require('../../config/utils');var config=require(_0x5f84('0x17'));var licenseUtil=require(_0x5f84('0x18'));var db=require(_0x5f84('0x19'))['db'];function respondWithStatusCode(_0x441b80,_0x1ee1b5){_0x1ee1b5=_0x1ee1b5||0xcc;return function(_0x14e350){if(_0x14e350){return _0x441b80[_0x5f84('0x1a')](_0x1ee1b5);}return _0x441b80['status'](_0x1ee1b5)[_0x5f84('0x1b')]();};}function respondWithResult(_0x5a8169,_0x4dae04){_0x4dae04=_0x4dae04||0xc8;return function(_0x4cfb06){if(_0x4cfb06){return _0x5a8169['status'](_0x4dae04)[_0x5f84('0x1c')](_0x4cfb06);}};}function respondWithFilteredResult(_0x4a0688,_0x7fc5b6){return function(_0x14ea3c){if(_0x14ea3c){var _0x4f4e19=typeof _0x7fc5b6[_0x5f84('0x1d')]==='undefined'&&typeof _0x7fc5b6['limit']===_0x5f84('0x1e');var _0x5cc13c=_0x14ea3c[_0x5f84('0x1f')];var _0x3c5da1=_0x4f4e19?0x0:_0x7fc5b6[_0x5f84('0x1d')];var _0x4d5632=_0x4f4e19?_0x14ea3c[_0x5f84('0x1f')]:_0x7fc5b6['offset']+_0x7fc5b6[_0x5f84('0x20')];var _0x1faa8d;if(_0x4d5632>=_0x5cc13c){_0x4d5632=_0x5cc13c;_0x1faa8d=0xc8;}else{_0x1faa8d=0xce;}_0x4a0688[_0x5f84('0x21')](_0x1faa8d);return _0x4a0688[_0x5f84('0x22')](_0x5f84('0x23'),_0x3c5da1+'-'+_0x4d5632+'/'+_0x5cc13c)[_0x5f84('0x1c')](_0x14ea3c);}return null;};}function patchUpdates(_0x168140){return function(_0x40b3f1){try{jsonpatch[_0x5f84('0x24')](_0x40b3f1,_0x168140,!![]);}catch(_0x27a66c){return BPromise[_0x5f84('0x25')](_0x27a66c);}return _0x40b3f1[_0x5f84('0x26')]();};}function saveUpdates(_0x36621a,_0x5b0356){return function(_0x27f3b7){if(_0x27f3b7){return _0x27f3b7[_0x5f84('0x27')](_0x36621a)[_0x5f84('0x28')](function(_0xf46304){return _0xf46304;});}return null;};}function removeEntity(_0x5dceb6,_0x5bd038){return function(_0x245c8d){if(_0x245c8d){return _0x245c8d[_0x5f84('0x29')]()[_0x5f84('0x28')](function(){_0x5dceb6[_0x5f84('0x21')](0xcc)[_0x5f84('0x1b')]();});}};}function handleEntityNotFound(_0x5e7fe2,_0x1e409f){return function(_0x39d687){if(!_0x39d687){_0x5e7fe2[_0x5f84('0x1a')](0x194);}return _0x39d687;};}function handleError(_0x2f7e3f,_0x27c508){_0x27c508=_0x27c508||0x1f4;return function(_0x13a1cc){logger[_0x5f84('0x2a')](_0x13a1cc[_0x5f84('0x2b')]);if(_0x13a1cc[_0x5f84('0x2c')]){delete _0x13a1cc['name'];}_0x2f7e3f['status'](_0x27c508)[_0x5f84('0x2d')](_0x13a1cc);};}exports[_0x5f84('0x2e')]=function(_0x296c53,_0x1a0dfe){var _0x42f84f={},_0x3d0983={},_0x36a41b={'count':0x0,'rows':[]};var _0x294176=_['map'](db[_0x5f84('0x2f')][_0x5f84('0x30')],function(_0xc8f06f){return{'name':_0xc8f06f[_0x5f84('0x31')],'type':_0xc8f06f[_0x5f84('0x32')]['key']};});_0x3d0983[_0x5f84('0x33')]=_[_0x5f84('0x34')](_0x294176,'name');_0x3d0983[_0x5f84('0x35')]=_[_0x5f84('0x36')](_0x296c53['query']);_0x3d0983[_0x5f84('0x37')]=_['intersection'](_0x3d0983[_0x5f84('0x33')],_0x3d0983[_0x5f84('0x35')]);_0x42f84f[_0x5f84('0x38')]=_[_0x5f84('0x39')](_0x3d0983[_0x5f84('0x33')],qs[_0x5f84('0x3a')](_0x296c53[_0x5f84('0x35')][_0x5f84('0x3a')]));_0x42f84f['attributes']=_0x42f84f[_0x5f84('0x38')][_0x5f84('0x3b')]?_0x42f84f['attributes']:_0x3d0983[_0x5f84('0x33')];if(!_0x296c53[_0x5f84('0x35')][_0x5f84('0x3c')](_0x5f84('0x3d'))){_0x42f84f[_0x5f84('0x20')]=qs[_0x5f84('0x20')](_0x296c53[_0x5f84('0x35')][_0x5f84('0x20')]);_0x42f84f['offset']=qs[_0x5f84('0x1d')](_0x296c53[_0x5f84('0x35')][_0x5f84('0x1d')]);}_0x42f84f[_0x5f84('0x3e')]=qs[_0x5f84('0x3f')](_0x296c53[_0x5f84('0x35')][_0x5f84('0x3f')]);_0x42f84f[_0x5f84('0x40')]=qs[_0x5f84('0x37')](_[_0x5f84('0x41')](_0x296c53[_0x5f84('0x35')],_0x3d0983['filters']),_0x294176);if(_0x296c53[_0x5f84('0x35')]['filter']){_0x42f84f['where']=_[_0x5f84('0x42')](_0x42f84f['where'],{'$or':_[_0x5f84('0x34')](_0x294176,function(_0x62dea){if(_0x62dea[_0x5f84('0x32')]!==_0x5f84('0x43')){var _0x499395={};_0x499395[_0x62dea['name']]={'$like':'%'+_0x296c53[_0x5f84('0x35')][_0x5f84('0x44')]+'%'};return _0x499395;}})});}_0x42f84f=_[_0x5f84('0x42')]({},_0x42f84f,_0x296c53[_0x5f84('0x45')]);var _0x3ff908={'where':_0x42f84f[_0x5f84('0x40')]};return db[_0x5f84('0x2f')]['count'](_0x3ff908)['then'](function(_0x3b7490){_0x36a41b[_0x5f84('0x1f')]=_0x3b7490;if(_0x296c53[_0x5f84('0x35')][_0x5f84('0x46')]){_0x42f84f['include']=[{'all':!![]}];}return db[_0x5f84('0x2f')][_0x5f84('0x47')](_0x42f84f);})[_0x5f84('0x28')](function(_0x309b74){_0x36a41b[_0x5f84('0x48')]=_0x309b74;return _0x36a41b;})[_0x5f84('0x28')](respondWithFilteredResult(_0x1a0dfe,_0x42f84f))[_0x5f84('0x49')](handleError(_0x1a0dfe,null));};exports[_0x5f84('0x4a')]=function(_0x24daf1,_0x3bd74f){var _0x157102={'raw':!![],'where':{'id':_0x24daf1[_0x5f84('0x4b')]['id']}},_0x447447={};_0x447447[_0x5f84('0x33')]=_[_0x5f84('0x36')](db[_0x5f84('0x2f')][_0x5f84('0x30')]);_0x447447[_0x5f84('0x35')]=_[_0x5f84('0x36')](_0x24daf1[_0x5f84('0x35')]);_0x447447['filters']=_[_0x5f84('0x39')](_0x447447[_0x5f84('0x33')],_0x447447[_0x5f84('0x35')]);_0x157102['attributes']=_[_0x5f84('0x39')](_0x447447['model'],qs[_0x5f84('0x3a')](_0x24daf1['query']['fields']));_0x157102[_0x5f84('0x38')]=_0x157102[_0x5f84('0x38')][_0x5f84('0x3b')]?_0x157102[_0x5f84('0x38')]:_0x447447[_0x5f84('0x33')];if(_0x24daf1[_0x5f84('0x35')]['includeAll']){_0x157102['include']=[{'all':!![]}];}_0x157102=_[_0x5f84('0x42')]({},_0x157102,_0x24daf1[_0x5f84('0x45')]);return db[_0x5f84('0x2f')][_0x5f84('0x4c')](_0x157102)[_0x5f84('0x28')](handleEntityNotFound(_0x3bd74f,null))[_0x5f84('0x28')](respondWithResult(_0x3bd74f,null))['catch'](handleError(_0x3bd74f,null));};exports[_0x5f84('0x4d')]=function(_0x2d4cdf,_0xa67c6){return db['VtigerField']['create'](_0x2d4cdf[_0x5f84('0x4e')],{})['then'](respondWithResult(_0xa67c6,0xc9))[_0x5f84('0x49')](handleError(_0xa67c6,null));};exports['update']=function(_0x311643,_0x574ad5){if(_0x311643[_0x5f84('0x4e')]['id']){delete _0x311643['body']['id'];}return db[_0x5f84('0x2f')][_0x5f84('0x4c')]({'where':{'id':_0x311643[_0x5f84('0x4b')]['id']}})[_0x5f84('0x28')](handleEntityNotFound(_0x574ad5,null))['then'](saveUpdates(_0x311643[_0x5f84('0x4e')],null))[_0x5f84('0x28')](respondWithResult(_0x574ad5,null))[_0x5f84('0x49')](handleError(_0x574ad5,null));};exports['destroy']=function(_0x3a1398,_0xe1279d){return db[_0x5f84('0x2f')]['find']({'where':{'id':_0x3a1398['params']['id']}})['then'](handleEntityNotFound(_0xe1279d,null))[_0x5f84('0x28')](removeEntity(_0xe1279d,null))[_0x5f84('0x49')](handleError(_0xe1279d,null));};