32f83c0c5a121740e4881b9f9a3ed190738a04bb
[motion2.git] / server / api / intSalesforceField / intSalesforceField.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 _0x06f6=['rawAttributes','type','key','model','keys','query','attributes','fields','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','intersection','length','find','update','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','fs-extra','squel','crypto','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','status','end','json','offset','undefined','limit','count','Content-Range','apply','save','then','destroy','sendStatus','stack','name','send','index','map','SalesforceField'];(function(_0x3eb475,_0x43e757){var _0x58e47b=function(_0x192000){while(--_0x192000){_0x3eb475['push'](_0x3eb475['shift']());}};_0x58e47b(++_0x43e757);}(_0x06f6,0x18a));var _0x606f=function(_0x2aaf12,_0x572e7a){_0x2aaf12=_0x2aaf12-0x0;var _0x289e2e=_0x06f6[_0x2aaf12];return _0x289e2e;};'use strict';var emlformat=require(_0x606f('0x0'));var rimraf=require(_0x606f('0x1'));var zipdir=require(_0x606f('0x2'));var jsonpatch=require(_0x606f('0x3'));var rp=require(_0x606f('0x4'));var moment=require(_0x606f('0x5'));var BPromise=require(_0x606f('0x6'));var Mustache=require('mustache');var util=require(_0x606f('0x7'));var path=require(_0x606f('0x8'));var sox=require(_0x606f('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x606f('0xa'));var _=require('lodash');var squel=require(_0x606f('0xb'));var crypto=require(_0x606f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x606f('0xd'));var toCsv=require(_0x606f('0xe'));var querystring=require(_0x606f('0xf'));var Papa=require(_0x606f('0x10'));var Redis=require('ioredis');var authService=require(_0x606f('0x11'));var qs=require(_0x606f('0x12'));var as=require(_0x606f('0x13'));var hardwareService=require(_0x606f('0x14'));var logger=require(_0x606f('0x15'))(_0x606f('0x16'));var utils=require(_0x606f('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x606f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5703b0,_0x9d3867){_0x9d3867=_0x9d3867||0xcc;return function(_0x5bd623){if(_0x5bd623){return _0x5703b0['sendStatus'](_0x9d3867);}return _0x5703b0[_0x606f('0x19')](_0x9d3867)[_0x606f('0x1a')]();};}function respondWithResult(_0x4a4117,_0x440fc0){_0x440fc0=_0x440fc0||0xc8;return function(_0x29014a){if(_0x29014a){return _0x4a4117[_0x606f('0x19')](_0x440fc0)[_0x606f('0x1b')](_0x29014a);}};}function respondWithFilteredResult(_0x47b7ea,_0x5e04f2){return function(_0x47e120){if(_0x47e120){var _0x3a8ade=typeof _0x5e04f2[_0x606f('0x1c')]===_0x606f('0x1d')&&typeof _0x5e04f2[_0x606f('0x1e')]===_0x606f('0x1d');var _0x57d4a1=_0x47e120[_0x606f('0x1f')];var _0x625658=_0x3a8ade?0x0:_0x5e04f2[_0x606f('0x1c')];var _0x230e0a=_0x3a8ade?_0x47e120[_0x606f('0x1f')]:_0x5e04f2[_0x606f('0x1c')]+_0x5e04f2[_0x606f('0x1e')];var _0x3d906a;if(_0x230e0a>=_0x57d4a1){_0x230e0a=_0x57d4a1;_0x3d906a=0xc8;}else{_0x3d906a=0xce;}_0x47b7ea[_0x606f('0x19')](_0x3d906a);return _0x47b7ea['set'](_0x606f('0x20'),_0x625658+'-'+_0x230e0a+'/'+_0x57d4a1)[_0x606f('0x1b')](_0x47e120);}return null;};}function patchUpdates(_0x159cf3){return function(_0x411fb8){try{jsonpatch[_0x606f('0x21')](_0x411fb8,_0x159cf3,!![]);}catch(_0x306bb7){return BPromise['reject'](_0x306bb7);}return _0x411fb8[_0x606f('0x22')]();};}function saveUpdates(_0x55a9d6,_0x5ce760){return function(_0x1aa469){if(_0x1aa469){return _0x1aa469['update'](_0x55a9d6)[_0x606f('0x23')](function(_0x58d566){return _0x58d566;});}return null;};}function removeEntity(_0x5c06f2,_0x34376a){return function(_0x580600){if(_0x580600){return _0x580600[_0x606f('0x24')]()[_0x606f('0x23')](function(){_0x5c06f2[_0x606f('0x19')](0xcc)[_0x606f('0x1a')]();});}};}function handleEntityNotFound(_0x3720e9,_0x3d5c1b){return function(_0x33c135){if(!_0x33c135){_0x3720e9[_0x606f('0x25')](0x194);}return _0x33c135;};}function handleError(_0x2e79c4,_0x4c7596){_0x4c7596=_0x4c7596||0x1f4;return function(_0x498152){logger['error'](_0x498152[_0x606f('0x26')]);if(_0x498152[_0x606f('0x27')]){delete _0x498152[_0x606f('0x27')];}_0x2e79c4[_0x606f('0x19')](_0x4c7596)[_0x606f('0x28')](_0x498152);};}exports[_0x606f('0x29')]=function(_0x556440,_0x1e33ee){var _0x502002={},_0x222f04={},_0x5e8e54={'count':0x0,'rows':[]};var _0x59dee8=_[_0x606f('0x2a')](db[_0x606f('0x2b')][_0x606f('0x2c')],function(_0x495c42){return{'name':_0x495c42['fieldName'],'type':_0x495c42[_0x606f('0x2d')][_0x606f('0x2e')]};});_0x222f04[_0x606f('0x2f')]=_[_0x606f('0x2a')](_0x59dee8,_0x606f('0x27'));_0x222f04['query']=_[_0x606f('0x30')](_0x556440[_0x606f('0x31')]);_0x222f04['filters']=_['intersection'](_0x222f04[_0x606f('0x2f')],_0x222f04['query']);_0x502002[_0x606f('0x32')]=_['intersection'](_0x222f04[_0x606f('0x2f')],qs['fields'](_0x556440['query'][_0x606f('0x33')]));_0x502002[_0x606f('0x32')]=_0x502002[_0x606f('0x32')]['length']?_0x502002['attributes']:_0x222f04[_0x606f('0x2f')];if(!_0x556440[_0x606f('0x31')]['hasOwnProperty'](_0x606f('0x34'))){_0x502002['limit']=qs['limit'](_0x556440[_0x606f('0x31')][_0x606f('0x1e')]);_0x502002[_0x606f('0x1c')]=qs[_0x606f('0x1c')](_0x556440['query']['offset']);}_0x502002[_0x606f('0x35')]=qs[_0x606f('0x36')](_0x556440[_0x606f('0x31')][_0x606f('0x36')]);_0x502002[_0x606f('0x37')]=qs[_0x606f('0x38')](_[_0x606f('0x39')](_0x556440[_0x606f('0x31')],_0x222f04[_0x606f('0x38')]),_0x59dee8);if(_0x556440[_0x606f('0x31')][_0x606f('0x3a')]){_0x502002['where']=_[_0x606f('0x3b')](_0x502002['where'],{'$or':_['map'](_0x59dee8,function(_0xa8b740){if(_0xa8b740[_0x606f('0x2d')]!==_0x606f('0x3c')){var _0x2c0b1b={};_0x2c0b1b[_0xa8b740[_0x606f('0x27')]]={'$like':'%'+_0x556440[_0x606f('0x31')][_0x606f('0x3a')]+'%'};return _0x2c0b1b;}})});}_0x502002=_[_0x606f('0x3b')]({},_0x502002,_0x556440[_0x606f('0x3d')]);var _0x596232={'where':_0x502002[_0x606f('0x37')]};return db[_0x606f('0x2b')]['count'](_0x596232)[_0x606f('0x23')](function(_0x1a508a){_0x5e8e54[_0x606f('0x1f')]=_0x1a508a;if(_0x556440[_0x606f('0x31')][_0x606f('0x3e')]){_0x502002[_0x606f('0x3f')]=[{'all':!![]}];}return db[_0x606f('0x2b')][_0x606f('0x40')](_0x502002);})[_0x606f('0x23')](function(_0x57c03d){_0x5e8e54['rows']=_0x57c03d;return _0x5e8e54;})[_0x606f('0x23')](respondWithFilteredResult(_0x1e33ee,_0x502002))[_0x606f('0x41')](handleError(_0x1e33ee,null));};exports[_0x606f('0x42')]=function(_0x3a4390,_0x381d64){var _0x277b36={'raw':!![],'where':{'id':_0x3a4390[_0x606f('0x43')]['id']}},_0x556245={};_0x556245[_0x606f('0x2f')]=_[_0x606f('0x30')](db[_0x606f('0x2b')][_0x606f('0x2c')]);_0x556245['query']=_['keys'](_0x3a4390['query']);_0x556245[_0x606f('0x38')]=_['intersection'](_0x556245[_0x606f('0x2f')],_0x556245['query']);_0x277b36[_0x606f('0x32')]=_[_0x606f('0x44')](_0x556245[_0x606f('0x2f')],qs['fields'](_0x3a4390['query'][_0x606f('0x33')]));_0x277b36['attributes']=_0x277b36['attributes'][_0x606f('0x45')]?_0x277b36[_0x606f('0x32')]:_0x556245['model'];if(_0x3a4390[_0x606f('0x31')]['includeAll']){_0x277b36[_0x606f('0x3f')]=[{'all':!![]}];}_0x277b36=_[_0x606f('0x3b')]({},_0x277b36,_0x3a4390[_0x606f('0x3d')]);return db['SalesforceField'][_0x606f('0x46')](_0x277b36)[_0x606f('0x23')](handleEntityNotFound(_0x381d64,null))[_0x606f('0x23')](respondWithResult(_0x381d64,null))['catch'](handleError(_0x381d64,null));};exports['create']=function(_0x2292f8,_0x26bc1f){return db['SalesforceField']['create'](_0x2292f8['body'],{})[_0x606f('0x23')](respondWithResult(_0x26bc1f,0xc9))[_0x606f('0x41')](handleError(_0x26bc1f,null));};exports[_0x606f('0x47')]=function(_0x454e95,_0x5140ac){if(_0x454e95[_0x606f('0x48')]['id']){delete _0x454e95[_0x606f('0x48')]['id'];}return db['SalesforceField']['find']({'where':{'id':_0x454e95[_0x606f('0x43')]['id']}})[_0x606f('0x23')](handleEntityNotFound(_0x5140ac,null))['then'](saveUpdates(_0x454e95[_0x606f('0x48')],null))['then'](respondWithResult(_0x5140ac,null))['catch'](handleError(_0x5140ac,null));};exports[_0x606f('0x24')]=function(_0x4f25d1,_0x556163){return db[_0x606f('0x2b')][_0x606f('0x46')]({'where':{'id':_0x4f25d1['params']['id']}})['then'](handleEntityNotFound(_0x556163,null))[_0x606f('0x23')](removeEntity(_0x556163,null))[_0x606f('0x41')](handleError(_0x556163,null));};