Built motion from commit efa66e19.|2.6.22
[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 _0x00a2=['fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','VIRTUAL','merge','options','include','findAll','rows','show','params','VtigerField','includeAll','find','create','body','catch','eml-format','rimraf','zip-dir','bluebird','mustache','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','status','end','error','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','intersection'];(function(_0x2b419a,_0x2c74b7){var _0x1d1e40=function(_0x5bc36f){while(--_0x5bc36f){_0x2b419a['push'](_0x2b419a['shift']());}};_0x1d1e40(++_0x2c74b7);}(_0x00a2,0xb1));var _0x200a=function(_0x3a2d3d,_0x4e057f){_0x3a2d3d=_0x3a2d3d-0x0;var _0x1a7446=_0x00a2[_0x3a2d3d];return _0x1a7446;};'use strict';var emlformat=require(_0x200a('0x0'));var rimraf=require(_0x200a('0x1'));var zipdir=require(_0x200a('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x200a('0x3'));var Mustache=require(_0x200a('0x4'));var util=require('util');var path=require('path');var sox=require(_0x200a('0x5'));var csv=require(_0x200a('0x6'));var ejs=require(_0x200a('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x200a('0x8'));var squel=require(_0x200a('0x9'));var crypto=require(_0x200a('0xa'));var jsforce=require(_0x200a('0xb'));var deskjs=require(_0x200a('0xc'));var toCsv=require(_0x200a('0x6'));var querystring=require(_0x200a('0xd'));var Papa=require(_0x200a('0xe'));var Redis=require(_0x200a('0xf'));var authService=require(_0x200a('0x10'));var qs=require(_0x200a('0x11'));var as=require(_0x200a('0x12'));var hardwareService=require(_0x200a('0x13'));var logger=require(_0x200a('0x14'))(_0x200a('0x15'));var utils=require(_0x200a('0x16'));var config=require(_0x200a('0x17'));var licenseUtil=require(_0x200a('0x18'));var db=require(_0x200a('0x19'))['db'];function respondWithStatusCode(_0xc3f6f8,_0x4ac456){_0x4ac456=_0x4ac456||0xcc;return function(_0x275aac){if(_0x275aac){return _0xc3f6f8[_0x200a('0x1a')](_0x4ac456);}return _0xc3f6f8['status'](_0x4ac456)['end']();};}function respondWithResult(_0x4eaede,_0x5f53c3){_0x5f53c3=_0x5f53c3||0xc8;return function(_0x2636d1){if(_0x2636d1){return _0x4eaede['status'](_0x5f53c3)['json'](_0x2636d1);}};}function respondWithFilteredResult(_0x177188,_0xed4671){return function(_0x164a40){if(_0x164a40){var _0x491c5b=typeof _0xed4671[_0x200a('0x1b')]===_0x200a('0x1c')&&typeof _0xed4671[_0x200a('0x1d')]===_0x200a('0x1c');var _0x1429ad=_0x164a40['count'];var _0x59927b=_0x491c5b?0x0:_0xed4671[_0x200a('0x1b')];var _0x507251=_0x491c5b?_0x164a40[_0x200a('0x1e')]:_0xed4671[_0x200a('0x1b')]+_0xed4671['limit'];var _0x3c6ed9;if(_0x507251>=_0x1429ad){_0x507251=_0x1429ad;_0x3c6ed9=0xc8;}else{_0x3c6ed9=0xce;}_0x177188['status'](_0x3c6ed9);return _0x177188[_0x200a('0x1f')](_0x200a('0x20'),_0x59927b+'-'+_0x507251+'/'+_0x1429ad)['json'](_0x164a40);}return null;};}function patchUpdates(_0x164eef){return function(_0x48271d){try{jsonpatch[_0x200a('0x21')](_0x48271d,_0x164eef,!![]);}catch(_0xf1e683){return BPromise[_0x200a('0x22')](_0xf1e683);}return _0x48271d[_0x200a('0x23')]();};}function saveUpdates(_0x196e03,_0x20999c){return function(_0xb6b1e0){if(_0xb6b1e0){return _0xb6b1e0[_0x200a('0x24')](_0x196e03)[_0x200a('0x25')](function(_0x1e8d1){return _0x1e8d1;});}return null;};}function removeEntity(_0x3cc87f,_0x7e91d7){return function(_0xd8b8c0){if(_0xd8b8c0){return _0xd8b8c0[_0x200a('0x26')]()[_0x200a('0x25')](function(){_0x3cc87f[_0x200a('0x27')](0xcc)[_0x200a('0x28')]();});}};}function handleEntityNotFound(_0x123ce3,_0x289b6b){return function(_0x14e492){if(!_0x14e492){_0x123ce3[_0x200a('0x1a')](0x194);}return _0x14e492;};}function handleError(_0x49c379,_0x4b82b0){_0x4b82b0=_0x4b82b0||0x1f4;return function(_0x361b37){logger[_0x200a('0x29')](_0x361b37['stack']);if(_0x361b37[_0x200a('0x2a')]){delete _0x361b37['name'];}_0x49c379[_0x200a('0x27')](_0x4b82b0)[_0x200a('0x2b')](_0x361b37);};}exports[_0x200a('0x2c')]=function(_0x46425b,_0x4e2bdf){var _0x4afc40={},_0x5512f4={},_0xe985ec={'count':0x0,'rows':[]};var _0x4e67d3=_[_0x200a('0x2d')](db['VtigerField'][_0x200a('0x2e')],function(_0x56e7cf){return{'name':_0x56e7cf[_0x200a('0x2f')],'type':_0x56e7cf[_0x200a('0x30')][_0x200a('0x31')]};});_0x5512f4[_0x200a('0x32')]=_[_0x200a('0x2d')](_0x4e67d3,_0x200a('0x2a'));_0x5512f4[_0x200a('0x33')]=_[_0x200a('0x34')](_0x46425b[_0x200a('0x33')]);_0x5512f4['filters']=_[_0x200a('0x35')](_0x5512f4[_0x200a('0x32')],_0x5512f4[_0x200a('0x33')]);_0x4afc40['attributes']=_['intersection'](_0x5512f4[_0x200a('0x32')],qs['fields'](_0x46425b['query'][_0x200a('0x36')]));_0x4afc40[_0x200a('0x37')]=_0x4afc40[_0x200a('0x37')][_0x200a('0x38')]?_0x4afc40['attributes']:_0x5512f4[_0x200a('0x32')];if(!_0x46425b[_0x200a('0x33')][_0x200a('0x39')](_0x200a('0x3a'))){_0x4afc40['limit']=qs[_0x200a('0x1d')](_0x46425b[_0x200a('0x33')][_0x200a('0x1d')]);_0x4afc40['offset']=qs['offset'](_0x46425b['query'][_0x200a('0x1b')]);}_0x4afc40[_0x200a('0x3b')]=qs['sort'](_0x46425b[_0x200a('0x33')][_0x200a('0x3c')]);_0x4afc40[_0x200a('0x3d')]=qs[_0x200a('0x3e')](_['pick'](_0x46425b['query'],_0x5512f4[_0x200a('0x3e')]),_0x4e67d3);if(_0x46425b['query']['filter']){_0x4afc40[_0x200a('0x3d')]=_['merge'](_0x4afc40[_0x200a('0x3d')],{'$or':_['map'](_0x4e67d3,function(_0x144a9f){if(_0x144a9f[_0x200a('0x30')]!==_0x200a('0x3f')){var _0x35cad0={};_0x35cad0[_0x144a9f[_0x200a('0x2a')]]={'$like':'%'+_0x46425b[_0x200a('0x33')]['filter']+'%'};return _0x35cad0;}})});}_0x4afc40=_[_0x200a('0x40')]({},_0x4afc40,_0x46425b[_0x200a('0x41')]);var _0x1c7aed={'where':_0x4afc40[_0x200a('0x3d')]};return db['VtigerField']['count'](_0x1c7aed)[_0x200a('0x25')](function(_0x2f84ba){_0xe985ec[_0x200a('0x1e')]=_0x2f84ba;if(_0x46425b[_0x200a('0x33')]['includeAll']){_0x4afc40[_0x200a('0x42')]=[{'all':!![]}];}return db['VtigerField'][_0x200a('0x43')](_0x4afc40);})['then'](function(_0x530721){_0xe985ec[_0x200a('0x44')]=_0x530721;return _0xe985ec;})[_0x200a('0x25')](respondWithFilteredResult(_0x4e2bdf,_0x4afc40))['catch'](handleError(_0x4e2bdf,null));};exports[_0x200a('0x45')]=function(_0x1d2e71,_0x255e06){var _0x50e0a8={'raw':!![],'where':{'id':_0x1d2e71[_0x200a('0x46')]['id']}},_0x5134db={};_0x5134db['model']=_[_0x200a('0x34')](db[_0x200a('0x47')][_0x200a('0x2e')]);_0x5134db[_0x200a('0x33')]=_['keys'](_0x1d2e71[_0x200a('0x33')]);_0x5134db['filters']=_[_0x200a('0x35')](_0x5134db['model'],_0x5134db[_0x200a('0x33')]);_0x50e0a8['attributes']=_[_0x200a('0x35')](_0x5134db['model'],qs[_0x200a('0x36')](_0x1d2e71[_0x200a('0x33')][_0x200a('0x36')]));_0x50e0a8[_0x200a('0x37')]=_0x50e0a8[_0x200a('0x37')][_0x200a('0x38')]?_0x50e0a8[_0x200a('0x37')]:_0x5134db[_0x200a('0x32')];if(_0x1d2e71[_0x200a('0x33')][_0x200a('0x48')]){_0x50e0a8[_0x200a('0x42')]=[{'all':!![]}];}_0x50e0a8=_[_0x200a('0x40')]({},_0x50e0a8,_0x1d2e71['options']);return db[_0x200a('0x47')][_0x200a('0x49')](_0x50e0a8)[_0x200a('0x25')](handleEntityNotFound(_0x255e06,null))[_0x200a('0x25')](respondWithResult(_0x255e06,null))['catch'](handleError(_0x255e06,null));};exports[_0x200a('0x4a')]=function(_0x34fe90,_0x218eb3){return db[_0x200a('0x47')][_0x200a('0x4a')](_0x34fe90[_0x200a('0x4b')],{})['then'](respondWithResult(_0x218eb3,0xc9))[_0x200a('0x4c')](handleError(_0x218eb3,null));};exports[_0x200a('0x24')]=function(_0x59f0b5,_0x3b649){if(_0x59f0b5[_0x200a('0x4b')]['id']){delete _0x59f0b5['body']['id'];}return db[_0x200a('0x47')][_0x200a('0x49')]({'where':{'id':_0x59f0b5[_0x200a('0x46')]['id']}})[_0x200a('0x25')](handleEntityNotFound(_0x3b649,null))['then'](saveUpdates(_0x59f0b5[_0x200a('0x4b')],null))['then'](respondWithResult(_0x3b649,null))['catch'](handleError(_0x3b649,null));};exports[_0x200a('0x26')]=function(_0x134091,_0x12fc7a){return db[_0x200a('0x47')][_0x200a('0x49')]({'where':{'id':_0x134091[_0x200a('0x46')]['id']}})['then'](handleEntityNotFound(_0x12fc7a,null))['then'](removeEntity(_0x12fc7a,null))[_0x200a('0x4c')](handleError(_0x12fc7a,null));};