842317a2404770c7297c3ad8b4ad4c0a5d548e5e
[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 _0x6f58=['length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options','VtigerField','includeAll','include','findAll','params','keys','find','catch','create','body','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','to-csv','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','then','stack','name','send','index','map','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields'];(function(_0x3851ea,_0x2a2ee9){var _0x58db3c=function(_0x321c83){while(--_0x321c83){_0x3851ea['push'](_0x3851ea['shift']());}};_0x58db3c(++_0x2a2ee9);}(_0x6f58,0xe9));var _0x86f5=function(_0x228eb7,_0x526138){_0x228eb7=_0x228eb7-0x0;var _0x59da7a=_0x6f58[_0x228eb7];return _0x59da7a;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x86f5('0x0'));var zipdir=require(_0x86f5('0x1'));var jsonpatch=require(_0x86f5('0x2'));var rp=require('request-promise');var moment=require(_0x86f5('0x3'));var BPromise=require(_0x86f5('0x4'));var Mustache=require('mustache');var util=require(_0x86f5('0x5'));var path=require(_0x86f5('0x6'));var sox=require('sox');var csv=require(_0x86f5('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x86f5('0x8'));var squel=require('squel');var crypto=require(_0x86f5('0x9'));var jsforce=require(_0x86f5('0xa'));var deskjs=require(_0x86f5('0xb'));var toCsv=require(_0x86f5('0x7'));var querystring=require(_0x86f5('0xc'));var Papa=require(_0x86f5('0xd'));var Redis=require('ioredis');var authService=require(_0x86f5('0xe'));var qs=require(_0x86f5('0xf'));var as=require(_0x86f5('0x10'));var hardwareService=require(_0x86f5('0x11'));var logger=require(_0x86f5('0x12'))(_0x86f5('0x13'));var utils=require(_0x86f5('0x14'));var config=require(_0x86f5('0x15'));var db=require(_0x86f5('0x16'))['db'];function respondWithStatusCode(_0x272129,_0x264cbe){_0x264cbe=_0x264cbe||0xcc;return function(_0x4e2029){if(_0x4e2029){return _0x272129[_0x86f5('0x17')](_0x264cbe);}return _0x272129[_0x86f5('0x18')](_0x264cbe)[_0x86f5('0x19')]();};}function respondWithResult(_0x58ff3c,_0x9dafd){_0x9dafd=_0x9dafd||0xc8;return function(_0x5df6ad){if(_0x5df6ad){return _0x58ff3c[_0x86f5('0x18')](_0x9dafd)[_0x86f5('0x1a')](_0x5df6ad);}};}function respondWithFilteredResult(_0x4fea9f,_0x9b5f10){return function(_0x438619){if(_0x438619){var _0x27c5a5=_0x438619[_0x86f5('0x1b')],_0x8a4c28=_0x9b5f10[_0x86f5('0x1c')],_0xc297d8=_0x9b5f10[_0x86f5('0x1c')]+_0x9b5f10[_0x86f5('0x1d')],_0x5448c3;if(_0xc297d8>=_0x27c5a5){_0xc297d8=_0x27c5a5;_0x5448c3=0xc8;}else{_0x5448c3=0xce;}_0x4fea9f['status'](_0x5448c3);return _0x4fea9f[_0x86f5('0x1e')](_0x86f5('0x1f'),_0x8a4c28+'-'+_0xc297d8+'/'+_0x27c5a5)[_0x86f5('0x1a')](_0x438619);}return null;};}function patchUpdates(_0x48057d){return function(_0x3c8978){try{jsonpatch[_0x86f5('0x20')](_0x3c8978,_0x48057d,!![]);}catch(_0x2e2a01){return BPromise[_0x86f5('0x21')](_0x2e2a01);}return _0x3c8978[_0x86f5('0x22')]();};}function saveUpdates(_0x2dd300,_0x2ae4db){return function(_0x27e93f){if(_0x27e93f){return _0x27e93f['update'](_0x2dd300)[_0x86f5('0x23')](function(_0x4a2f85){return _0x4a2f85;});}return null;};}function removeEntity(_0x36bc77,_0xc77f9b){return function(_0x25887e){if(_0x25887e){return _0x25887e['destroy']()[_0x86f5('0x23')](function(){_0x36bc77[_0x86f5('0x18')](0xcc)[_0x86f5('0x19')]();});}};}function handleEntityNotFound(_0x2e0647,_0x4c4b8b){return function(_0x3fe9e7){if(!_0x3fe9e7){_0x2e0647['sendStatus'](0x194);}return _0x3fe9e7;};}function handleError(_0x46f147,_0x4ee00e){_0x4ee00e=_0x4ee00e||0x1f4;return function(_0x4416f5){logger['error'](_0x4416f5[_0x86f5('0x24')]);if(_0x4416f5['name']){delete _0x4416f5[_0x86f5('0x25')];}_0x46f147[_0x86f5('0x18')](_0x4ee00e)[_0x86f5('0x26')](_0x4416f5);};}exports[_0x86f5('0x27')]=function(_0x3fc3c6,_0xca25d3){var _0x4ab0c={},_0x4e8085={},_0xb9686e={'count':0x0,'rows':[]};var _0x138e46=_[_0x86f5('0x28')](db['VtigerField'][_0x86f5('0x29')],function(_0x54b8e6){return{'name':_0x54b8e6[_0x86f5('0x2a')],'type':_0x54b8e6[_0x86f5('0x2b')][_0x86f5('0x2c')]};});_0x4e8085['model']=_[_0x86f5('0x28')](_0x138e46,_0x86f5('0x25'));_0x4e8085[_0x86f5('0x2d')]=_['keys'](_0x3fc3c6[_0x86f5('0x2d')]);_0x4e8085[_0x86f5('0x2e')]=_[_0x86f5('0x2f')](_0x4e8085[_0x86f5('0x30')],_0x4e8085[_0x86f5('0x2d')]);_0x4ab0c[_0x86f5('0x31')]=_[_0x86f5('0x2f')](_0x4e8085[_0x86f5('0x30')],qs[_0x86f5('0x32')](_0x3fc3c6[_0x86f5('0x2d')][_0x86f5('0x32')]));_0x4ab0c[_0x86f5('0x31')]=_0x4ab0c[_0x86f5('0x31')][_0x86f5('0x33')]?_0x4ab0c[_0x86f5('0x31')]:_0x4e8085[_0x86f5('0x30')];if(!_0x3fc3c6[_0x86f5('0x2d')][_0x86f5('0x34')]('nolimit')){_0x4ab0c['limit']=qs[_0x86f5('0x1d')](_0x3fc3c6[_0x86f5('0x2d')][_0x86f5('0x1d')]);_0x4ab0c[_0x86f5('0x1c')]=qs[_0x86f5('0x1c')](_0x3fc3c6[_0x86f5('0x2d')][_0x86f5('0x1c')]);}_0x4ab0c[_0x86f5('0x35')]=qs['sort'](_0x3fc3c6[_0x86f5('0x2d')][_0x86f5('0x36')]);_0x4ab0c[_0x86f5('0x37')]=qs[_0x86f5('0x2e')](_[_0x86f5('0x38')](_0x3fc3c6[_0x86f5('0x2d')],_0x4e8085[_0x86f5('0x2e')]),_0x138e46);if(_0x3fc3c6[_0x86f5('0x2d')][_0x86f5('0x39')]){_0x4ab0c['where']=_[_0x86f5('0x3a')](_0x4ab0c['where'],{'$or':_[_0x86f5('0x28')](_0x138e46,function(_0x1b1ec9){if(_0x1b1ec9[_0x86f5('0x2b')]!==_0x86f5('0x3b')){var _0x13adde={};_0x13adde[_0x1b1ec9['name']]={'$like':'%'+_0x3fc3c6[_0x86f5('0x2d')]['filter']+'%'};return _0x13adde;}})});}_0x4ab0c=_[_0x86f5('0x3a')]({},_0x4ab0c,_0x3fc3c6[_0x86f5('0x3c')]);var _0x507842={'where':_0x4ab0c[_0x86f5('0x37')]};return db[_0x86f5('0x3d')][_0x86f5('0x1b')](_0x507842)[_0x86f5('0x23')](function(_0x5705c9){_0xb9686e['count']=_0x5705c9;if(_0x3fc3c6['query'][_0x86f5('0x3e')]){_0x4ab0c[_0x86f5('0x3f')]=[{'all':!![]}];}return db[_0x86f5('0x3d')][_0x86f5('0x40')](_0x4ab0c);})['then'](function(_0x41c001){_0xb9686e['rows']=_0x41c001;return _0xb9686e;})[_0x86f5('0x23')](respondWithFilteredResult(_0xca25d3,_0x4ab0c))['catch'](handleError(_0xca25d3,null));};exports['show']=function(_0x363d3a,_0x47b842){var _0x2db0c1={'raw':!![],'where':{'id':_0x363d3a[_0x86f5('0x41')]['id']}},_0x31bcda={};_0x31bcda[_0x86f5('0x30')]=_[_0x86f5('0x42')](db[_0x86f5('0x3d')][_0x86f5('0x29')]);_0x31bcda['query']=_[_0x86f5('0x42')](_0x363d3a[_0x86f5('0x2d')]);_0x31bcda[_0x86f5('0x2e')]=_[_0x86f5('0x2f')](_0x31bcda[_0x86f5('0x30')],_0x31bcda[_0x86f5('0x2d')]);_0x2db0c1[_0x86f5('0x31')]=_[_0x86f5('0x2f')](_0x31bcda[_0x86f5('0x30')],qs[_0x86f5('0x32')](_0x363d3a[_0x86f5('0x2d')][_0x86f5('0x32')]));_0x2db0c1[_0x86f5('0x31')]=_0x2db0c1['attributes']['length']?_0x2db0c1[_0x86f5('0x31')]:_0x31bcda[_0x86f5('0x30')];if(_0x363d3a['query'][_0x86f5('0x3e')]){_0x2db0c1[_0x86f5('0x3f')]=[{'all':!![]}];}_0x2db0c1=_[_0x86f5('0x3a')]({},_0x2db0c1,_0x363d3a[_0x86f5('0x3c')]);return db[_0x86f5('0x3d')][_0x86f5('0x43')](_0x2db0c1)['then'](handleEntityNotFound(_0x47b842,null))[_0x86f5('0x23')](respondWithResult(_0x47b842,null))[_0x86f5('0x44')](handleError(_0x47b842,null));};exports[_0x86f5('0x45')]=function(_0x20b958,_0x31a932){return db[_0x86f5('0x3d')][_0x86f5('0x45')](_0x20b958['body'],{})['then'](respondWithResult(_0x31a932,0xc9))[_0x86f5('0x44')](handleError(_0x31a932,null));};exports['update']=function(_0x380184,_0x34232e){if(_0x380184[_0x86f5('0x46')]['id']){delete _0x380184[_0x86f5('0x46')]['id'];}return db['VtigerField']['find']({'where':{'id':_0x380184[_0x86f5('0x41')]['id']}})[_0x86f5('0x23')](handleEntityNotFound(_0x34232e,null))[_0x86f5('0x23')](saveUpdates(_0x380184[_0x86f5('0x46')],null))['then'](respondWithResult(_0x34232e,null))[_0x86f5('0x44')](handleError(_0x34232e,null));};exports['destroy']=function(_0x3cc75a,_0x202e29){return db[_0x86f5('0x3d')]['find']({'where':{'id':_0x3cc75a['params']['id']}})[_0x86f5('0x23')](handleEntityNotFound(_0x202e29,null))['then'](removeEntity(_0x202e29,null))[_0x86f5('0x44')](handleError(_0x202e29,null));};