716620fd1b4c459f0b4d1d1319f96540629ab667
[motion2.git] / server / api / intSugarcrmField / intSugarcrmField.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 _0xfcbf=['name','index','map','SugarcrmField','rawAttributes','fieldName','type','query','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','merge','filter','findAll','rows','catch','show','params','keys','length','includeAll','include','find','body','destroy','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','jsforce','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then','error','stack'];(function(_0x3885cd,_0x4dc619){var _0x1e5c7e=function(_0x54b7b5){while(--_0x54b7b5){_0x3885cd['push'](_0x3885cd['shift']());}};_0x1e5c7e(++_0x4dc619);}(_0xfcbf,0x188));var _0xffcb=function(_0x5d0e7e,_0x5f2010){_0x5d0e7e=_0x5d0e7e-0x0;var _0x2d4118=_0xfcbf[_0x5d0e7e];return _0x2d4118;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xffcb('0x0'));var zipdir=require(_0xffcb('0x1'));var jsonpatch=require(_0xffcb('0x2'));var rp=require(_0xffcb('0x3'));var moment=require(_0xffcb('0x4'));var BPromise=require(_0xffcb('0x5'));var Mustache=require(_0xffcb('0x6'));var util=require('util');var path=require(_0xffcb('0x7'));var sox=require(_0xffcb('0x8'));var csv=require(_0xffcb('0x9'));var ejs=require(_0xffcb('0xa'));var fs=require('fs');var fs_extra=require(_0xffcb('0xb'));var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xffcb('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xffcb('0xd'));var authService=require(_0xffcb('0xe'));var qs=require(_0xffcb('0xf'));var as=require(_0xffcb('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xffcb('0x11'))(_0xffcb('0x12'));var utils=require(_0xffcb('0x13'));var config=require(_0xffcb('0x14'));var licenseUtil=require(_0xffcb('0x15'));var db=require(_0xffcb('0x16'))['db'];function respondWithStatusCode(_0x28a8fd,_0x480b66){_0x480b66=_0x480b66||0xcc;return function(_0xf81592){if(_0xf81592){return _0x28a8fd[_0xffcb('0x17')](_0x480b66);}return _0x28a8fd[_0xffcb('0x18')](_0x480b66)[_0xffcb('0x19')]();};}function respondWithResult(_0x449644,_0x337306){_0x337306=_0x337306||0xc8;return function(_0x4b0c6b){if(_0x4b0c6b){return _0x449644[_0xffcb('0x18')](_0x337306)['json'](_0x4b0c6b);}};}function respondWithFilteredResult(_0x295e84,_0x15e930){return function(_0x45ffe7){if(_0x45ffe7){var _0x2b5bc8=typeof _0x15e930[_0xffcb('0x1a')]===_0xffcb('0x1b')&&typeof _0x15e930[_0xffcb('0x1c')]===_0xffcb('0x1b');var _0x387556=_0x45ffe7[_0xffcb('0x1d')];var _0x30ded5=_0x2b5bc8?0x0:_0x15e930['offset'];var _0xe780df=_0x2b5bc8?_0x45ffe7[_0xffcb('0x1d')]:_0x15e930[_0xffcb('0x1a')]+_0x15e930['limit'];var _0x8cc26a;if(_0xe780df>=_0x387556){_0xe780df=_0x387556;_0x8cc26a=0xc8;}else{_0x8cc26a=0xce;}_0x295e84[_0xffcb('0x18')](_0x8cc26a);return _0x295e84[_0xffcb('0x1e')](_0xffcb('0x1f'),_0x30ded5+'-'+_0xe780df+'/'+_0x387556)[_0xffcb('0x20')](_0x45ffe7);}return null;};}function patchUpdates(_0x4d9102){return function(_0x154ce2){try{jsonpatch[_0xffcb('0x21')](_0x154ce2,_0x4d9102,!![]);}catch(_0x4846f4){return BPromise[_0xffcb('0x22')](_0x4846f4);}return _0x154ce2[_0xffcb('0x23')]();};}function saveUpdates(_0x2715ad,_0x179924){return function(_0x382561){if(_0x382561){return _0x382561[_0xffcb('0x24')](_0x2715ad)[_0xffcb('0x25')](function(_0x509ac9){return _0x509ac9;});}return null;};}function removeEntity(_0x5d23fe,_0x4a30c2){return function(_0x55fc88){if(_0x55fc88){return _0x55fc88['destroy']()[_0xffcb('0x25')](function(){_0x5d23fe['status'](0xcc)[_0xffcb('0x19')]();});}};}function handleEntityNotFound(_0x24e45a,_0x5f5798){return function(_0x342fa0){if(!_0x342fa0){_0x24e45a['sendStatus'](0x194);}return _0x342fa0;};}function handleError(_0x2d1979,_0x4f9a59){_0x4f9a59=_0x4f9a59||0x1f4;return function(_0x6e6f65){logger[_0xffcb('0x26')](_0x6e6f65[_0xffcb('0x27')]);if(_0x6e6f65[_0xffcb('0x28')]){delete _0x6e6f65[_0xffcb('0x28')];}_0x2d1979['status'](_0x4f9a59)['send'](_0x6e6f65);};}exports[_0xffcb('0x29')]=function(_0x3de594,_0x4edcbe){var _0x545b54={},_0x1c91f2={},_0x2bf3cb={'count':0x0,'rows':[]};var _0x23fa3e=_[_0xffcb('0x2a')](db[_0xffcb('0x2b')][_0xffcb('0x2c')],function(_0x12249b){return{'name':_0x12249b[_0xffcb('0x2d')],'type':_0x12249b[_0xffcb('0x2e')]['key']};});_0x1c91f2['model']=_[_0xffcb('0x2a')](_0x23fa3e,'name');_0x1c91f2[_0xffcb('0x2f')]=_['keys'](_0x3de594[_0xffcb('0x2f')]);_0x1c91f2[_0xffcb('0x30')]=_[_0xffcb('0x31')](_0x1c91f2[_0xffcb('0x32')],_0x1c91f2[_0xffcb('0x2f')]);_0x545b54[_0xffcb('0x33')]=_['intersection'](_0x1c91f2[_0xffcb('0x32')],qs[_0xffcb('0x34')](_0x3de594['query'][_0xffcb('0x34')]));_0x545b54[_0xffcb('0x33')]=_0x545b54[_0xffcb('0x33')]['length']?_0x545b54[_0xffcb('0x33')]:_0x1c91f2[_0xffcb('0x32')];if(!_0x3de594[_0xffcb('0x2f')][_0xffcb('0x35')](_0xffcb('0x36'))){_0x545b54['limit']=qs[_0xffcb('0x1c')](_0x3de594['query'][_0xffcb('0x1c')]);_0x545b54['offset']=qs[_0xffcb('0x1a')](_0x3de594['query'][_0xffcb('0x1a')]);}_0x545b54[_0xffcb('0x37')]=qs[_0xffcb('0x38')](_0x3de594['query'][_0xffcb('0x38')]);_0x545b54[_0xffcb('0x39')]=qs[_0xffcb('0x30')](_['pick'](_0x3de594[_0xffcb('0x2f')],_0x1c91f2[_0xffcb('0x30')]),_0x23fa3e);if(_0x3de594['query']['filter']){_0x545b54['where']=_[_0xffcb('0x3a')](_0x545b54[_0xffcb('0x39')],{'$or':_['map'](_0x23fa3e,function(_0x3d2917){if(_0x3d2917['type']!=='VIRTUAL'){var _0x57309b={};_0x57309b[_0x3d2917[_0xffcb('0x28')]]={'$like':'%'+_0x3de594[_0xffcb('0x2f')][_0xffcb('0x3b')]+'%'};return _0x57309b;}})});}_0x545b54=_[_0xffcb('0x3a')]({},_0x545b54,_0x3de594['options']);var _0x4fb5bd={'where':_0x545b54[_0xffcb('0x39')]};return db[_0xffcb('0x2b')]['count'](_0x4fb5bd)['then'](function(_0x80e23){_0x2bf3cb['count']=_0x80e23;if(_0x3de594[_0xffcb('0x2f')]['includeAll']){_0x545b54['include']=[{'all':!![]}];}return db['SugarcrmField'][_0xffcb('0x3c')](_0x545b54);})[_0xffcb('0x25')](function(_0x5c9b72){_0x2bf3cb[_0xffcb('0x3d')]=_0x5c9b72;return _0x2bf3cb;})[_0xffcb('0x25')](respondWithFilteredResult(_0x4edcbe,_0x545b54))[_0xffcb('0x3e')](handleError(_0x4edcbe,null));};exports[_0xffcb('0x3f')]=function(_0x383a07,_0x298e61){var _0x5b62fd={'raw':!![],'where':{'id':_0x383a07[_0xffcb('0x40')]['id']}},_0x19af94={};_0x19af94[_0xffcb('0x32')]=_[_0xffcb('0x41')](db[_0xffcb('0x2b')][_0xffcb('0x2c')]);_0x19af94['query']=_[_0xffcb('0x41')](_0x383a07[_0xffcb('0x2f')]);_0x19af94[_0xffcb('0x30')]=_[_0xffcb('0x31')](_0x19af94[_0xffcb('0x32')],_0x19af94[_0xffcb('0x2f')]);_0x5b62fd['attributes']=_[_0xffcb('0x31')](_0x19af94[_0xffcb('0x32')],qs[_0xffcb('0x34')](_0x383a07['query'][_0xffcb('0x34')]));_0x5b62fd[_0xffcb('0x33')]=_0x5b62fd[_0xffcb('0x33')][_0xffcb('0x42')]?_0x5b62fd[_0xffcb('0x33')]:_0x19af94[_0xffcb('0x32')];if(_0x383a07[_0xffcb('0x2f')][_0xffcb('0x43')]){_0x5b62fd[_0xffcb('0x44')]=[{'all':!![]}];}_0x5b62fd=_['merge']({},_0x5b62fd,_0x383a07['options']);return db[_0xffcb('0x2b')][_0xffcb('0x45')](_0x5b62fd)[_0xffcb('0x25')](handleEntityNotFound(_0x298e61,null))[_0xffcb('0x25')](respondWithResult(_0x298e61,null))[_0xffcb('0x3e')](handleError(_0x298e61,null));};exports['create']=function(_0x4837e1,_0x512611){return db[_0xffcb('0x2b')]['create'](_0x4837e1[_0xffcb('0x46')],{})[_0xffcb('0x25')](respondWithResult(_0x512611,0xc9))[_0xffcb('0x3e')](handleError(_0x512611,null));};exports['update']=function(_0x336bf6,_0x4abe89){if(_0x336bf6['body']['id']){delete _0x336bf6[_0xffcb('0x46')]['id'];}return db[_0xffcb('0x2b')][_0xffcb('0x45')]({'where':{'id':_0x336bf6[_0xffcb('0x40')]['id']}})['then'](handleEntityNotFound(_0x4abe89,null))[_0xffcb('0x25')](saveUpdates(_0x336bf6[_0xffcb('0x46')],null))[_0xffcb('0x25')](respondWithResult(_0x4abe89,null))[_0xffcb('0x3e')](handleError(_0x4abe89,null));};exports[_0xffcb('0x47')]=function(_0x354043,_0x121501){return db[_0xffcb('0x2b')]['find']({'where':{'id':_0x354043[_0xffcb('0x40')]['id']}})[_0xffcb('0x25')](handleEntityNotFound(_0x121501,null))['then'](removeEntity(_0x121501,null))[_0xffcb('0x3e')](handleError(_0x121501,null));};