3c9a520c4a1e47719631339321139074d4df11f3
[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 _0x005f=['options','find','body','html-pdf','eml-format','rimraf','fast-json-patch','moment','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','set','Content-Range','apply','reject','save','update','then','destroy','error','name','send','index','map','VtigerField','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','limit','order','sort','pick','filter','where','merge','VIRTUAL','count','include','catch','params'];(function(_0x5413a7,_0x440330){var _0x462093=function(_0x239314){while(--_0x239314){_0x5413a7['push'](_0x5413a7['shift']());}};_0x462093(++_0x440330);}(_0x005f,0x161));var _0xf005=function(_0x1b86a2,_0x442de2){_0x1b86a2=_0x1b86a2-0x0;var _0x53926e=_0x005f[_0x1b86a2];return _0x53926e;};'use strict';var pdf=require(_0xf005('0x0'));var emlformat=require(_0xf005('0x1'));var rimraf=require(_0xf005('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf005('0x3'));var rp=require('request-promise');var moment=require(_0xf005('0x4'));var BPromise=require(_0xf005('0x5'));var Mustache=require(_0xf005('0x6'));var util=require(_0xf005('0x7'));var path=require(_0xf005('0x8'));var sox=require(_0xf005('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xf005('0xa'));var squel=require(_0xf005('0xb'));var crypto=require(_0xf005('0xc'));var jsforce=require(_0xf005('0xd'));var deskjs=require(_0xf005('0xe'));var toCsv=require('to-csv');var querystring=require(_0xf005('0xf'));var Papa=require(_0xf005('0x10'));var Redis=require('ioredis');var authService=require(_0xf005('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xf005('0x12'))(_0xf005('0x13'));var utils=require(_0xf005('0x14'));var config=require(_0xf005('0x15'));var db=require(_0xf005('0x16'))['db'];function respondWithStatusCode(_0x5b8872,_0x41e7aa){_0x41e7aa=_0x41e7aa||0xcc;return function(_0x5b9ded){if(_0x5b9ded){return _0x5b8872[_0xf005('0x17')](_0x41e7aa);}return _0x5b8872[_0xf005('0x18')](_0x41e7aa)[_0xf005('0x19')]();};}function respondWithResult(_0x4de1b0,_0x51909d){_0x51909d=_0x51909d||0xc8;return function(_0x23422f){if(_0x23422f){return _0x4de1b0[_0xf005('0x18')](_0x51909d)[_0xf005('0x1a')](_0x23422f);}};}function respondWithFilteredResult(_0xf02e4d,_0x4141f1){return function(_0x3403df){if(_0x3403df){var _0x30200a=_0x3403df['count'],_0x15a3ad=_0x4141f1[_0xf005('0x1b')],_0x524b49=_0x4141f1[_0xf005('0x1b')]+_0x4141f1['limit'],_0x5e4a5a;if(_0x524b49>=_0x30200a){_0x524b49=_0x30200a;_0x5e4a5a=0xc8;}else{_0x5e4a5a=0xce;}_0xf02e4d[_0xf005('0x18')](_0x5e4a5a);return _0xf02e4d[_0xf005('0x1c')](_0xf005('0x1d'),_0x15a3ad+'-'+_0x524b49+'/'+_0x30200a)[_0xf005('0x1a')](_0x3403df);}return null;};}function patchUpdates(_0x5337cc){return function(_0x1dd2f4){try{jsonpatch[_0xf005('0x1e')](_0x1dd2f4,_0x5337cc,!![]);}catch(_0x4abcd2){return BPromise[_0xf005('0x1f')](_0x4abcd2);}return _0x1dd2f4[_0xf005('0x20')]();};}function saveUpdates(_0x501fca,_0x48293e){return function(_0x43ebba){if(_0x43ebba){return _0x43ebba[_0xf005('0x21')](_0x501fca)[_0xf005('0x22')](function(_0x169cb9){return _0x169cb9;});}return null;};}function removeEntity(_0x9dadbc,_0xdfc3f4){return function(_0x5edc69){if(_0x5edc69){return _0x5edc69[_0xf005('0x23')]()['then'](function(){_0x9dadbc[_0xf005('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x259c41,_0x5842a8){return function(_0x156560){if(!_0x156560){_0x259c41[_0xf005('0x17')](0x194);}return _0x156560;};}function handleError(_0x17844b,_0xe64ba2){_0xe64ba2=_0xe64ba2||0x1f4;return function(_0x1a3508){logger[_0xf005('0x24')](_0x1a3508['stack']);if(_0x1a3508[_0xf005('0x25')]){delete _0x1a3508[_0xf005('0x25')];}_0x17844b[_0xf005('0x18')](_0xe64ba2)[_0xf005('0x26')](_0x1a3508);};}exports[_0xf005('0x27')]=function(_0x50554a,_0x27fb2a){var _0x557b68={},_0x54f0f7={},_0x479e54={'count':0x0,'rows':[]};var _0x4ae155=_[_0xf005('0x28')](db[_0xf005('0x29')][_0xf005('0x2a')],function(_0xd888be){return{'name':_0xd888be[_0xf005('0x2b')],'type':_0xd888be[_0xf005('0x2c')][_0xf005('0x2d')]};});_0x54f0f7[_0xf005('0x2e')]=_[_0xf005('0x28')](_0x4ae155,'name');_0x54f0f7[_0xf005('0x2f')]=_[_0xf005('0x30')](_0x50554a['query']);_0x54f0f7[_0xf005('0x31')]=_[_0xf005('0x32')](_0x54f0f7['model'],_0x54f0f7['query']);_0x557b68[_0xf005('0x33')]=_[_0xf005('0x32')](_0x54f0f7['model'],qs[_0xf005('0x34')](_0x50554a[_0xf005('0x2f')][_0xf005('0x34')]));_0x557b68[_0xf005('0x33')]=_0x557b68[_0xf005('0x33')]['length']?_0x557b68[_0xf005('0x33')]:_0x54f0f7[_0xf005('0x2e')];if(!_0x50554a[_0xf005('0x2f')][_0xf005('0x35')](_0xf005('0x36'))){_0x557b68[_0xf005('0x37')]=qs['limit'](_0x50554a[_0xf005('0x2f')][_0xf005('0x37')]);_0x557b68[_0xf005('0x1b')]=qs['offset'](_0x50554a['query'][_0xf005('0x1b')]);}_0x557b68[_0xf005('0x38')]=qs[_0xf005('0x39')](_0x50554a[_0xf005('0x2f')][_0xf005('0x39')]);_0x557b68['where']=qs[_0xf005('0x31')](_[_0xf005('0x3a')](_0x50554a[_0xf005('0x2f')],_0x54f0f7[_0xf005('0x31')]),_0x4ae155);if(_0x50554a['query'][_0xf005('0x3b')]){_0x557b68[_0xf005('0x3c')]=_[_0xf005('0x3d')](_0x557b68[_0xf005('0x3c')],{'$or':_['map'](_0x4ae155,function(_0x91b2ad){if(_0x91b2ad[_0xf005('0x2c')]!==_0xf005('0x3e')){var _0x596537={};_0x596537[_0x91b2ad[_0xf005('0x25')]]={'$like':'%'+_0x50554a[_0xf005('0x2f')][_0xf005('0x3b')]+'%'};return _0x596537;}})});}_0x557b68=_[_0xf005('0x3d')]({},_0x557b68,_0x50554a['options']);var _0x433be4={'where':_0x557b68[_0xf005('0x3c')]};return db['VtigerField'][_0xf005('0x3f')](_0x433be4)[_0xf005('0x22')](function(_0xbec659){_0x479e54[_0xf005('0x3f')]=_0xbec659;if(_0x50554a[_0xf005('0x2f')]['includeAll']){_0x557b68[_0xf005('0x40')]=[{'all':!![]}];}return db[_0xf005('0x29')]['findAll'](_0x557b68);})['then'](function(_0x2171cf){_0x479e54['rows']=_0x2171cf;return _0x479e54;})[_0xf005('0x22')](respondWithFilteredResult(_0x27fb2a,_0x557b68))[_0xf005('0x41')](handleError(_0x27fb2a,null));};exports['show']=function(_0x3cdaab,_0x118ff5){var _0x1a6e04={'raw':!![],'where':{'id':_0x3cdaab[_0xf005('0x42')]['id']}},_0x24c0f9={};_0x24c0f9[_0xf005('0x2e')]=_[_0xf005('0x30')](db['VtigerField'][_0xf005('0x2a')]);_0x24c0f9[_0xf005('0x2f')]=_['keys'](_0x3cdaab[_0xf005('0x2f')]);_0x24c0f9[_0xf005('0x31')]=_['intersection'](_0x24c0f9[_0xf005('0x2e')],_0x24c0f9[_0xf005('0x2f')]);_0x1a6e04[_0xf005('0x33')]=_[_0xf005('0x32')](_0x24c0f9[_0xf005('0x2e')],qs[_0xf005('0x34')](_0x3cdaab[_0xf005('0x2f')]['fields']));_0x1a6e04['attributes']=_0x1a6e04[_0xf005('0x33')]['length']?_0x1a6e04['attributes']:_0x24c0f9[_0xf005('0x2e')];if(_0x3cdaab[_0xf005('0x2f')]['includeAll']){_0x1a6e04[_0xf005('0x40')]=[{'all':!![]}];}_0x1a6e04=_[_0xf005('0x3d')]({},_0x1a6e04,_0x3cdaab[_0xf005('0x43')]);return db[_0xf005('0x29')][_0xf005('0x44')](_0x1a6e04)[_0xf005('0x22')](handleEntityNotFound(_0x118ff5,null))['then'](respondWithResult(_0x118ff5,null))['catch'](handleError(_0x118ff5,null));};exports['create']=function(_0x17dc0c,_0x238cee){return db['VtigerField']['create'](_0x17dc0c['body'],{})[_0xf005('0x22')](respondWithResult(_0x238cee,0xc9))[_0xf005('0x41')](handleError(_0x238cee,null));};exports['update']=function(_0x3d1285,_0x3c9629){if(_0x3d1285[_0xf005('0x45')]['id']){delete _0x3d1285[_0xf005('0x45')]['id'];}return db[_0xf005('0x29')][_0xf005('0x44')]({'where':{'id':_0x3d1285[_0xf005('0x42')]['id']}})[_0xf005('0x22')](handleEntityNotFound(_0x3c9629,null))[_0xf005('0x22')](saveUpdates(_0x3d1285['body'],null))['then'](respondWithResult(_0x3c9629,null))[_0xf005('0x41')](handleError(_0x3c9629,null));};exports[_0xf005('0x23')]=function(_0x14b573,_0x16abd9){return db['VtigerField'][_0xf005('0x44')]({'where':{'id':_0x14b573[_0xf005('0x42')]['id']}})['then'](handleEntityNotFound(_0x16abd9,null))[_0xf005('0x22')](removeEntity(_0x16abd9,null))[_0xf005('0x41')](handleError(_0x16abd9,null));};