Built motion from commit (unavailable).|2.3.1
[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 _0xd2be=['params','rawAttributes','options','find','create','body','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','jsforce','papaparse','../../components/auth/service','../../config/license/hardware','ioredis','../../mysqldb','status','end','json','count','offset','apply','reject','save','update','then','destroy','sendStatus','error','name','index','VtigerField','model','keys','query','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','where','filters','pick','filter','merge','map','key','field','includeAll','include','findAll','rows','catch','show'];(function(_0x52c5cc,_0x1d948f){var _0x4ab346=function(_0x3d941d){while(--_0x3d941d){_0x52c5cc['push'](_0x52c5cc['shift']());}};_0x4ab346(++_0x1d948f);}(_0xd2be,0x86));var _0xed2b=function(_0x9a7796,_0xe30784){_0x9a7796=_0x9a7796-0x0;var _0x2e73a0=_0xd2be[_0x9a7796];return _0x2e73a0;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xed2b('0x0'));var zipdir=require(_0xed2b('0x1'));var jsonpatch=require(_0xed2b('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xed2b('0x3'));var Mustache=require(_0xed2b('0x4'));var util=require(_0xed2b('0x5'));var path=require(_0xed2b('0x6'));var sox=require('sox');var csv=require(_0xed2b('0x7'));var ejs=require(_0xed2b('0x8'));var fs=require('fs');var _=require(_0xed2b('0x9'));var squel=require(_0xed2b('0xa'));var crypto=require('crypto');var jsforce=require(_0xed2b('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xed2b('0xc'));var authService=require(_0xed2b('0xd'));var hardwareService=require(_0xed2b('0xe'));var Redis=require(_0xed2b('0xf'));var qs=require('../../components/parsers/qs');var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0xed2b('0x10'))['db'];function respondWithStatusCode(_0x1421c4,_0x5df3d9){_0x5df3d9=_0x5df3d9||0xcc;return function(_0x3bda34){if(_0x3bda34){return _0x1421c4['sendStatus'](_0x5df3d9);}return _0x1421c4[_0xed2b('0x11')](_0x5df3d9)[_0xed2b('0x12')]();};}function respondWithResult(_0x366d2a,_0x111901){_0x111901=_0x111901||0xc8;return function(_0x3dd18b){if(_0x3dd18b){return _0x366d2a[_0xed2b('0x11')](_0x111901)[_0xed2b('0x13')](_0x3dd18b);}};}function respondWithFilteredResult(_0x5a08b0,_0x4ae146){return function(_0x1a6b66){if(_0x1a6b66){var _0xa6c74c=_0x1a6b66[_0xed2b('0x14')],_0x4fcf61=_0x4ae146[_0xed2b('0x15')],_0x4c9198=_0x4ae146['offset']+_0x4ae146['limit'],_0x13119d;if(_0x4c9198>=_0xa6c74c){_0x4c9198=_0xa6c74c;_0x13119d=0xc8;}else{_0x13119d=0xce;}_0x5a08b0[_0xed2b('0x11')](_0x13119d);return _0x5a08b0['set']('Content-Range',_0x4fcf61+'-'+_0x4c9198+'/'+_0xa6c74c)[_0xed2b('0x13')](_0x1a6b66);}return null;};}function patchUpdates(_0x572b39){return function(_0x173b44){try{jsonpatch[_0xed2b('0x16')](_0x173b44,_0x572b39,!![]);}catch(_0x29dd2e){return BPromise[_0xed2b('0x17')](_0x29dd2e);}return _0x173b44[_0xed2b('0x18')]();};}function saveUpdates(_0x52c32d,_0x545045){return function(_0x39f1a2){if(_0x39f1a2){return _0x39f1a2[_0xed2b('0x19')](_0x52c32d)[_0xed2b('0x1a')](function(_0xcd06b9){return _0xcd06b9;});}return null;};}function removeEntity(_0x42e92a,_0x40668a){return function(_0x21306b){if(_0x21306b){return _0x21306b[_0xed2b('0x1b')]()[_0xed2b('0x1a')](function(){_0x42e92a['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x53911d,_0x1a244e){return function(_0xfc2f52){if(!_0xfc2f52){_0x53911d[_0xed2b('0x1c')](0x194);}return _0xfc2f52;};}function handleError(_0x4deda7,_0x15d036){_0x15d036=_0x15d036||0x1f4;return function(_0x313c13){logger[_0xed2b('0x1d')](_0x313c13['stack']);if(_0x313c13['name']){delete _0x313c13[_0xed2b('0x1e')];}_0x4deda7[_0xed2b('0x11')](_0x15d036)['send'](_0x313c13);};}exports[_0xed2b('0x1f')]=function(_0x2f4755,_0x50e57e){var _0x169135={},_0x5ef8c1={},_0x51ae98={'count':0x0,'rows':[]};var _0x56c741=db[_0xed2b('0x20')]['rawAttributes'];_0x5ef8c1[_0xed2b('0x21')]=_[_0xed2b('0x22')](_0x56c741);_0x5ef8c1['query']=_[_0xed2b('0x22')](_0x2f4755[_0xed2b('0x23')]);_0x5ef8c1['filters']=_[_0xed2b('0x24')](_0x5ef8c1[_0xed2b('0x21')],_0x5ef8c1[_0xed2b('0x23')]);_0x169135[_0xed2b('0x25')]=_['intersection'](_0x5ef8c1[_0xed2b('0x21')],qs[_0xed2b('0x26')](_0x2f4755[_0xed2b('0x23')][_0xed2b('0x26')]));_0x169135[_0xed2b('0x25')]=_0x169135[_0xed2b('0x25')][_0xed2b('0x27')]?_0x169135[_0xed2b('0x25')]:_0x5ef8c1[_0xed2b('0x21')];if(!_0x2f4755[_0xed2b('0x23')][_0xed2b('0x28')]('nolimit')){_0x169135[_0xed2b('0x29')]=qs[_0xed2b('0x29')](_0x2f4755[_0xed2b('0x23')][_0xed2b('0x29')]);_0x169135[_0xed2b('0x15')]=qs['offset'](_0x2f4755[_0xed2b('0x23')][_0xed2b('0x15')]);}_0x169135[_0xed2b('0x2a')]=qs['sort'](_0x2f4755[_0xed2b('0x23')][_0xed2b('0x2b')]);_0x169135[_0xed2b('0x2c')]=qs[_0xed2b('0x2d')](_[_0xed2b('0x2e')](_0x2f4755[_0xed2b('0x23')],_0x5ef8c1[_0xed2b('0x2d')]));if(_0x2f4755['query'][_0xed2b('0x2f')]){_0x169135[_0xed2b('0x2c')]=_[_0xed2b('0x30')](_0x169135[_0xed2b('0x2c')],{'$or':_[_0xed2b('0x31')](_0x56c741,function(_0x394314){if(_0x394314['type'][_0xed2b('0x32')]!=='VIRTUAL'){var _0xa5a57a={};_0xa5a57a[_0x394314[_0xed2b('0x33')]]={'$like':'%'+_0x2f4755['query'][_0xed2b('0x2f')]+'%'};return _0xa5a57a;}})});}_0x169135=_[_0xed2b('0x30')]({},_0x169135,_0x2f4755['options']);var _0x26e8d1={'where':_0x169135[_0xed2b('0x2c')]};return db[_0xed2b('0x20')][_0xed2b('0x14')](_0x26e8d1)[_0xed2b('0x1a')](function(_0x30ac08){_0x51ae98[_0xed2b('0x14')]=_0x30ac08;if(_0x2f4755[_0xed2b('0x23')][_0xed2b('0x34')]){_0x169135[_0xed2b('0x35')]=[{'all':!![]}];}return db[_0xed2b('0x20')][_0xed2b('0x36')](_0x169135);})['then'](function(_0x3ab194){_0x51ae98[_0xed2b('0x37')]=_0x3ab194;return _0x51ae98;})[_0xed2b('0x1a')](respondWithFilteredResult(_0x50e57e,_0x169135))[_0xed2b('0x38')](handleError(_0x50e57e,null));};exports[_0xed2b('0x39')]=function(_0x3fdb84,_0xe43e86){var _0x28b333={'raw':!![],'where':{'id':_0x3fdb84[_0xed2b('0x3a')]['id']}},_0x3e7de6={};_0x3e7de6[_0xed2b('0x21')]=_['keys'](db[_0xed2b('0x20')][_0xed2b('0x3b')]);_0x3e7de6[_0xed2b('0x23')]=_[_0xed2b('0x22')](_0x3fdb84['query']);_0x3e7de6[_0xed2b('0x2d')]=_[_0xed2b('0x24')](_0x3e7de6[_0xed2b('0x21')],_0x3e7de6[_0xed2b('0x23')]);_0x28b333[_0xed2b('0x25')]=_[_0xed2b('0x24')](_0x3e7de6['model'],qs[_0xed2b('0x26')](_0x3fdb84[_0xed2b('0x23')][_0xed2b('0x26')]));_0x28b333[_0xed2b('0x25')]=_0x28b333['attributes'][_0xed2b('0x27')]?_0x28b333['attributes']:_0x3e7de6[_0xed2b('0x21')];if(_0x3fdb84[_0xed2b('0x23')][_0xed2b('0x34')]){_0x28b333[_0xed2b('0x35')]=[{'all':!![]}];}_0x28b333=_['merge']({},_0x28b333,_0x3fdb84[_0xed2b('0x3c')]);return db[_0xed2b('0x20')][_0xed2b('0x3d')](_0x28b333)[_0xed2b('0x1a')](handleEntityNotFound(_0xe43e86,null))['then'](respondWithResult(_0xe43e86,null))[_0xed2b('0x38')](handleError(_0xe43e86,null));};exports['create']=function(_0x4fd2cb,_0x32f4bf){return db['VtigerField'][_0xed2b('0x3e')](_0x4fd2cb[_0xed2b('0x3f')],{})[_0xed2b('0x1a')](respondWithResult(_0x32f4bf,0xc9))['catch'](handleError(_0x32f4bf,null));};exports[_0xed2b('0x19')]=function(_0x5dfd6b,_0x4d1d36){if(_0x5dfd6b[_0xed2b('0x3f')]['id']){delete _0x5dfd6b[_0xed2b('0x3f')]['id'];}return db[_0xed2b('0x20')][_0xed2b('0x3d')]({'where':{'id':_0x5dfd6b[_0xed2b('0x3a')]['id']}})[_0xed2b('0x1a')](handleEntityNotFound(_0x4d1d36,null))[_0xed2b('0x1a')](saveUpdates(_0x5dfd6b[_0xed2b('0x3f')],null))[_0xed2b('0x1a')](respondWithResult(_0x4d1d36,null))[_0xed2b('0x38')](handleError(_0x4d1d36,null));};exports['destroy']=function(_0x41bdcd,_0x581ffe){return db['VtigerField'][_0xed2b('0x3d')]({'where':{'id':_0x41bdcd['params']['id']}})[_0xed2b('0x1a')](handleEntityNotFound(_0x581ffe,null))['then'](removeEntity(_0x581ffe,null))[_0xed2b('0x38')](handleError(_0x581ffe,null));};