Built motion from commit (unavailable).|2.5.3
[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 _0xbbb3=['hasOwnProperty','offset','order','sort','where','pick','filter','merge','VIRTUAL','options','SalesforceField','count','includeAll','include','rows','catch','show','params','rawAttributes','length','find','create','body','destroy','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','sendStatus','status','json','limit','set','Content-Range','apply','reject','save','update','then','end','stack','name','send','index','map','fieldName','type','key','query','keys','filters','intersection','model','fields','attributes'];(function(_0x329044,_0x32e3b4){var _0x192555=function(_0x476d6c){while(--_0x476d6c){_0x329044['push'](_0x329044['shift']());}};_0x192555(++_0x32e3b4);}(_0xbbb3,0x1d4));var _0x3bbb=function(_0x4225de,_0x3e3909){_0x4225de=_0x4225de-0x0;var _0x111a00=_0xbbb3[_0x4225de];return _0x111a00;};'use strict';var pdf=require(_0x3bbb('0x0'));var emlformat=require(_0x3bbb('0x1'));var rimraf=require(_0x3bbb('0x2'));var zipdir=require(_0x3bbb('0x3'));var jsonpatch=require(_0x3bbb('0x4'));var rp=require(_0x3bbb('0x5'));var moment=require(_0x3bbb('0x6'));var BPromise=require(_0x3bbb('0x7'));var Mustache=require(_0x3bbb('0x8'));var util=require(_0x3bbb('0x9'));var path=require(_0x3bbb('0xa'));var sox=require(_0x3bbb('0xb'));var csv=require(_0x3bbb('0xc'));var ejs=require(_0x3bbb('0xd'));var fs=require('fs');var _=require('lodash');var squel=require(_0x3bbb('0xe'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x3bbb('0xf'));var toCsv=require(_0x3bbb('0xc'));var querystring=require(_0x3bbb('0x10'));var Papa=require('papaparse');var Redis=require(_0x3bbb('0x11'));var authService=require(_0x3bbb('0x12'));var qs=require(_0x3bbb('0x13'));var as=require(_0x3bbb('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x3bbb('0x15'))('api');var utils=require(_0x3bbb('0x16'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5d3842,_0xa8fe94){_0xa8fe94=_0xa8fe94||0xcc;return function(_0x507a33){if(_0x507a33){return _0x5d3842[_0x3bbb('0x17')](_0xa8fe94);}return _0x5d3842['status'](_0xa8fe94)['end']();};}function respondWithResult(_0x37bbe4,_0x423f8e){_0x423f8e=_0x423f8e||0xc8;return function(_0x41464f){if(_0x41464f){return _0x37bbe4[_0x3bbb('0x18')](_0x423f8e)[_0x3bbb('0x19')](_0x41464f);}};}function respondWithFilteredResult(_0x497f9e,_0x169a46){return function(_0x2ef78c){if(_0x2ef78c){var _0x43b872=_0x2ef78c['count'],_0x28da00=_0x169a46['offset'],_0x18127e=_0x169a46['offset']+_0x169a46[_0x3bbb('0x1a')],_0x2d183c;if(_0x18127e>=_0x43b872){_0x18127e=_0x43b872;_0x2d183c=0xc8;}else{_0x2d183c=0xce;}_0x497f9e[_0x3bbb('0x18')](_0x2d183c);return _0x497f9e[_0x3bbb('0x1b')](_0x3bbb('0x1c'),_0x28da00+'-'+_0x18127e+'/'+_0x43b872)[_0x3bbb('0x19')](_0x2ef78c);}return null;};}function patchUpdates(_0x476951){return function(_0x384064){try{jsonpatch[_0x3bbb('0x1d')](_0x384064,_0x476951,!![]);}catch(_0x4b193a){return BPromise[_0x3bbb('0x1e')](_0x4b193a);}return _0x384064[_0x3bbb('0x1f')]();};}function saveUpdates(_0x57d59a,_0x4ced95){return function(_0x384603){if(_0x384603){return _0x384603[_0x3bbb('0x20')](_0x57d59a)[_0x3bbb('0x21')](function(_0x123928){return _0x123928;});}return null;};}function removeEntity(_0x30797e,_0x53c54c){return function(_0x3624d8){if(_0x3624d8){return _0x3624d8['destroy']()[_0x3bbb('0x21')](function(){_0x30797e[_0x3bbb('0x18')](0xcc)[_0x3bbb('0x22')]();});}};}function handleEntityNotFound(_0x5d36e8,_0x3314e5){return function(_0x253585){if(!_0x253585){_0x5d36e8[_0x3bbb('0x17')](0x194);}return _0x253585;};}function handleError(_0x59b1f0,_0x12e624){_0x12e624=_0x12e624||0x1f4;return function(_0x4bc240){logger['error'](_0x4bc240[_0x3bbb('0x23')]);if(_0x4bc240[_0x3bbb('0x24')]){delete _0x4bc240[_0x3bbb('0x24')];}_0x59b1f0[_0x3bbb('0x18')](_0x12e624)[_0x3bbb('0x25')](_0x4bc240);};}exports[_0x3bbb('0x26')]=function(_0x1bbb51,_0x1025bb){var _0x3982c8={},_0x33cecc={},_0x150d6c={'count':0x0,'rows':[]};var _0x318480=_[_0x3bbb('0x27')](db['SalesforceField']['rawAttributes'],function(_0xc7cb9d){return{'name':_0xc7cb9d[_0x3bbb('0x28')],'type':_0xc7cb9d[_0x3bbb('0x29')][_0x3bbb('0x2a')]};});_0x33cecc['model']=_[_0x3bbb('0x27')](_0x318480,_0x3bbb('0x24'));_0x33cecc[_0x3bbb('0x2b')]=_[_0x3bbb('0x2c')](_0x1bbb51[_0x3bbb('0x2b')]);_0x33cecc[_0x3bbb('0x2d')]=_[_0x3bbb('0x2e')](_0x33cecc[_0x3bbb('0x2f')],_0x33cecc['query']);_0x3982c8['attributes']=_['intersection'](_0x33cecc[_0x3bbb('0x2f')],qs[_0x3bbb('0x30')](_0x1bbb51['query'][_0x3bbb('0x30')]));_0x3982c8[_0x3bbb('0x31')]=_0x3982c8[_0x3bbb('0x31')]['length']?_0x3982c8[_0x3bbb('0x31')]:_0x33cecc[_0x3bbb('0x2f')];if(!_0x1bbb51[_0x3bbb('0x2b')][_0x3bbb('0x32')]('nolimit')){_0x3982c8[_0x3bbb('0x1a')]=qs['limit'](_0x1bbb51[_0x3bbb('0x2b')][_0x3bbb('0x1a')]);_0x3982c8['offset']=qs[_0x3bbb('0x33')](_0x1bbb51[_0x3bbb('0x2b')][_0x3bbb('0x33')]);}_0x3982c8[_0x3bbb('0x34')]=qs[_0x3bbb('0x35')](_0x1bbb51['query'][_0x3bbb('0x35')]);_0x3982c8[_0x3bbb('0x36')]=qs[_0x3bbb('0x2d')](_[_0x3bbb('0x37')](_0x1bbb51[_0x3bbb('0x2b')],_0x33cecc['filters']),_0x318480);if(_0x1bbb51[_0x3bbb('0x2b')][_0x3bbb('0x38')]){_0x3982c8[_0x3bbb('0x36')]=_[_0x3bbb('0x39')](_0x3982c8[_0x3bbb('0x36')],{'$or':_[_0x3bbb('0x27')](_0x318480,function(_0x17f3f1){if(_0x17f3f1['type']!==_0x3bbb('0x3a')){var _0x49ddb1={};_0x49ddb1[_0x17f3f1[_0x3bbb('0x24')]]={'$like':'%'+_0x1bbb51['query'][_0x3bbb('0x38')]+'%'};return _0x49ddb1;}})});}_0x3982c8=_[_0x3bbb('0x39')]({},_0x3982c8,_0x1bbb51[_0x3bbb('0x3b')]);var _0x546bd1={'where':_0x3982c8[_0x3bbb('0x36')]};return db[_0x3bbb('0x3c')][_0x3bbb('0x3d')](_0x546bd1)[_0x3bbb('0x21')](function(_0x19e7e6){_0x150d6c[_0x3bbb('0x3d')]=_0x19e7e6;if(_0x1bbb51[_0x3bbb('0x2b')][_0x3bbb('0x3e')]){_0x3982c8[_0x3bbb('0x3f')]=[{'all':!![]}];}return db[_0x3bbb('0x3c')]['findAll'](_0x3982c8);})['then'](function(_0x2a95ba){_0x150d6c[_0x3bbb('0x40')]=_0x2a95ba;return _0x150d6c;})[_0x3bbb('0x21')](respondWithFilteredResult(_0x1025bb,_0x3982c8))[_0x3bbb('0x41')](handleError(_0x1025bb,null));};exports[_0x3bbb('0x42')]=function(_0x567adf,_0x5ae9a2){var _0x412e2d={'raw':!![],'where':{'id':_0x567adf[_0x3bbb('0x43')]['id']}},_0x4e3de9={};_0x4e3de9[_0x3bbb('0x2f')]=_[_0x3bbb('0x2c')](db[_0x3bbb('0x3c')][_0x3bbb('0x44')]);_0x4e3de9[_0x3bbb('0x2b')]=_['keys'](_0x567adf[_0x3bbb('0x2b')]);_0x4e3de9[_0x3bbb('0x2d')]=_[_0x3bbb('0x2e')](_0x4e3de9[_0x3bbb('0x2f')],_0x4e3de9[_0x3bbb('0x2b')]);_0x412e2d['attributes']=_[_0x3bbb('0x2e')](_0x4e3de9[_0x3bbb('0x2f')],qs['fields'](_0x567adf[_0x3bbb('0x2b')][_0x3bbb('0x30')]));_0x412e2d['attributes']=_0x412e2d[_0x3bbb('0x31')][_0x3bbb('0x45')]?_0x412e2d[_0x3bbb('0x31')]:_0x4e3de9['model'];if(_0x567adf[_0x3bbb('0x2b')][_0x3bbb('0x3e')]){_0x412e2d[_0x3bbb('0x3f')]=[{'all':!![]}];}_0x412e2d=_['merge']({},_0x412e2d,_0x567adf['options']);return db['SalesforceField'][_0x3bbb('0x46')](_0x412e2d)[_0x3bbb('0x21')](handleEntityNotFound(_0x5ae9a2,null))[_0x3bbb('0x21')](respondWithResult(_0x5ae9a2,null))[_0x3bbb('0x41')](handleError(_0x5ae9a2,null));};exports[_0x3bbb('0x47')]=function(_0x5e47c7,_0x174a32){return db[_0x3bbb('0x3c')][_0x3bbb('0x47')](_0x5e47c7[_0x3bbb('0x48')],{})['then'](respondWithResult(_0x174a32,0xc9))[_0x3bbb('0x41')](handleError(_0x174a32,null));};exports['update']=function(_0x30da03,_0x31413e){if(_0x30da03[_0x3bbb('0x48')]['id']){delete _0x30da03[_0x3bbb('0x48')]['id'];}return db[_0x3bbb('0x3c')][_0x3bbb('0x46')]({'where':{'id':_0x30da03[_0x3bbb('0x43')]['id']}})[_0x3bbb('0x21')](handleEntityNotFound(_0x31413e,null))['then'](saveUpdates(_0x30da03[_0x3bbb('0x48')],null))['then'](respondWithResult(_0x31413e,null))[_0x3bbb('0x41')](handleError(_0x31413e,null));};exports[_0x3bbb('0x49')]=function(_0x58c86a,_0x3dd528){return db[_0x3bbb('0x3c')][_0x3bbb('0x46')]({'where':{'id':_0x58c86a['params']['id']}})[_0x3bbb('0x21')](handleEntityNotFound(_0x3dd528,null))[_0x3bbb('0x21')](removeEntity(_0x3dd528,null))[_0x3bbb('0x41')](handleError(_0x3dd528,null));};