dcf9bdf1429a8ff6d96365d686f73c29b2d7c494
[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 _0xa8fe=['nolimit','order','sort','where','merge','VIRTUAL','options','count','include','findAll','rows','catch','show','params','includeAll','find','create','body','update','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','ejs','lodash','squel','jsforce','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','set','Content-Range','apply','reject','destroy','then','error','stack','name','send','index','map','VtigerField','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty'];(function(_0x5d47f9,_0x5cd0cb){var _0x1163c2=function(_0x166f9e){while(--_0x166f9e){_0x5d47f9['push'](_0x5d47f9['shift']());}};_0x1163c2(++_0x5cd0cb);}(_0xa8fe,0x180));var _0xea8f=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0xa8fe[_0x4a9fb1];return _0x348672;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xea8f('0x0'));var rimraf=require(_0xea8f('0x1'));var zipdir=require(_0xea8f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xea8f('0x3'));var moment=require('moment');var BPromise=require(_0xea8f('0x4'));var Mustache=require(_0xea8f('0x5'));var util=require(_0xea8f('0x6'));var path=require(_0xea8f('0x7'));var sox=require(_0xea8f('0x8'));var csv=require('to-csv');var ejs=require(_0xea8f('0x9'));var fs=require('fs');var _=require(_0xea8f('0xa'));var squel=require(_0xea8f('0xb'));var crypto=require('crypto');var jsforce=require(_0xea8f('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xea8f('0xd'));var querystring=require(_0xea8f('0xe'));var Papa=require('papaparse');var Redis=require(_0xea8f('0xf'));var authService=require(_0xea8f('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xea8f('0x11'));var hardwareService=require(_0xea8f('0x12'));var logger=require(_0xea8f('0x13'))('api');var utils=require(_0xea8f('0x14'));var config=require(_0xea8f('0x15'));var licenseUtil=require(_0xea8f('0x16'));var db=require(_0xea8f('0x17'))['db'];function respondWithStatusCode(_0x5e95ea,_0x12b02f){_0x12b02f=_0x12b02f||0xcc;return function(_0x3af9be){if(_0x3af9be){return _0x5e95ea[_0xea8f('0x18')](_0x12b02f);}return _0x5e95ea[_0xea8f('0x19')](_0x12b02f)['end']();};}function respondWithResult(_0xb544b6,_0x280810){_0x280810=_0x280810||0xc8;return function(_0x53badd){if(_0x53badd){return _0xb544b6[_0xea8f('0x19')](_0x280810)[_0xea8f('0x1a')](_0x53badd);}};}function respondWithFilteredResult(_0xb386fa,_0x594eab){return function(_0x47543b){if(_0x47543b){var _0x1326cd=_0x47543b['count'],_0x47779e=_0x594eab[_0xea8f('0x1b')],_0x3ac045=_0x594eab[_0xea8f('0x1b')]+_0x594eab[_0xea8f('0x1c')],_0x18e208;if(_0x3ac045>=_0x1326cd){_0x3ac045=_0x1326cd;_0x18e208=0xc8;}else{_0x18e208=0xce;}_0xb386fa[_0xea8f('0x19')](_0x18e208);return _0xb386fa[_0xea8f('0x1d')](_0xea8f('0x1e'),_0x47779e+'-'+_0x3ac045+'/'+_0x1326cd)[_0xea8f('0x1a')](_0x47543b);}return null;};}function patchUpdates(_0x5ad326){return function(_0x13faf3){try{jsonpatch[_0xea8f('0x1f')](_0x13faf3,_0x5ad326,!![]);}catch(_0x13ac12){return BPromise[_0xea8f('0x20')](_0x13ac12);}return _0x13faf3['save']();};}function saveUpdates(_0x1f9b8f,_0x2fc5d3){return function(_0x2f1ad3){if(_0x2f1ad3){return _0x2f1ad3['update'](_0x1f9b8f)['then'](function(_0x317244){return _0x317244;});}return null;};}function removeEntity(_0x51396d,_0x289b42){return function(_0x19b7dc){if(_0x19b7dc){return _0x19b7dc[_0xea8f('0x21')]()[_0xea8f('0x22')](function(){_0x51396d[_0xea8f('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x127f9d,_0x5b69ff){return function(_0x489045){if(!_0x489045){_0x127f9d[_0xea8f('0x18')](0x194);}return _0x489045;};}function handleError(_0x10e259,_0x511f17){_0x511f17=_0x511f17||0x1f4;return function(_0x1f9a71){logger[_0xea8f('0x23')](_0x1f9a71[_0xea8f('0x24')]);if(_0x1f9a71[_0xea8f('0x25')]){delete _0x1f9a71[_0xea8f('0x25')];}_0x10e259['status'](_0x511f17)[_0xea8f('0x26')](_0x1f9a71);};}exports[_0xea8f('0x27')]=function(_0x5e8acb,_0x29ff){var _0x4af3f8={},_0x584e11={},_0x558a49={'count':0x0,'rows':[]};var _0x13adb9=_[_0xea8f('0x28')](db[_0xea8f('0x29')][_0xea8f('0x2a')],function(_0x174133){return{'name':_0x174133['fieldName'],'type':_0x174133[_0xea8f('0x2b')][_0xea8f('0x2c')]};});_0x584e11[_0xea8f('0x2d')]=_[_0xea8f('0x28')](_0x13adb9,_0xea8f('0x25'));_0x584e11[_0xea8f('0x2e')]=_[_0xea8f('0x2f')](_0x5e8acb[_0xea8f('0x2e')]);_0x584e11[_0xea8f('0x30')]=_[_0xea8f('0x31')](_0x584e11[_0xea8f('0x2d')],_0x584e11[_0xea8f('0x2e')]);_0x4af3f8[_0xea8f('0x32')]=_[_0xea8f('0x31')](_0x584e11[_0xea8f('0x2d')],qs['fields'](_0x5e8acb[_0xea8f('0x2e')][_0xea8f('0x33')]));_0x4af3f8[_0xea8f('0x32')]=_0x4af3f8[_0xea8f('0x32')][_0xea8f('0x34')]?_0x4af3f8[_0xea8f('0x32')]:_0x584e11[_0xea8f('0x2d')];if(!_0x5e8acb[_0xea8f('0x2e')][_0xea8f('0x35')](_0xea8f('0x36'))){_0x4af3f8[_0xea8f('0x1c')]=qs['limit'](_0x5e8acb[_0xea8f('0x2e')]['limit']);_0x4af3f8[_0xea8f('0x1b')]=qs[_0xea8f('0x1b')](_0x5e8acb[_0xea8f('0x2e')][_0xea8f('0x1b')]);}_0x4af3f8[_0xea8f('0x37')]=qs[_0xea8f('0x38')](_0x5e8acb[_0xea8f('0x2e')][_0xea8f('0x38')]);_0x4af3f8[_0xea8f('0x39')]=qs['filters'](_['pick'](_0x5e8acb[_0xea8f('0x2e')],_0x584e11[_0xea8f('0x30')]),_0x13adb9);if(_0x5e8acb[_0xea8f('0x2e')]['filter']){_0x4af3f8['where']=_[_0xea8f('0x3a')](_0x4af3f8[_0xea8f('0x39')],{'$or':_['map'](_0x13adb9,function(_0x2ee63d){if(_0x2ee63d['type']!==_0xea8f('0x3b')){var _0x4792d9={};_0x4792d9[_0x2ee63d[_0xea8f('0x25')]]={'$like':'%'+_0x5e8acb[_0xea8f('0x2e')]['filter']+'%'};return _0x4792d9;}})});}_0x4af3f8=_[_0xea8f('0x3a')]({},_0x4af3f8,_0x5e8acb[_0xea8f('0x3c')]);var _0x5cb4ed={'where':_0x4af3f8[_0xea8f('0x39')]};return db['VtigerField']['count'](_0x5cb4ed)[_0xea8f('0x22')](function(_0xff9446){_0x558a49[_0xea8f('0x3d')]=_0xff9446;if(_0x5e8acb[_0xea8f('0x2e')]['includeAll']){_0x4af3f8[_0xea8f('0x3e')]=[{'all':!![]}];}return db[_0xea8f('0x29')][_0xea8f('0x3f')](_0x4af3f8);})['then'](function(_0x354048){_0x558a49[_0xea8f('0x40')]=_0x354048;return _0x558a49;})[_0xea8f('0x22')](respondWithFilteredResult(_0x29ff,_0x4af3f8))[_0xea8f('0x41')](handleError(_0x29ff,null));};exports[_0xea8f('0x42')]=function(_0x20e250,_0x2355da){var _0x54551c={'raw':!![],'where':{'id':_0x20e250[_0xea8f('0x43')]['id']}},_0x83be3e={};_0x83be3e[_0xea8f('0x2d')]=_['keys'](db['VtigerField'][_0xea8f('0x2a')]);_0x83be3e[_0xea8f('0x2e')]=_[_0xea8f('0x2f')](_0x20e250['query']);_0x83be3e[_0xea8f('0x30')]=_['intersection'](_0x83be3e[_0xea8f('0x2d')],_0x83be3e[_0xea8f('0x2e')]);_0x54551c[_0xea8f('0x32')]=_[_0xea8f('0x31')](_0x83be3e[_0xea8f('0x2d')],qs[_0xea8f('0x33')](_0x20e250[_0xea8f('0x2e')][_0xea8f('0x33')]));_0x54551c[_0xea8f('0x32')]=_0x54551c[_0xea8f('0x32')]['length']?_0x54551c[_0xea8f('0x32')]:_0x83be3e['model'];if(_0x20e250[_0xea8f('0x2e')][_0xea8f('0x44')]){_0x54551c['include']=[{'all':!![]}];}_0x54551c=_[_0xea8f('0x3a')]({},_0x54551c,_0x20e250[_0xea8f('0x3c')]);return db[_0xea8f('0x29')][_0xea8f('0x45')](_0x54551c)[_0xea8f('0x22')](handleEntityNotFound(_0x2355da,null))['then'](respondWithResult(_0x2355da,null))[_0xea8f('0x41')](handleError(_0x2355da,null));};exports[_0xea8f('0x46')]=function(_0x219e30,_0x5872af){return db[_0xea8f('0x29')][_0xea8f('0x46')](_0x219e30[_0xea8f('0x47')],{})['then'](respondWithResult(_0x5872af,0xc9))[_0xea8f('0x41')](handleError(_0x5872af,null));};exports[_0xea8f('0x48')]=function(_0x31503c,_0x4a7bed){if(_0x31503c['body']['id']){delete _0x31503c[_0xea8f('0x47')]['id'];}return db[_0xea8f('0x29')][_0xea8f('0x45')]({'where':{'id':_0x31503c['params']['id']}})[_0xea8f('0x22')](handleEntityNotFound(_0x4a7bed,null))[_0xea8f('0x22')](saveUpdates(_0x31503c['body'],null))[_0xea8f('0x22')](respondWithResult(_0x4a7bed,null))[_0xea8f('0x41')](handleError(_0x4a7bed,null));};exports[_0xea8f('0x21')]=function(_0x3a02ed,_0x2c44eb){return db[_0xea8f('0x29')]['find']({'where':{'id':_0x3a02ed['params']['id']}})[_0xea8f('0x22')](handleEntityNotFound(_0x2c44eb,null))[_0xea8f('0x22')](removeEntity(_0x2c44eb,null))[_0xea8f('0x41')](handleError(_0x2c44eb,null));};