Built motion from commit c0cdc9d8.|2.6.28
[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 _0x98f0=['findAll','rows','show','params','rawAttributes','find','catch','create','body','update','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','querystring','ioredis','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','count','limit','set','apply','reject','save','then','destroy','stack','name','index','map','VtigerField','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include'];(function(_0x4e77c6,_0x4c359c){var _0x3e326c=function(_0x50e425){while(--_0x50e425){_0x4e77c6['push'](_0x4e77c6['shift']());}};_0x3e326c(++_0x4c359c);}(_0x98f0,0xdc));var _0x098f=function(_0x540286,_0x4dc75a){_0x540286=_0x540286-0x0;var _0x48854f=_0x98f0[_0x540286];return _0x48854f;};'use strict';var emlformat=require(_0x098f('0x0'));var rimraf=require(_0x098f('0x1'));var zipdir=require(_0x098f('0x2'));var jsonpatch=require(_0x098f('0x3'));var rp=require(_0x098f('0x4'));var moment=require('moment');var BPromise=require(_0x098f('0x5'));var Mustache=require(_0x098f('0x6'));var util=require(_0x098f('0x7'));var path=require(_0x098f('0x8'));var sox=require('sox');var csv=require(_0x098f('0x9'));var ejs=require(_0x098f('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x098f('0xb'));var squel=require(_0x098f('0xc'));var crypto=require(_0x098f('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x098f('0xe'));var Papa=require('papaparse');var Redis=require(_0x098f('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x098f('0x10'))(_0x098f('0x11'));var utils=require(_0x098f('0x12'));var config=require(_0x098f('0x13'));var licenseUtil=require(_0x098f('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3fcf95,_0x27a1e0){_0x27a1e0=_0x27a1e0||0xcc;return function(_0x115d14){if(_0x115d14){return _0x3fcf95[_0x098f('0x15')](_0x27a1e0);}return _0x3fcf95[_0x098f('0x16')](_0x27a1e0)[_0x098f('0x17')]();};}function respondWithResult(_0x17498a,_0x5c07e1){_0x5c07e1=_0x5c07e1||0xc8;return function(_0x3b7c94){if(_0x3b7c94){return _0x17498a[_0x098f('0x16')](_0x5c07e1)[_0x098f('0x18')](_0x3b7c94);}};}function respondWithFilteredResult(_0x378169,_0x262939){return function(_0x425d33){if(_0x425d33){var _0x30acc4=typeof _0x262939[_0x098f('0x19')]===_0x098f('0x1a')&&typeof _0x262939['limit']==='undefined';var _0x43cd72=_0x425d33[_0x098f('0x1b')];var _0x266e14=_0x30acc4?0x0:_0x262939['offset'];var _0xf50c4d=_0x30acc4?_0x425d33[_0x098f('0x1b')]:_0x262939[_0x098f('0x19')]+_0x262939[_0x098f('0x1c')];var _0x31bcd8;if(_0xf50c4d>=_0x43cd72){_0xf50c4d=_0x43cd72;_0x31bcd8=0xc8;}else{_0x31bcd8=0xce;}_0x378169['status'](_0x31bcd8);return _0x378169[_0x098f('0x1d')]('Content-Range',_0x266e14+'-'+_0xf50c4d+'/'+_0x43cd72)['json'](_0x425d33);}return null;};}function patchUpdates(_0x26c46b){return function(_0x168194){try{jsonpatch[_0x098f('0x1e')](_0x168194,_0x26c46b,!![]);}catch(_0x28b78d){return BPromise[_0x098f('0x1f')](_0x28b78d);}return _0x168194[_0x098f('0x20')]();};}function saveUpdates(_0xe0de47,_0x14b9f6){return function(_0x1a7a40){if(_0x1a7a40){return _0x1a7a40['update'](_0xe0de47)[_0x098f('0x21')](function(_0x4ba187){return _0x4ba187;});}return null;};}function removeEntity(_0xb98e8f,_0x56e0e1){return function(_0x283b14){if(_0x283b14){return _0x283b14[_0x098f('0x22')]()[_0x098f('0x21')](function(){_0xb98e8f[_0x098f('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0xc7ba96,_0x5a6ea4){return function(_0x3399e8){if(!_0x3399e8){_0xc7ba96['sendStatus'](0x194);}return _0x3399e8;};}function handleError(_0x225eaf,_0x4d9536){_0x4d9536=_0x4d9536||0x1f4;return function(_0x10941b){logger['error'](_0x10941b[_0x098f('0x23')]);if(_0x10941b[_0x098f('0x24')]){delete _0x10941b[_0x098f('0x24')];}_0x225eaf[_0x098f('0x16')](_0x4d9536)['send'](_0x10941b);};}exports[_0x098f('0x25')]=function(_0x35963d,_0x5cb307){var _0x27c4e8={},_0x34f7f5={},_0x3e22f5={'count':0x0,'rows':[]};var _0xf9f7fd=_[_0x098f('0x26')](db[_0x098f('0x27')]['rawAttributes'],function(_0xfaf3dd){return{'name':_0xfaf3dd[_0x098f('0x28')],'type':_0xfaf3dd[_0x098f('0x29')]['key']};});_0x34f7f5[_0x098f('0x2a')]=_[_0x098f('0x26')](_0xf9f7fd,'name');_0x34f7f5[_0x098f('0x2b')]=_[_0x098f('0x2c')](_0x35963d['query']);_0x34f7f5[_0x098f('0x2d')]=_['intersection'](_0x34f7f5['model'],_0x34f7f5[_0x098f('0x2b')]);_0x27c4e8['attributes']=_[_0x098f('0x2e')](_0x34f7f5[_0x098f('0x2a')],qs[_0x098f('0x2f')](_0x35963d[_0x098f('0x2b')][_0x098f('0x2f')]));_0x27c4e8[_0x098f('0x30')]=_0x27c4e8[_0x098f('0x30')][_0x098f('0x31')]?_0x27c4e8[_0x098f('0x30')]:_0x34f7f5[_0x098f('0x2a')];if(!_0x35963d[_0x098f('0x2b')]['hasOwnProperty'](_0x098f('0x32'))){_0x27c4e8['limit']=qs['limit'](_0x35963d['query'][_0x098f('0x1c')]);_0x27c4e8[_0x098f('0x19')]=qs[_0x098f('0x19')](_0x35963d['query'][_0x098f('0x19')]);}_0x27c4e8[_0x098f('0x33')]=qs['sort'](_0x35963d['query'][_0x098f('0x34')]);_0x27c4e8[_0x098f('0x35')]=qs[_0x098f('0x2d')](_[_0x098f('0x36')](_0x35963d['query'],_0x34f7f5[_0x098f('0x2d')]),_0xf9f7fd);if(_0x35963d['query'][_0x098f('0x37')]){_0x27c4e8[_0x098f('0x35')]=_[_0x098f('0x38')](_0x27c4e8[_0x098f('0x35')],{'$or':_[_0x098f('0x26')](_0xf9f7fd,function(_0x7b56ee){if(_0x7b56ee[_0x098f('0x29')]!==_0x098f('0x39')){var _0x164f80={};_0x164f80[_0x7b56ee[_0x098f('0x24')]]={'$like':'%'+_0x35963d['query'][_0x098f('0x37')]+'%'};return _0x164f80;}})});}_0x27c4e8=_['merge']({},_0x27c4e8,_0x35963d['options']);var _0x51f79f={'where':_0x27c4e8[_0x098f('0x35')]};return db['VtigerField'][_0x098f('0x1b')](_0x51f79f)[_0x098f('0x21')](function(_0x2ae403){_0x3e22f5['count']=_0x2ae403;if(_0x35963d['query'][_0x098f('0x3a')]){_0x27c4e8[_0x098f('0x3b')]=[{'all':!![]}];}return db['VtigerField'][_0x098f('0x3c')](_0x27c4e8);})[_0x098f('0x21')](function(_0x4da2e9){_0x3e22f5[_0x098f('0x3d')]=_0x4da2e9;return _0x3e22f5;})[_0x098f('0x21')](respondWithFilteredResult(_0x5cb307,_0x27c4e8))['catch'](handleError(_0x5cb307,null));};exports[_0x098f('0x3e')]=function(_0x31002d,_0x18ed66){var _0x1620fe={'raw':!![],'where':{'id':_0x31002d[_0x098f('0x3f')]['id']}},_0x3ad690={};_0x3ad690[_0x098f('0x2a')]=_[_0x098f('0x2c')](db[_0x098f('0x27')][_0x098f('0x40')]);_0x3ad690['query']=_['keys'](_0x31002d[_0x098f('0x2b')]);_0x3ad690[_0x098f('0x2d')]=_[_0x098f('0x2e')](_0x3ad690[_0x098f('0x2a')],_0x3ad690[_0x098f('0x2b')]);_0x1620fe[_0x098f('0x30')]=_['intersection'](_0x3ad690[_0x098f('0x2a')],qs[_0x098f('0x2f')](_0x31002d[_0x098f('0x2b')][_0x098f('0x2f')]));_0x1620fe[_0x098f('0x30')]=_0x1620fe['attributes'][_0x098f('0x31')]?_0x1620fe[_0x098f('0x30')]:_0x3ad690[_0x098f('0x2a')];if(_0x31002d[_0x098f('0x2b')][_0x098f('0x3a')]){_0x1620fe[_0x098f('0x3b')]=[{'all':!![]}];}_0x1620fe=_[_0x098f('0x38')]({},_0x1620fe,_0x31002d['options']);return db['VtigerField'][_0x098f('0x41')](_0x1620fe)[_0x098f('0x21')](handleEntityNotFound(_0x18ed66,null))[_0x098f('0x21')](respondWithResult(_0x18ed66,null))[_0x098f('0x42')](handleError(_0x18ed66,null));};exports['create']=function(_0x2d0653,_0x43deee){return db[_0x098f('0x27')][_0x098f('0x43')](_0x2d0653[_0x098f('0x44')],{})[_0x098f('0x21')](respondWithResult(_0x43deee,0xc9))[_0x098f('0x42')](handleError(_0x43deee,null));};exports[_0x098f('0x45')]=function(_0x2fb115,_0x5b6953){if(_0x2fb115['body']['id']){delete _0x2fb115[_0x098f('0x44')]['id'];}return db['VtigerField']['find']({'where':{'id':_0x2fb115[_0x098f('0x3f')]['id']}})['then'](handleEntityNotFound(_0x5b6953,null))['then'](saveUpdates(_0x2fb115[_0x098f('0x44')],null))[_0x098f('0x21')](respondWithResult(_0x5b6953,null))[_0x098f('0x42')](handleError(_0x5b6953,null));};exports['destroy']=function(_0x22194d,_0xc9d520){return db[_0x098f('0x27')][_0x098f('0x41')]({'where':{'id':_0x22194d[_0x098f('0x3f')]['id']}})[_0x098f('0x21')](handleEntityNotFound(_0xc9d520,null))[_0x098f('0x21')](removeEntity(_0xc9d520,null))[_0x098f('0x42')](handleError(_0xc9d520,null));};