Built motion from commit (unavailable).|2.5.0
[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 _0x530f=['querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','then','destroy','end','error','stack','name','send','index','map','key','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','VIRTUAL','options','VtigerField','includeAll','include','findAll','rows','catch','show','rawAttributes','length','find','create','update','body','params','html-pdf','eml-format','rimraf','zip-dir','bluebird','mustache','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv'];(function(_0x26a9e0,_0x1c482a){var _0x2756e4=function(_0x4e9677){while(--_0x4e9677){_0x26a9e0['push'](_0x26a9e0['shift']());}};_0x2756e4(++_0x1c482a);}(_0x530f,0x1ba));var _0xf530=function(_0x3d474e,_0x431f54){_0x3d474e=_0x3d474e-0x0;var _0x30b3e3=_0x530f[_0x3d474e];return _0x30b3e3;};'use strict';var pdf=require(_0xf530('0x0'));var emlformat=require(_0xf530('0x1'));var rimraf=require(_0xf530('0x2'));var zipdir=require(_0xf530('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xf530('0x4'));var Mustache=require(_0xf530('0x5'));var util=require('util');var path=require(_0xf530('0x6'));var sox=require(_0xf530('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xf530('0x8'));var squel=require(_0xf530('0x9'));var crypto=require(_0xf530('0xa'));var jsforce=require(_0xf530('0xb'));var deskjs=require(_0xf530('0xc'));var toCsv=require(_0xf530('0xd'));var querystring=require(_0xf530('0xe'));var Papa=require(_0xf530('0xf'));var Redis=require(_0xf530('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xf530('0x11'));var as=require(_0xf530('0x12'));var hardwareService=require(_0xf530('0x13'));var logger=require('../../config/logger')(_0xf530('0x14'));var utils=require(_0xf530('0x15'));var config=require(_0xf530('0x16'));var db=require(_0xf530('0x17'))['db'];function respondWithStatusCode(_0x44c382,_0x250922){_0x250922=_0x250922||0xcc;return function(_0x138a5f){if(_0x138a5f){return _0x44c382[_0xf530('0x18')](_0x250922);}return _0x44c382[_0xf530('0x19')](_0x250922)['end']();};}function respondWithResult(_0x19992b,_0x32f868){_0x32f868=_0x32f868||0xc8;return function(_0x3b2374){if(_0x3b2374){return _0x19992b[_0xf530('0x19')](_0x32f868)[_0xf530('0x1a')](_0x3b2374);}};}function respondWithFilteredResult(_0x3b8903,_0x148f6c){return function(_0x17f74c){if(_0x17f74c){var _0x5407d3=_0x17f74c[_0xf530('0x1b')],_0x5e6f22=_0x148f6c[_0xf530('0x1c')],_0x323969=_0x148f6c[_0xf530('0x1c')]+_0x148f6c[_0xf530('0x1d')],_0x18f78e;if(_0x323969>=_0x5407d3){_0x323969=_0x5407d3;_0x18f78e=0xc8;}else{_0x18f78e=0xce;}_0x3b8903['status'](_0x18f78e);return _0x3b8903[_0xf530('0x1e')](_0xf530('0x1f'),_0x5e6f22+'-'+_0x323969+'/'+_0x5407d3)['json'](_0x17f74c);}return null;};}function patchUpdates(_0x61c2c1){return function(_0x3f5443){try{jsonpatch[_0xf530('0x20')](_0x3f5443,_0x61c2c1,!![]);}catch(_0x267db5){return BPromise[_0xf530('0x21')](_0x267db5);}return _0x3f5443[_0xf530('0x22')]();};}function saveUpdates(_0x877d8f,_0x23d4ab){return function(_0x2f1bb4){if(_0x2f1bb4){return _0x2f1bb4['update'](_0x877d8f)[_0xf530('0x23')](function(_0x3fb4b4){return _0x3fb4b4;});}return null;};}function removeEntity(_0x9bf990,_0x57d325){return function(_0x384a7f){if(_0x384a7f){return _0x384a7f[_0xf530('0x24')]()[_0xf530('0x23')](function(){_0x9bf990['status'](0xcc)[_0xf530('0x25')]();});}};}function handleEntityNotFound(_0x2e1bb6,_0x2facb4){return function(_0x548307){if(!_0x548307){_0x2e1bb6[_0xf530('0x18')](0x194);}return _0x548307;};}function handleError(_0xe0217c,_0x337c8a){_0x337c8a=_0x337c8a||0x1f4;return function(_0x549151){logger[_0xf530('0x26')](_0x549151[_0xf530('0x27')]);if(_0x549151['name']){delete _0x549151[_0xf530('0x28')];}_0xe0217c['status'](_0x337c8a)[_0xf530('0x29')](_0x549151);};}exports[_0xf530('0x2a')]=function(_0x1bd3ff,_0x5d6966){var _0x1333d4={},_0x110d7f={},_0x40ee05={'count':0x0,'rows':[]};var _0x2a2549=_[_0xf530('0x2b')](db['VtigerField']['rawAttributes'],function(_0x2d4dea){return{'name':_0x2d4dea['fieldName'],'type':_0x2d4dea['type'][_0xf530('0x2c')]};});_0x110d7f['model']=_[_0xf530('0x2b')](_0x2a2549,_0xf530('0x28'));_0x110d7f[_0xf530('0x2d')]=_[_0xf530('0x2e')](_0x1bd3ff[_0xf530('0x2d')]);_0x110d7f[_0xf530('0x2f')]=_[_0xf530('0x30')](_0x110d7f[_0xf530('0x31')],_0x110d7f['query']);_0x1333d4[_0xf530('0x32')]=_[_0xf530('0x30')](_0x110d7f[_0xf530('0x31')],qs[_0xf530('0x33')](_0x1bd3ff['query'][_0xf530('0x33')]));_0x1333d4['attributes']=_0x1333d4[_0xf530('0x32')]['length']?_0x1333d4['attributes']:_0x110d7f[_0xf530('0x31')];if(!_0x1bd3ff[_0xf530('0x2d')][_0xf530('0x34')](_0xf530('0x35'))){_0x1333d4[_0xf530('0x1d')]=qs[_0xf530('0x1d')](_0x1bd3ff[_0xf530('0x2d')]['limit']);_0x1333d4[_0xf530('0x1c')]=qs[_0xf530('0x1c')](_0x1bd3ff[_0xf530('0x2d')]['offset']);}_0x1333d4[_0xf530('0x36')]=qs[_0xf530('0x37')](_0x1bd3ff[_0xf530('0x2d')][_0xf530('0x37')]);_0x1333d4[_0xf530('0x38')]=qs[_0xf530('0x2f')](_[_0xf530('0x39')](_0x1bd3ff['query'],_0x110d7f[_0xf530('0x2f')]));if(_0x1bd3ff[_0xf530('0x2d')]['filter']){_0x1333d4[_0xf530('0x38')]=_[_0xf530('0x3a')](_0x1333d4[_0xf530('0x38')],{'$or':_[_0xf530('0x2b')](_0x2a2549,function(_0x582dcd){if(_0x582dcd[_0xf530('0x3b')]!==_0xf530('0x3c')){var _0x2f5a80={};_0x2f5a80[_0x582dcd[_0xf530('0x28')]]={'$like':'%'+_0x1bd3ff['query']['filter']+'%'};return _0x2f5a80;}})});}_0x1333d4=_['merge']({},_0x1333d4,_0x1bd3ff[_0xf530('0x3d')]);var _0x2f0ab7={'where':_0x1333d4[_0xf530('0x38')]};return db[_0xf530('0x3e')][_0xf530('0x1b')](_0x2f0ab7)['then'](function(_0x324fd1){_0x40ee05['count']=_0x324fd1;if(_0x1bd3ff[_0xf530('0x2d')][_0xf530('0x3f')]){_0x1333d4[_0xf530('0x40')]=[{'all':!![]}];}return db[_0xf530('0x3e')][_0xf530('0x41')](_0x1333d4);})[_0xf530('0x23')](function(_0x381b94){_0x40ee05[_0xf530('0x42')]=_0x381b94;return _0x40ee05;})[_0xf530('0x23')](respondWithFilteredResult(_0x5d6966,_0x1333d4))[_0xf530('0x43')](handleError(_0x5d6966,null));};exports[_0xf530('0x44')]=function(_0x5cad1c,_0x5a8629){var _0x5cc031={'raw':!![],'where':{'id':_0x5cad1c['params']['id']}},_0x189b21={};_0x189b21[_0xf530('0x31')]=_[_0xf530('0x2e')](db[_0xf530('0x3e')][_0xf530('0x45')]);_0x189b21[_0xf530('0x2d')]=_[_0xf530('0x2e')](_0x5cad1c[_0xf530('0x2d')]);_0x189b21[_0xf530('0x2f')]=_[_0xf530('0x30')](_0x189b21[_0xf530('0x31')],_0x189b21['query']);_0x5cc031[_0xf530('0x32')]=_[_0xf530('0x30')](_0x189b21['model'],qs[_0xf530('0x33')](_0x5cad1c['query'][_0xf530('0x33')]));_0x5cc031[_0xf530('0x32')]=_0x5cc031[_0xf530('0x32')][_0xf530('0x46')]?_0x5cc031[_0xf530('0x32')]:_0x189b21[_0xf530('0x31')];if(_0x5cad1c[_0xf530('0x2d')][_0xf530('0x3f')]){_0x5cc031[_0xf530('0x40')]=[{'all':!![]}];}_0x5cc031=_[_0xf530('0x3a')]({},_0x5cc031,_0x5cad1c[_0xf530('0x3d')]);return db[_0xf530('0x3e')][_0xf530('0x47')](_0x5cc031)['then'](handleEntityNotFound(_0x5a8629,null))[_0xf530('0x23')](respondWithResult(_0x5a8629,null))['catch'](handleError(_0x5a8629,null));};exports['create']=function(_0xb27f35,_0x467387){return db[_0xf530('0x3e')][_0xf530('0x48')](_0xb27f35['body'],{})['then'](respondWithResult(_0x467387,0xc9))[_0xf530('0x43')](handleError(_0x467387,null));};exports[_0xf530('0x49')]=function(_0x266acc,_0x5c4adf){if(_0x266acc[_0xf530('0x4a')]['id']){delete _0x266acc['body']['id'];}return db['VtigerField']['find']({'where':{'id':_0x266acc[_0xf530('0x4b')]['id']}})[_0xf530('0x23')](handleEntityNotFound(_0x5c4adf,null))[_0xf530('0x23')](saveUpdates(_0x266acc[_0xf530('0x4a')],null))['then'](respondWithResult(_0x5c4adf,null))['catch'](handleError(_0x5c4adf,null));};exports['destroy']=function(_0x462ba8,_0x25c8af){return db[_0xf530('0x3e')]['find']({'where':{'id':_0x462ba8[_0xf530('0x4b')]['id']}})[_0xf530('0x23')](handleEntityNotFound(_0x25c8af,null))[_0xf530('0x23')](removeEntity(_0x25c8af,null))[_0xf530('0x43')](handleError(_0x25c8af,null));};