Built motion from commit 092f8824.|2.5.49
[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 _0x19f9=['options','create','body','find','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','sendStatus','end','status','json','undefined','count','set','reject','save','update','then','destroy','error','stack','name','index','map','VtigerField','rawAttributes','fieldName','type','key','model','query','intersection','attributes','fields','hasOwnProperty','nolimit','limit','offset','order','sort','where','filters','filter','merge','VIRTUAL','include','findAll','catch','show','params','keys','length'];(function(_0x1a9ed0,_0x1085fc){var _0x47bbd6=function(_0x27bd1c){while(--_0x27bd1c){_0x1a9ed0['push'](_0x1a9ed0['shift']());}};_0x47bbd6(++_0x1085fc);}(_0x19f9,0x124));var _0x919f=function(_0x46d0c9,_0x526bfa){_0x46d0c9=_0x46d0c9-0x0;var _0x174506=_0x19f9[_0x46d0c9];return _0x174506;};'use strict';var emlformat=require(_0x919f('0x0'));var rimraf=require(_0x919f('0x1'));var zipdir=require(_0x919f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x919f('0x3'));var moment=require(_0x919f('0x4'));var BPromise=require(_0x919f('0x5'));var Mustache=require('mustache');var util=require(_0x919f('0x6'));var path=require(_0x919f('0x7'));var sox=require(_0x919f('0x8'));var csv=require(_0x919f('0x9'));var ejs=require(_0x919f('0xa'));var fs=require('fs');var fs_extra=require(_0x919f('0xb'));var _=require(_0x919f('0xc'));var squel=require(_0x919f('0xd'));var crypto=require(_0x919f('0xe'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x919f('0x9'));var querystring=require(_0x919f('0xf'));var Papa=require(_0x919f('0x10'));var Redis=require(_0x919f('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x919f('0x12'));var hardwareService=require(_0x919f('0x13'));var logger=require(_0x919f('0x14'))(_0x919f('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x919f('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x19aac4,_0x1bad6f){_0x1bad6f=_0x1bad6f||0xcc;return function(_0x32fbe8){if(_0x32fbe8){return _0x19aac4[_0x919f('0x17')](_0x1bad6f);}return _0x19aac4['status'](_0x1bad6f)[_0x919f('0x18')]();};}function respondWithResult(_0x5513ca,_0x4d0170){_0x4d0170=_0x4d0170||0xc8;return function(_0x25518a){if(_0x25518a){return _0x5513ca[_0x919f('0x19')](_0x4d0170)[_0x919f('0x1a')](_0x25518a);}};}function respondWithFilteredResult(_0x22cb24,_0x3d1970){return function(_0x470c42){if(_0x470c42){var _0xc69b17=typeof _0x3d1970['offset']===_0x919f('0x1b')&&typeof _0x3d1970['limit']==='undefined';var _0x447cd3=_0x470c42[_0x919f('0x1c')];var _0x5d7522=_0xc69b17?0x0:_0x3d1970['offset'];var _0x18b02c=_0xc69b17?_0x470c42['count']:_0x3d1970['offset']+_0x3d1970['limit'];var _0x16551f;if(_0x18b02c>=_0x447cd3){_0x18b02c=_0x447cd3;_0x16551f=0xc8;}else{_0x16551f=0xce;}_0x22cb24['status'](_0x16551f);return _0x22cb24[_0x919f('0x1d')]('Content-Range',_0x5d7522+'-'+_0x18b02c+'/'+_0x447cd3)[_0x919f('0x1a')](_0x470c42);}return null;};}function patchUpdates(_0x53cb32){return function(_0x330f1e){try{jsonpatch['apply'](_0x330f1e,_0x53cb32,!![]);}catch(_0x164ef9){return BPromise[_0x919f('0x1e')](_0x164ef9);}return _0x330f1e[_0x919f('0x1f')]();};}function saveUpdates(_0x5c9812,_0x225bd5){return function(_0x5c959d){if(_0x5c959d){return _0x5c959d[_0x919f('0x20')](_0x5c9812)[_0x919f('0x21')](function(_0x5203b6){return _0x5203b6;});}return null;};}function removeEntity(_0x410493,_0x40d1b7){return function(_0x5a55eb){if(_0x5a55eb){return _0x5a55eb[_0x919f('0x22')]()[_0x919f('0x21')](function(){_0x410493['status'](0xcc)[_0x919f('0x18')]();});}};}function handleEntityNotFound(_0x3f5d23,_0x287195){return function(_0x3ade2c){if(!_0x3ade2c){_0x3f5d23[_0x919f('0x17')](0x194);}return _0x3ade2c;};}function handleError(_0x56d54c,_0x571f3e){_0x571f3e=_0x571f3e||0x1f4;return function(_0xc7faab){logger[_0x919f('0x23')](_0xc7faab[_0x919f('0x24')]);if(_0xc7faab[_0x919f('0x25')]){delete _0xc7faab['name'];}_0x56d54c[_0x919f('0x19')](_0x571f3e)['send'](_0xc7faab);};}exports[_0x919f('0x26')]=function(_0x2636ea,_0x10563b){var _0x12f20f={},_0x2cf6e7={},_0xff884f={'count':0x0,'rows':[]};var _0x23f34d=_[_0x919f('0x27')](db[_0x919f('0x28')][_0x919f('0x29')],function(_0x2d7167){return{'name':_0x2d7167[_0x919f('0x2a')],'type':_0x2d7167[_0x919f('0x2b')][_0x919f('0x2c')]};});_0x2cf6e7[_0x919f('0x2d')]=_[_0x919f('0x27')](_0x23f34d,_0x919f('0x25'));_0x2cf6e7[_0x919f('0x2e')]=_['keys'](_0x2636ea[_0x919f('0x2e')]);_0x2cf6e7['filters']=_[_0x919f('0x2f')](_0x2cf6e7[_0x919f('0x2d')],_0x2cf6e7[_0x919f('0x2e')]);_0x12f20f[_0x919f('0x30')]=_[_0x919f('0x2f')](_0x2cf6e7[_0x919f('0x2d')],qs[_0x919f('0x31')](_0x2636ea['query'][_0x919f('0x31')]));_0x12f20f[_0x919f('0x30')]=_0x12f20f[_0x919f('0x30')]['length']?_0x12f20f['attributes']:_0x2cf6e7[_0x919f('0x2d')];if(!_0x2636ea[_0x919f('0x2e')][_0x919f('0x32')](_0x919f('0x33'))){_0x12f20f[_0x919f('0x34')]=qs[_0x919f('0x34')](_0x2636ea[_0x919f('0x2e')][_0x919f('0x34')]);_0x12f20f[_0x919f('0x35')]=qs[_0x919f('0x35')](_0x2636ea[_0x919f('0x2e')][_0x919f('0x35')]);}_0x12f20f[_0x919f('0x36')]=qs[_0x919f('0x37')](_0x2636ea[_0x919f('0x2e')][_0x919f('0x37')]);_0x12f20f[_0x919f('0x38')]=qs[_0x919f('0x39')](_['pick'](_0x2636ea['query'],_0x2cf6e7[_0x919f('0x39')]),_0x23f34d);if(_0x2636ea[_0x919f('0x2e')][_0x919f('0x3a')]){_0x12f20f[_0x919f('0x38')]=_[_0x919f('0x3b')](_0x12f20f[_0x919f('0x38')],{'$or':_['map'](_0x23f34d,function(_0x3f9fb3){if(_0x3f9fb3[_0x919f('0x2b')]!==_0x919f('0x3c')){var _0x4ab8c8={};_0x4ab8c8[_0x3f9fb3[_0x919f('0x25')]]={'$like':'%'+_0x2636ea[_0x919f('0x2e')][_0x919f('0x3a')]+'%'};return _0x4ab8c8;}})});}_0x12f20f=_['merge']({},_0x12f20f,_0x2636ea['options']);var _0x188fd5={'where':_0x12f20f['where']};return db[_0x919f('0x28')][_0x919f('0x1c')](_0x188fd5)[_0x919f('0x21')](function(_0x166d03){_0xff884f['count']=_0x166d03;if(_0x2636ea[_0x919f('0x2e')]['includeAll']){_0x12f20f[_0x919f('0x3d')]=[{'all':!![]}];}return db[_0x919f('0x28')][_0x919f('0x3e')](_0x12f20f);})['then'](function(_0x12aa7b){_0xff884f['rows']=_0x12aa7b;return _0xff884f;})['then'](respondWithFilteredResult(_0x10563b,_0x12f20f))[_0x919f('0x3f')](handleError(_0x10563b,null));};exports[_0x919f('0x40')]=function(_0x142781,_0x6859c4){var _0x266a51={'raw':!![],'where':{'id':_0x142781[_0x919f('0x41')]['id']}},_0x1bea67={};_0x1bea67[_0x919f('0x2d')]=_[_0x919f('0x42')](db[_0x919f('0x28')][_0x919f('0x29')]);_0x1bea67[_0x919f('0x2e')]=_['keys'](_0x142781[_0x919f('0x2e')]);_0x1bea67['filters']=_[_0x919f('0x2f')](_0x1bea67[_0x919f('0x2d')],_0x1bea67[_0x919f('0x2e')]);_0x266a51[_0x919f('0x30')]=_[_0x919f('0x2f')](_0x1bea67['model'],qs['fields'](_0x142781[_0x919f('0x2e')]['fields']));_0x266a51[_0x919f('0x30')]=_0x266a51[_0x919f('0x30')][_0x919f('0x43')]?_0x266a51['attributes']:_0x1bea67[_0x919f('0x2d')];if(_0x142781['query']['includeAll']){_0x266a51[_0x919f('0x3d')]=[{'all':!![]}];}_0x266a51=_[_0x919f('0x3b')]({},_0x266a51,_0x142781[_0x919f('0x44')]);return db[_0x919f('0x28')]['find'](_0x266a51)[_0x919f('0x21')](handleEntityNotFound(_0x6859c4,null))[_0x919f('0x21')](respondWithResult(_0x6859c4,null))[_0x919f('0x3f')](handleError(_0x6859c4,null));};exports['create']=function(_0xe5cb7f,_0x3cee0e){return db['VtigerField'][_0x919f('0x45')](_0xe5cb7f[_0x919f('0x46')],{})[_0x919f('0x21')](respondWithResult(_0x3cee0e,0xc9))[_0x919f('0x3f')](handleError(_0x3cee0e,null));};exports[_0x919f('0x20')]=function(_0x293449,_0x9e373b){if(_0x293449[_0x919f('0x46')]['id']){delete _0x293449['body']['id'];}return db[_0x919f('0x28')][_0x919f('0x47')]({'where':{'id':_0x293449['params']['id']}})['then'](handleEntityNotFound(_0x9e373b,null))[_0x919f('0x21')](saveUpdates(_0x293449['body'],null))['then'](respondWithResult(_0x9e373b,null))['catch'](handleError(_0x9e373b,null));};exports[_0x919f('0x22')]=function(_0x243f72,_0x3ca86a){return db[_0x919f('0x28')][_0x919f('0x47')]({'where':{'id':_0x243f72[_0x919f('0x41')]['id']}})[_0x919f('0x21')](handleEntityNotFound(_0x3ca86a,null))['then'](removeEntity(_0x3ca86a,null))['catch'](handleError(_0x3ca86a,null));};