9712ef711fd548935a0feb33bdaa099cc570e249
[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 _0xfc46=['moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','VtigerField','rawAttributes','fieldName','type','key','model','keys','intersection','query','attributes','fields','length','nolimit','limit','sort','where','filters','pick','filter','merge','VIRTUAL','count','includeAll','include','findAll','rows','show','params','options','find','create','body','catch','destroy','html-pdf','rimraf','zip-dir','fast-json-patch'];(function(_0x1a9bdf,_0x43130a){var _0x61a042=function(_0x13fdf5){while(--_0x13fdf5){_0x1a9bdf['push'](_0x1a9bdf['shift']());}};_0x61a042(++_0x43130a);}(_0xfc46,0x9a));var _0x6fc4=function(_0x25248b,_0x3c8491){_0x25248b=_0x25248b-0x0;var _0x509939=_0xfc46[_0x25248b];return _0x509939;};'use strict';var pdf=require(_0x6fc4('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x6fc4('0x1'));var zipdir=require(_0x6fc4('0x2'));var jsonpatch=require(_0x6fc4('0x3'));var rp=require('request-promise');var moment=require(_0x6fc4('0x4'));var BPromise=require(_0x6fc4('0x5'));var Mustache=require(_0x6fc4('0x6'));var util=require(_0x6fc4('0x7'));var path=require('path');var sox=require(_0x6fc4('0x8'));var csv=require(_0x6fc4('0x9'));var ejs=require(_0x6fc4('0xa'));var fs=require('fs');var _=require(_0x6fc4('0xb'));var squel=require(_0x6fc4('0xc'));var crypto=require(_0x6fc4('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x6fc4('0xe'));var toCsv=require('to-csv');var querystring=require(_0x6fc4('0xf'));var Papa=require(_0x6fc4('0x10'));var Redis=require('ioredis');var authService=require(_0x6fc4('0x11'));var qs=require(_0x6fc4('0x12'));var as=require(_0x6fc4('0x13'));var hardwareService=require(_0x6fc4('0x14'));var logger=require(_0x6fc4('0x15'))(_0x6fc4('0x16'));var utils=require(_0x6fc4('0x17'));var config=require(_0x6fc4('0x18'));var licenseUtil=require(_0x6fc4('0x19'));var db=require(_0x6fc4('0x1a'))['db'];function respondWithStatusCode(_0x2227c3,_0x13bf6b){_0x13bf6b=_0x13bf6b||0xcc;return function(_0x34cb6b){if(_0x34cb6b){return _0x2227c3[_0x6fc4('0x1b')](_0x13bf6b);}return _0x2227c3[_0x6fc4('0x1c')](_0x13bf6b)[_0x6fc4('0x1d')]();};}function respondWithResult(_0xcd9d73,_0x519c52){_0x519c52=_0x519c52||0xc8;return function(_0x56383b){if(_0x56383b){return _0xcd9d73[_0x6fc4('0x1c')](_0x519c52)[_0x6fc4('0x1e')](_0x56383b);}};}function respondWithFilteredResult(_0x3b42a5,_0x4352cf){return function(_0x21d493){if(_0x21d493){var _0x34368a=_0x21d493['count'],_0x3e2fc6=_0x4352cf[_0x6fc4('0x1f')],_0x30812b=_0x4352cf[_0x6fc4('0x1f')]+_0x4352cf['limit'],_0x1d51b1;if(_0x30812b>=_0x34368a){_0x30812b=_0x34368a;_0x1d51b1=0xc8;}else{_0x1d51b1=0xce;}_0x3b42a5['status'](_0x1d51b1);return _0x3b42a5[_0x6fc4('0x20')](_0x6fc4('0x21'),_0x3e2fc6+'-'+_0x30812b+'/'+_0x34368a)['json'](_0x21d493);}return null;};}function patchUpdates(_0xf34889){return function(_0xb4a47a){try{jsonpatch[_0x6fc4('0x22')](_0xb4a47a,_0xf34889,!![]);}catch(_0x4edb51){return BPromise[_0x6fc4('0x23')](_0x4edb51);}return _0xb4a47a[_0x6fc4('0x24')]();};}function saveUpdates(_0x3a3842,_0x518579){return function(_0x470184){if(_0x470184){return _0x470184[_0x6fc4('0x25')](_0x3a3842)['then'](function(_0x4a0eec){return _0x4a0eec;});}return null;};}function removeEntity(_0x2e676a,_0x4950c4){return function(_0x53e5fb){if(_0x53e5fb){return _0x53e5fb['destroy']()[_0x6fc4('0x26')](function(){_0x2e676a[_0x6fc4('0x1c')](0xcc)[_0x6fc4('0x1d')]();});}};}function handleEntityNotFound(_0x59d809,_0x1912a8){return function(_0x38f60c){if(!_0x38f60c){_0x59d809['sendStatus'](0x194);}return _0x38f60c;};}function handleError(_0x14aa5f,_0x1e93d2){_0x1e93d2=_0x1e93d2||0x1f4;return function(_0x2b9811){logger[_0x6fc4('0x27')](_0x2b9811[_0x6fc4('0x28')]);if(_0x2b9811[_0x6fc4('0x29')]){delete _0x2b9811[_0x6fc4('0x29')];}_0x14aa5f[_0x6fc4('0x1c')](_0x1e93d2)[_0x6fc4('0x2a')](_0x2b9811);};}exports[_0x6fc4('0x2b')]=function(_0x3be501,_0x2fcdf8){var _0x37d90f={},_0x5adec0={},_0x36f53b={'count':0x0,'rows':[]};var _0x24d5d8=_[_0x6fc4('0x2c')](db[_0x6fc4('0x2d')][_0x6fc4('0x2e')],function(_0x21e2d7){return{'name':_0x21e2d7[_0x6fc4('0x2f')],'type':_0x21e2d7[_0x6fc4('0x30')][_0x6fc4('0x31')]};});_0x5adec0[_0x6fc4('0x32')]=_[_0x6fc4('0x2c')](_0x24d5d8,_0x6fc4('0x29'));_0x5adec0['query']=_[_0x6fc4('0x33')](_0x3be501['query']);_0x5adec0['filters']=_[_0x6fc4('0x34')](_0x5adec0[_0x6fc4('0x32')],_0x5adec0[_0x6fc4('0x35')]);_0x37d90f[_0x6fc4('0x36')]=_[_0x6fc4('0x34')](_0x5adec0[_0x6fc4('0x32')],qs['fields'](_0x3be501[_0x6fc4('0x35')][_0x6fc4('0x37')]));_0x37d90f[_0x6fc4('0x36')]=_0x37d90f[_0x6fc4('0x36')][_0x6fc4('0x38')]?_0x37d90f[_0x6fc4('0x36')]:_0x5adec0[_0x6fc4('0x32')];if(!_0x3be501[_0x6fc4('0x35')]['hasOwnProperty'](_0x6fc4('0x39'))){_0x37d90f[_0x6fc4('0x3a')]=qs[_0x6fc4('0x3a')](_0x3be501[_0x6fc4('0x35')][_0x6fc4('0x3a')]);_0x37d90f[_0x6fc4('0x1f')]=qs[_0x6fc4('0x1f')](_0x3be501[_0x6fc4('0x35')][_0x6fc4('0x1f')]);}_0x37d90f['order']=qs['sort'](_0x3be501[_0x6fc4('0x35')][_0x6fc4('0x3b')]);_0x37d90f[_0x6fc4('0x3c')]=qs[_0x6fc4('0x3d')](_[_0x6fc4('0x3e')](_0x3be501[_0x6fc4('0x35')],_0x5adec0['filters']),_0x24d5d8);if(_0x3be501[_0x6fc4('0x35')][_0x6fc4('0x3f')]){_0x37d90f[_0x6fc4('0x3c')]=_[_0x6fc4('0x40')](_0x37d90f[_0x6fc4('0x3c')],{'$or':_[_0x6fc4('0x2c')](_0x24d5d8,function(_0x30b7fd){if(_0x30b7fd[_0x6fc4('0x30')]!==_0x6fc4('0x41')){var _0x27934c={};_0x27934c[_0x30b7fd[_0x6fc4('0x29')]]={'$like':'%'+_0x3be501[_0x6fc4('0x35')][_0x6fc4('0x3f')]+'%'};return _0x27934c;}})});}_0x37d90f=_[_0x6fc4('0x40')]({},_0x37d90f,_0x3be501['options']);var _0x1de1e6={'where':_0x37d90f[_0x6fc4('0x3c')]};return db[_0x6fc4('0x2d')]['count'](_0x1de1e6)[_0x6fc4('0x26')](function(_0x34cd20){_0x36f53b[_0x6fc4('0x42')]=_0x34cd20;if(_0x3be501[_0x6fc4('0x35')][_0x6fc4('0x43')]){_0x37d90f[_0x6fc4('0x44')]=[{'all':!![]}];}return db[_0x6fc4('0x2d')][_0x6fc4('0x45')](_0x37d90f);})[_0x6fc4('0x26')](function(_0x34f09e){_0x36f53b[_0x6fc4('0x46')]=_0x34f09e;return _0x36f53b;})[_0x6fc4('0x26')](respondWithFilteredResult(_0x2fcdf8,_0x37d90f))['catch'](handleError(_0x2fcdf8,null));};exports[_0x6fc4('0x47')]=function(_0x306e03,_0x41a5ac){var _0x5b2526={'raw':!![],'where':{'id':_0x306e03[_0x6fc4('0x48')]['id']}},_0xcf729c={};_0xcf729c[_0x6fc4('0x32')]=_['keys'](db['VtigerField'][_0x6fc4('0x2e')]);_0xcf729c[_0x6fc4('0x35')]=_[_0x6fc4('0x33')](_0x306e03['query']);_0xcf729c[_0x6fc4('0x3d')]=_[_0x6fc4('0x34')](_0xcf729c[_0x6fc4('0x32')],_0xcf729c[_0x6fc4('0x35')]);_0x5b2526[_0x6fc4('0x36')]=_[_0x6fc4('0x34')](_0xcf729c[_0x6fc4('0x32')],qs[_0x6fc4('0x37')](_0x306e03[_0x6fc4('0x35')]['fields']));_0x5b2526[_0x6fc4('0x36')]=_0x5b2526[_0x6fc4('0x36')]['length']?_0x5b2526[_0x6fc4('0x36')]:_0xcf729c[_0x6fc4('0x32')];if(_0x306e03[_0x6fc4('0x35')][_0x6fc4('0x43')]){_0x5b2526[_0x6fc4('0x44')]=[{'all':!![]}];}_0x5b2526=_['merge']({},_0x5b2526,_0x306e03[_0x6fc4('0x49')]);return db['VtigerField'][_0x6fc4('0x4a')](_0x5b2526)[_0x6fc4('0x26')](handleEntityNotFound(_0x41a5ac,null))['then'](respondWithResult(_0x41a5ac,null))['catch'](handleError(_0x41a5ac,null));};exports[_0x6fc4('0x4b')]=function(_0xb61016,_0xde41bf){return db['VtigerField'][_0x6fc4('0x4b')](_0xb61016[_0x6fc4('0x4c')],{})[_0x6fc4('0x26')](respondWithResult(_0xde41bf,0xc9))[_0x6fc4('0x4d')](handleError(_0xde41bf,null));};exports[_0x6fc4('0x25')]=function(_0xcd9bb5,_0x21a856){if(_0xcd9bb5[_0x6fc4('0x4c')]['id']){delete _0xcd9bb5[_0x6fc4('0x4c')]['id'];}return db[_0x6fc4('0x2d')]['find']({'where':{'id':_0xcd9bb5[_0x6fc4('0x48')]['id']}})[_0x6fc4('0x26')](handleEntityNotFound(_0x21a856,null))[_0x6fc4('0x26')](saveUpdates(_0xcd9bb5[_0x6fc4('0x4c')],null))['then'](respondWithResult(_0x21a856,null))[_0x6fc4('0x4d')](handleError(_0x21a856,null));};exports[_0x6fc4('0x4e')]=function(_0x488540,_0x31140d){return db[_0x6fc4('0x2d')][_0x6fc4('0x4a')]({'where':{'id':_0x488540['params']['id']}})['then'](handleEntityNotFound(_0x31140d,null))[_0x6fc4('0x26')](removeEntity(_0x31140d,null))[_0x6fc4('0x4d')](handleError(_0x31140d,null));};