Built motion from commit dbf3a7e2.|2.6.30
[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 _0x0bc6=['merge','VIRTUAL','filter','options','includeAll','findAll','rows','show','params','length','include','find','catch','create','body','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','map','VtigerField','fieldName','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick'];(function(_0x21aec3,_0x5c97e9){var _0x288bbc=function(_0x2283fe){while(--_0x2283fe){_0x21aec3['push'](_0x21aec3['shift']());}};_0x288bbc(++_0x5c97e9);}(_0x0bc6,0x13f));var _0x60bc=function(_0x335da3,_0x8bac2a){_0x335da3=_0x335da3-0x0;var _0x359a6d=_0x0bc6[_0x335da3];return _0x359a6d;};'use strict';var emlformat=require(_0x60bc('0x0'));var rimraf=require(_0x60bc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x60bc('0x2'));var rp=require(_0x60bc('0x3'));var moment=require(_0x60bc('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x60bc('0x5'));var util=require(_0x60bc('0x6'));var path=require(_0x60bc('0x7'));var sox=require('sox');var csv=require(_0x60bc('0x8'));var ejs=require(_0x60bc('0x9'));var fs=require('fs');var fs_extra=require(_0x60bc('0xa'));var _=require(_0x60bc('0xb'));var squel=require(_0x60bc('0xc'));var crypto=require('crypto');var jsforce=require(_0x60bc('0xd'));var deskjs=require(_0x60bc('0xe'));var toCsv=require(_0x60bc('0x8'));var querystring=require(_0x60bc('0xf'));var Papa=require('papaparse');var Redis=require(_0x60bc('0x10'));var authService=require(_0x60bc('0x11'));var qs=require(_0x60bc('0x12'));var as=require(_0x60bc('0x13'));var hardwareService=require(_0x60bc('0x14'));var logger=require(_0x60bc('0x15'))('api');var utils=require(_0x60bc('0x16'));var config=require(_0x60bc('0x17'));var licenseUtil=require(_0x60bc('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xa81d30,_0x57125b){_0x57125b=_0x57125b||0xcc;return function(_0x4e0caf){if(_0x4e0caf){return _0xa81d30['sendStatus'](_0x57125b);}return _0xa81d30[_0x60bc('0x19')](_0x57125b)[_0x60bc('0x1a')]();};}function respondWithResult(_0x5095b3,_0x1a9907){_0x1a9907=_0x1a9907||0xc8;return function(_0xab655d){if(_0xab655d){return _0x5095b3[_0x60bc('0x19')](_0x1a9907)[_0x60bc('0x1b')](_0xab655d);}};}function respondWithFilteredResult(_0x39176a,_0x5c7a01){return function(_0xb9290a){if(_0xb9290a){var _0x2d4731=typeof _0x5c7a01[_0x60bc('0x1c')]===_0x60bc('0x1d')&&typeof _0x5c7a01[_0x60bc('0x1e')]===_0x60bc('0x1d');var _0xa13ced=_0xb9290a[_0x60bc('0x1f')];var _0x4df028=_0x2d4731?0x0:_0x5c7a01[_0x60bc('0x1c')];var _0x5cdb03=_0x2d4731?_0xb9290a[_0x60bc('0x1f')]:_0x5c7a01[_0x60bc('0x1c')]+_0x5c7a01[_0x60bc('0x1e')];var _0x59896d;if(_0x5cdb03>=_0xa13ced){_0x5cdb03=_0xa13ced;_0x59896d=0xc8;}else{_0x59896d=0xce;}_0x39176a[_0x60bc('0x19')](_0x59896d);return _0x39176a[_0x60bc('0x20')](_0x60bc('0x21'),_0x4df028+'-'+_0x5cdb03+'/'+_0xa13ced)['json'](_0xb9290a);}return null;};}function patchUpdates(_0x359dac){return function(_0x187f7f){try{jsonpatch['apply'](_0x187f7f,_0x359dac,!![]);}catch(_0x4cc7ac){return BPromise[_0x60bc('0x22')](_0x4cc7ac);}return _0x187f7f[_0x60bc('0x23')]();};}function saveUpdates(_0x2bec79,_0x23e59d){return function(_0x28107d){if(_0x28107d){return _0x28107d[_0x60bc('0x24')](_0x2bec79)[_0x60bc('0x25')](function(_0x3bb57c){return _0x3bb57c;});}return null;};}function removeEntity(_0x4ad5b2,_0x511040){return function(_0x3c51d6){if(_0x3c51d6){return _0x3c51d6[_0x60bc('0x26')]()[_0x60bc('0x25')](function(){_0x4ad5b2[_0x60bc('0x19')](0xcc)[_0x60bc('0x1a')]();});}};}function handleEntityNotFound(_0x46036e,_0x34b43e){return function(_0x47383a){if(!_0x47383a){_0x46036e[_0x60bc('0x27')](0x194);}return _0x47383a;};}function handleError(_0x156d51,_0x365f89){_0x365f89=_0x365f89||0x1f4;return function(_0x365a4d){logger[_0x60bc('0x28')](_0x365a4d[_0x60bc('0x29')]);if(_0x365a4d[_0x60bc('0x2a')]){delete _0x365a4d[_0x60bc('0x2a')];}_0x156d51[_0x60bc('0x19')](_0x365f89)[_0x60bc('0x2b')](_0x365a4d);};}exports[_0x60bc('0x2c')]=function(_0x1abb85,_0xe00c4e){var _0x2f11ca={},_0x2be2da={},_0x842a6b={'count':0x0,'rows':[]};var _0x48df9e=_[_0x60bc('0x2d')](db[_0x60bc('0x2e')]['rawAttributes'],function(_0x3078de){return{'name':_0x3078de[_0x60bc('0x2f')],'type':_0x3078de['type'][_0x60bc('0x30')]};});_0x2be2da[_0x60bc('0x31')]=_[_0x60bc('0x2d')](_0x48df9e,_0x60bc('0x2a'));_0x2be2da[_0x60bc('0x32')]=_[_0x60bc('0x33')](_0x1abb85[_0x60bc('0x32')]);_0x2be2da[_0x60bc('0x34')]=_[_0x60bc('0x35')](_0x2be2da['model'],_0x2be2da['query']);_0x2f11ca[_0x60bc('0x36')]=_[_0x60bc('0x35')](_0x2be2da[_0x60bc('0x31')],qs['fields'](_0x1abb85[_0x60bc('0x32')][_0x60bc('0x37')]));_0x2f11ca[_0x60bc('0x36')]=_0x2f11ca['attributes']['length']?_0x2f11ca[_0x60bc('0x36')]:_0x2be2da[_0x60bc('0x31')];if(!_0x1abb85[_0x60bc('0x32')][_0x60bc('0x38')]('nolimit')){_0x2f11ca[_0x60bc('0x1e')]=qs[_0x60bc('0x1e')](_0x1abb85[_0x60bc('0x32')][_0x60bc('0x1e')]);_0x2f11ca[_0x60bc('0x1c')]=qs[_0x60bc('0x1c')](_0x1abb85[_0x60bc('0x32')][_0x60bc('0x1c')]);}_0x2f11ca[_0x60bc('0x39')]=qs[_0x60bc('0x3a')](_0x1abb85[_0x60bc('0x32')]['sort']);_0x2f11ca[_0x60bc('0x3b')]=qs[_0x60bc('0x34')](_[_0x60bc('0x3c')](_0x1abb85[_0x60bc('0x32')],_0x2be2da[_0x60bc('0x34')]),_0x48df9e);if(_0x1abb85[_0x60bc('0x32')]['filter']){_0x2f11ca[_0x60bc('0x3b')]=_[_0x60bc('0x3d')](_0x2f11ca['where'],{'$or':_['map'](_0x48df9e,function(_0x46ef9d){if(_0x46ef9d['type']!==_0x60bc('0x3e')){var _0x296695={};_0x296695[_0x46ef9d[_0x60bc('0x2a')]]={'$like':'%'+_0x1abb85[_0x60bc('0x32')][_0x60bc('0x3f')]+'%'};return _0x296695;}})});}_0x2f11ca=_[_0x60bc('0x3d')]({},_0x2f11ca,_0x1abb85[_0x60bc('0x40')]);var _0x47b02a={'where':_0x2f11ca[_0x60bc('0x3b')]};return db[_0x60bc('0x2e')][_0x60bc('0x1f')](_0x47b02a)[_0x60bc('0x25')](function(_0x281b74){_0x842a6b[_0x60bc('0x1f')]=_0x281b74;if(_0x1abb85[_0x60bc('0x32')][_0x60bc('0x41')]){_0x2f11ca['include']=[{'all':!![]}];}return db['VtigerField'][_0x60bc('0x42')](_0x2f11ca);})[_0x60bc('0x25')](function(_0xde63c5){_0x842a6b[_0x60bc('0x43')]=_0xde63c5;return _0x842a6b;})[_0x60bc('0x25')](respondWithFilteredResult(_0xe00c4e,_0x2f11ca))['catch'](handleError(_0xe00c4e,null));};exports[_0x60bc('0x44')]=function(_0x17533f,_0x4a4c72){var _0x5c6c8e={'raw':!![],'where':{'id':_0x17533f[_0x60bc('0x45')]['id']}},_0x113cdb={};_0x113cdb[_0x60bc('0x31')]=_[_0x60bc('0x33')](db[_0x60bc('0x2e')]['rawAttributes']);_0x113cdb[_0x60bc('0x32')]=_[_0x60bc('0x33')](_0x17533f[_0x60bc('0x32')]);_0x113cdb['filters']=_[_0x60bc('0x35')](_0x113cdb['model'],_0x113cdb[_0x60bc('0x32')]);_0x5c6c8e[_0x60bc('0x36')]=_[_0x60bc('0x35')](_0x113cdb[_0x60bc('0x31')],qs[_0x60bc('0x37')](_0x17533f['query'][_0x60bc('0x37')]));_0x5c6c8e[_0x60bc('0x36')]=_0x5c6c8e['attributes'][_0x60bc('0x46')]?_0x5c6c8e[_0x60bc('0x36')]:_0x113cdb[_0x60bc('0x31')];if(_0x17533f['query'][_0x60bc('0x41')]){_0x5c6c8e[_0x60bc('0x47')]=[{'all':!![]}];}_0x5c6c8e=_[_0x60bc('0x3d')]({},_0x5c6c8e,_0x17533f[_0x60bc('0x40')]);return db[_0x60bc('0x2e')][_0x60bc('0x48')](_0x5c6c8e)[_0x60bc('0x25')](handleEntityNotFound(_0x4a4c72,null))[_0x60bc('0x25')](respondWithResult(_0x4a4c72,null))[_0x60bc('0x49')](handleError(_0x4a4c72,null));};exports[_0x60bc('0x4a')]=function(_0x38c611,_0x5433a2){return db['VtigerField']['create'](_0x38c611[_0x60bc('0x4b')],{})[_0x60bc('0x25')](respondWithResult(_0x5433a2,0xc9))[_0x60bc('0x49')](handleError(_0x5433a2,null));};exports[_0x60bc('0x24')]=function(_0x1192eb,_0x5b4b6c){if(_0x1192eb['body']['id']){delete _0x1192eb[_0x60bc('0x4b')]['id'];}return db[_0x60bc('0x2e')][_0x60bc('0x48')]({'where':{'id':_0x1192eb['params']['id']}})[_0x60bc('0x25')](handleEntityNotFound(_0x5b4b6c,null))['then'](saveUpdates(_0x1192eb[_0x60bc('0x4b')],null))[_0x60bc('0x25')](respondWithResult(_0x5b4b6c,null))[_0x60bc('0x49')](handleError(_0x5b4b6c,null));};exports[_0x60bc('0x26')]=function(_0xc75935,_0x519fbd){return db['VtigerField'][_0x60bc('0x48')]({'where':{'id':_0xc75935[_0x60bc('0x45')]['id']}})[_0x60bc('0x25')](handleEntityNotFound(_0x519fbd,null))['then'](removeEntity(_0x519fbd,null))[_0x60bc('0x49')](handleError(_0x519fbd,null));};