Built motion from commit (unavailable).|2.5.17
[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 _0x952f=['attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','merge','map','VIRTUAL','options','include','findAll','rows','params','includeAll','find','catch','create','update','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','squel','jsforce','papaparse','ioredis','../../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','count','offset','set','apply','save','then','destroy','stack','name','send','index','SalesforceField','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields'];(function(_0x442d9e,_0xb23597){var _0x3573be=function(_0x7f4e3d){while(--_0x7f4e3d){_0x442d9e['push'](_0x442d9e['shift']());}};_0x3573be(++_0xb23597);}(_0x952f,0xf5));var _0xf952=function(_0x26bafe,_0x13e506){_0x26bafe=_0x26bafe-0x0;var _0x307879=_0x952f[_0x26bafe];return _0x307879;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf952('0x0'));var rimraf=require(_0xf952('0x1'));var zipdir=require(_0xf952('0x2'));var jsonpatch=require(_0xf952('0x3'));var rp=require(_0xf952('0x4'));var moment=require(_0xf952('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xf952('0x6'));var util=require(_0xf952('0x7'));var path=require(_0xf952('0x8'));var sox=require(_0xf952('0x9'));var csv=require(_0xf952('0xa'));var ejs=require(_0xf952('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0xf952('0xc'));var crypto=require('crypto');var jsforce=require(_0xf952('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xf952('0xa'));var querystring=require('querystring');var Papa=require(_0xf952('0xe'));var Redis=require(_0xf952('0xf'));var authService=require(_0xf952('0x10'));var qs=require(_0xf952('0x11'));var as=require(_0xf952('0x12'));var hardwareService=require(_0xf952('0x13'));var logger=require(_0xf952('0x14'))(_0xf952('0x15'));var utils=require(_0xf952('0x16'));var config=require(_0xf952('0x17'));var licenseUtil=require(_0xf952('0x18'));var db=require(_0xf952('0x19'))['db'];function respondWithStatusCode(_0x2b9d1f,_0xf23c6){_0xf23c6=_0xf23c6||0xcc;return function(_0x4b616d){if(_0x4b616d){return _0x2b9d1f[_0xf952('0x1a')](_0xf23c6);}return _0x2b9d1f[_0xf952('0x1b')](_0xf23c6)[_0xf952('0x1c')]();};}function respondWithResult(_0x17acb9,_0x66d214){_0x66d214=_0x66d214||0xc8;return function(_0x30e75b){if(_0x30e75b){return _0x17acb9['status'](_0x66d214)[_0xf952('0x1d')](_0x30e75b);}};}function respondWithFilteredResult(_0x1e1dcc,_0xd0b745){return function(_0x2c8ab9){if(_0x2c8ab9){var _0x2b946a=_0x2c8ab9[_0xf952('0x1e')],_0x4796fa=_0xd0b745[_0xf952('0x1f')],_0x229016=_0xd0b745[_0xf952('0x1f')]+_0xd0b745['limit'],_0x5a204a;if(_0x229016>=_0x2b946a){_0x229016=_0x2b946a;_0x5a204a=0xc8;}else{_0x5a204a=0xce;}_0x1e1dcc['status'](_0x5a204a);return _0x1e1dcc[_0xf952('0x20')]('Content-Range',_0x4796fa+'-'+_0x229016+'/'+_0x2b946a)['json'](_0x2c8ab9);}return null;};}function patchUpdates(_0x2a7708){return function(_0x51f2cf){try{jsonpatch[_0xf952('0x21')](_0x51f2cf,_0x2a7708,!![]);}catch(_0x48fb5d){return BPromise['reject'](_0x48fb5d);}return _0x51f2cf[_0xf952('0x22')]();};}function saveUpdates(_0x49f002,_0x75dc49){return function(_0xd67551){if(_0xd67551){return _0xd67551['update'](_0x49f002)[_0xf952('0x23')](function(_0x2f0e00){return _0x2f0e00;});}return null;};}function removeEntity(_0x1a3429,_0x2e2363){return function(_0x4a92da){if(_0x4a92da){return _0x4a92da[_0xf952('0x24')]()[_0xf952('0x23')](function(){_0x1a3429[_0xf952('0x1b')](0xcc)[_0xf952('0x1c')]();});}};}function handleEntityNotFound(_0x379d54,_0x4ad8ec){return function(_0x5ed217){if(!_0x5ed217){_0x379d54['sendStatus'](0x194);}return _0x5ed217;};}function handleError(_0x1b1555,_0x346090){_0x346090=_0x346090||0x1f4;return function(_0x4774b1){logger['error'](_0x4774b1[_0xf952('0x25')]);if(_0x4774b1[_0xf952('0x26')]){delete _0x4774b1[_0xf952('0x26')];}_0x1b1555['status'](_0x346090)[_0xf952('0x27')](_0x4774b1);};}exports[_0xf952('0x28')]=function(_0x331461,_0x26c1da){var _0x434e30={},_0x4e867d={},_0x31b260={'count':0x0,'rows':[]};var _0x5afa25=_['map'](db[_0xf952('0x29')][_0xf952('0x2a')],function(_0x401d21){return{'name':_0x401d21[_0xf952('0x2b')],'type':_0x401d21[_0xf952('0x2c')]['key']};});_0x4e867d[_0xf952('0x2d')]=_['map'](_0x5afa25,_0xf952('0x26'));_0x4e867d[_0xf952('0x2e')]=_[_0xf952('0x2f')](_0x331461['query']);_0x4e867d[_0xf952('0x30')]=_[_0xf952('0x31')](_0x4e867d[_0xf952('0x2d')],_0x4e867d['query']);_0x434e30['attributes']=_['intersection'](_0x4e867d[_0xf952('0x2d')],qs[_0xf952('0x32')](_0x331461[_0xf952('0x2e')][_0xf952('0x32')]));_0x434e30[_0xf952('0x33')]=_0x434e30[_0xf952('0x33')][_0xf952('0x34')]?_0x434e30[_0xf952('0x33')]:_0x4e867d['model'];if(!_0x331461['query'][_0xf952('0x35')](_0xf952('0x36'))){_0x434e30['limit']=qs[_0xf952('0x37')](_0x331461[_0xf952('0x2e')][_0xf952('0x37')]);_0x434e30['offset']=qs[_0xf952('0x1f')](_0x331461['query'][_0xf952('0x1f')]);}_0x434e30[_0xf952('0x38')]=qs['sort'](_0x331461[_0xf952('0x2e')][_0xf952('0x39')]);_0x434e30[_0xf952('0x3a')]=qs['filters'](_[_0xf952('0x3b')](_0x331461[_0xf952('0x2e')],_0x4e867d[_0xf952('0x30')]),_0x5afa25);if(_0x331461[_0xf952('0x2e')]['filter']){_0x434e30[_0xf952('0x3a')]=_[_0xf952('0x3c')](_0x434e30['where'],{'$or':_[_0xf952('0x3d')](_0x5afa25,function(_0x300636){if(_0x300636[_0xf952('0x2c')]!==_0xf952('0x3e')){var _0xbf5c32={};_0xbf5c32[_0x300636[_0xf952('0x26')]]={'$like':'%'+_0x331461['query']['filter']+'%'};return _0xbf5c32;}})});}_0x434e30=_[_0xf952('0x3c')]({},_0x434e30,_0x331461[_0xf952('0x3f')]);var _0x2a4bc4={'where':_0x434e30[_0xf952('0x3a')]};return db['SalesforceField'][_0xf952('0x1e')](_0x2a4bc4)[_0xf952('0x23')](function(_0xac8c79){_0x31b260[_0xf952('0x1e')]=_0xac8c79;if(_0x331461[_0xf952('0x2e')]['includeAll']){_0x434e30[_0xf952('0x40')]=[{'all':!![]}];}return db[_0xf952('0x29')][_0xf952('0x41')](_0x434e30);})[_0xf952('0x23')](function(_0x290d36){_0x31b260[_0xf952('0x42')]=_0x290d36;return _0x31b260;})[_0xf952('0x23')](respondWithFilteredResult(_0x26c1da,_0x434e30))['catch'](handleError(_0x26c1da,null));};exports['show']=function(_0x17dc53,_0x2a887d){var _0x22004b={'raw':!![],'where':{'id':_0x17dc53[_0xf952('0x43')]['id']}},_0x2f50d0={};_0x2f50d0[_0xf952('0x2d')]=_[_0xf952('0x2f')](db[_0xf952('0x29')][_0xf952('0x2a')]);_0x2f50d0[_0xf952('0x2e')]=_[_0xf952('0x2f')](_0x17dc53[_0xf952('0x2e')]);_0x2f50d0[_0xf952('0x30')]=_[_0xf952('0x31')](_0x2f50d0[_0xf952('0x2d')],_0x2f50d0[_0xf952('0x2e')]);_0x22004b[_0xf952('0x33')]=_['intersection'](_0x2f50d0[_0xf952('0x2d')],qs[_0xf952('0x32')](_0x17dc53[_0xf952('0x2e')][_0xf952('0x32')]));_0x22004b[_0xf952('0x33')]=_0x22004b['attributes'][_0xf952('0x34')]?_0x22004b[_0xf952('0x33')]:_0x2f50d0[_0xf952('0x2d')];if(_0x17dc53[_0xf952('0x2e')][_0xf952('0x44')]){_0x22004b['include']=[{'all':!![]}];}_0x22004b=_[_0xf952('0x3c')]({},_0x22004b,_0x17dc53[_0xf952('0x3f')]);return db[_0xf952('0x29')][_0xf952('0x45')](_0x22004b)[_0xf952('0x23')](handleEntityNotFound(_0x2a887d,null))[_0xf952('0x23')](respondWithResult(_0x2a887d,null))[_0xf952('0x46')](handleError(_0x2a887d,null));};exports[_0xf952('0x47')]=function(_0x530ece,_0x17e8be){return db[_0xf952('0x29')][_0xf952('0x47')](_0x530ece['body'],{})[_0xf952('0x23')](respondWithResult(_0x17e8be,0xc9))[_0xf952('0x46')](handleError(_0x17e8be,null));};exports[_0xf952('0x48')]=function(_0x1c3332,_0x3a1f22){if(_0x1c3332[_0xf952('0x49')]['id']){delete _0x1c3332['body']['id'];}return db[_0xf952('0x29')][_0xf952('0x45')]({'where':{'id':_0x1c3332['params']['id']}})[_0xf952('0x23')](handleEntityNotFound(_0x3a1f22,null))[_0xf952('0x23')](saveUpdates(_0x1c3332[_0xf952('0x49')],null))[_0xf952('0x23')](respondWithResult(_0x3a1f22,null))['catch'](handleError(_0x3a1f22,null));};exports[_0xf952('0x24')]=function(_0x4e89a6,_0x193256){return db['SalesforceField']['find']({'where':{'id':_0x4e89a6['params']['id']}})[_0xf952('0x23')](handleEntityNotFound(_0x193256,null))[_0xf952('0x23')](removeEntity(_0x193256,null))[_0xf952('0x46')](handleError(_0x193256,null));};