95529ede5203f3f6405b4dbcddd079211b8fb63c
[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 _0x904e=['filters','filter','where','merge','type','VIRTUAL','options','SugarcrmField','includeAll','findAll','rows','catch','show','params','keys','include','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','end','undefined','count','offset','status','Content-Range','json','reject','save','update','then','destroy','error','stack','name','index','map','rawAttributes','fieldName','model','query','intersection','fields','attributes','limit','order','sort','pick'];(function(_0x397cfb,_0xb8f317){var _0x15fed9=function(_0x3eba43){while(--_0x3eba43){_0x397cfb['push'](_0x397cfb['shift']());}};_0x15fed9(++_0xb8f317);}(_0x904e,0xa9));var _0xe904=function(_0x2b10c6,_0x185590){_0x2b10c6=_0x2b10c6-0x0;var _0x3789d2=_0x904e[_0x2b10c6];return _0x3789d2;};'use strict';var emlformat=require(_0xe904('0x0'));var rimraf=require(_0xe904('0x1'));var zipdir=require(_0xe904('0x2'));var jsonpatch=require(_0xe904('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xe904('0x4'));var Mustache=require(_0xe904('0x5'));var util=require(_0xe904('0x6'));var path=require(_0xe904('0x7'));var sox=require(_0xe904('0x8'));var csv=require(_0xe904('0x9'));var ejs=require(_0xe904('0xa'));var fs=require('fs');var fs_extra=require(_0xe904('0xb'));var _=require('lodash');var squel=require(_0xe904('0xc'));var crypto=require(_0xe904('0xd'));var jsforce=require(_0xe904('0xe'));var deskjs=require(_0xe904('0xf'));var toCsv=require(_0xe904('0x9'));var querystring=require(_0xe904('0x10'));var Papa=require(_0xe904('0x11'));var Redis=require(_0xe904('0x12'));var authService=require(_0xe904('0x13'));var qs=require(_0xe904('0x14'));var as=require(_0xe904('0x15'));var hardwareService=require(_0xe904('0x16'));var logger=require(_0xe904('0x17'))(_0xe904('0x18'));var utils=require(_0xe904('0x19'));var config=require(_0xe904('0x1a'));var licenseUtil=require(_0xe904('0x1b'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x54269d,_0x4292ea){_0x4292ea=_0x4292ea||0xcc;return function(_0x54e515){if(_0x54e515){return _0x54269d['sendStatus'](_0x4292ea);}return _0x54269d['status'](_0x4292ea)[_0xe904('0x1c')]();};}function respondWithResult(_0x5339f6,_0xf6d525){_0xf6d525=_0xf6d525||0xc8;return function(_0x1844cf){if(_0x1844cf){return _0x5339f6['status'](_0xf6d525)['json'](_0x1844cf);}};}function respondWithFilteredResult(_0x7ae44a,_0xf1b873){return function(_0x5a3c66){if(_0x5a3c66){var _0x542877=typeof _0xf1b873['offset']===_0xe904('0x1d')&&typeof _0xf1b873['limit']===_0xe904('0x1d');var _0x3eeaf7=_0x5a3c66[_0xe904('0x1e')];var _0xa5b2a8=_0x542877?0x0:_0xf1b873[_0xe904('0x1f')];var _0x542ea9=_0x542877?_0x5a3c66[_0xe904('0x1e')]:_0xf1b873[_0xe904('0x1f')]+_0xf1b873['limit'];var _0xd4ef50;if(_0x542ea9>=_0x3eeaf7){_0x542ea9=_0x3eeaf7;_0xd4ef50=0xc8;}else{_0xd4ef50=0xce;}_0x7ae44a[_0xe904('0x20')](_0xd4ef50);return _0x7ae44a['set'](_0xe904('0x21'),_0xa5b2a8+'-'+_0x542ea9+'/'+_0x3eeaf7)[_0xe904('0x22')](_0x5a3c66);}return null;};}function patchUpdates(_0x53c80a){return function(_0x3f4e78){try{jsonpatch['apply'](_0x3f4e78,_0x53c80a,!![]);}catch(_0x64a369){return BPromise[_0xe904('0x23')](_0x64a369);}return _0x3f4e78[_0xe904('0x24')]();};}function saveUpdates(_0x43e3b1,_0x3a463a){return function(_0x174344){if(_0x174344){return _0x174344[_0xe904('0x25')](_0x43e3b1)[_0xe904('0x26')](function(_0x5e8358){return _0x5e8358;});}return null;};}function removeEntity(_0x96ae49,_0xab9f26){return function(_0x4837ae){if(_0x4837ae){return _0x4837ae[_0xe904('0x27')]()['then'](function(){_0x96ae49[_0xe904('0x20')](0xcc)[_0xe904('0x1c')]();});}};}function handleEntityNotFound(_0x47a307,_0x5c6bb5){return function(_0x19ba27){if(!_0x19ba27){_0x47a307['sendStatus'](0x194);}return _0x19ba27;};}function handleError(_0x47c8e8,_0x2567e5){_0x2567e5=_0x2567e5||0x1f4;return function(_0x58e96a){logger[_0xe904('0x28')](_0x58e96a[_0xe904('0x29')]);if(_0x58e96a[_0xe904('0x2a')]){delete _0x58e96a[_0xe904('0x2a')];}_0x47c8e8['status'](_0x2567e5)['send'](_0x58e96a);};}exports[_0xe904('0x2b')]=function(_0x9e44bd,_0x49b765){var _0x2b608b={},_0xe19796={},_0x43275e={'count':0x0,'rows':[]};var _0x59cbc0=_[_0xe904('0x2c')](db['SugarcrmField'][_0xe904('0x2d')],function(_0x100eef){return{'name':_0x100eef[_0xe904('0x2e')],'type':_0x100eef['type']['key']};});_0xe19796[_0xe904('0x2f')]=_[_0xe904('0x2c')](_0x59cbc0,_0xe904('0x2a'));_0xe19796[_0xe904('0x30')]=_['keys'](_0x9e44bd[_0xe904('0x30')]);_0xe19796['filters']=_['intersection'](_0xe19796[_0xe904('0x2f')],_0xe19796[_0xe904('0x30')]);_0x2b608b['attributes']=_[_0xe904('0x31')](_0xe19796[_0xe904('0x2f')],qs[_0xe904('0x32')](_0x9e44bd[_0xe904('0x30')][_0xe904('0x32')]));_0x2b608b[_0xe904('0x33')]=_0x2b608b[_0xe904('0x33')]['length']?_0x2b608b[_0xe904('0x33')]:_0xe19796[_0xe904('0x2f')];if(!_0x9e44bd[_0xe904('0x30')]['hasOwnProperty']('nolimit')){_0x2b608b['limit']=qs['limit'](_0x9e44bd[_0xe904('0x30')][_0xe904('0x34')]);_0x2b608b[_0xe904('0x1f')]=qs[_0xe904('0x1f')](_0x9e44bd[_0xe904('0x30')][_0xe904('0x1f')]);}_0x2b608b[_0xe904('0x35')]=qs[_0xe904('0x36')](_0x9e44bd[_0xe904('0x30')][_0xe904('0x36')]);_0x2b608b['where']=qs['filters'](_[_0xe904('0x37')](_0x9e44bd[_0xe904('0x30')],_0xe19796[_0xe904('0x38')]),_0x59cbc0);if(_0x9e44bd[_0xe904('0x30')][_0xe904('0x39')]){_0x2b608b[_0xe904('0x3a')]=_[_0xe904('0x3b')](_0x2b608b[_0xe904('0x3a')],{'$or':_['map'](_0x59cbc0,function(_0x485045){if(_0x485045[_0xe904('0x3c')]!==_0xe904('0x3d')){var _0x3e932f={};_0x3e932f[_0x485045[_0xe904('0x2a')]]={'$like':'%'+_0x9e44bd['query']['filter']+'%'};return _0x3e932f;}})});}_0x2b608b=_['merge']({},_0x2b608b,_0x9e44bd[_0xe904('0x3e')]);var _0x24638a={'where':_0x2b608b[_0xe904('0x3a')]};return db[_0xe904('0x3f')]['count'](_0x24638a)['then'](function(_0x47aefc){_0x43275e[_0xe904('0x1e')]=_0x47aefc;if(_0x9e44bd[_0xe904('0x30')][_0xe904('0x40')]){_0x2b608b['include']=[{'all':!![]}];}return db['SugarcrmField'][_0xe904('0x41')](_0x2b608b);})[_0xe904('0x26')](function(_0x4b181b){_0x43275e[_0xe904('0x42')]=_0x4b181b;return _0x43275e;})[_0xe904('0x26')](respondWithFilteredResult(_0x49b765,_0x2b608b))[_0xe904('0x43')](handleError(_0x49b765,null));};exports[_0xe904('0x44')]=function(_0x13a35d,_0x18a9e1){var _0x53ead1={'raw':!![],'where':{'id':_0x13a35d[_0xe904('0x45')]['id']}},_0x33b664={};_0x33b664[_0xe904('0x2f')]=_[_0xe904('0x46')](db[_0xe904('0x3f')][_0xe904('0x2d')]);_0x33b664[_0xe904('0x30')]=_[_0xe904('0x46')](_0x13a35d[_0xe904('0x30')]);_0x33b664[_0xe904('0x38')]=_['intersection'](_0x33b664[_0xe904('0x2f')],_0x33b664[_0xe904('0x30')]);_0x53ead1['attributes']=_[_0xe904('0x31')](_0x33b664['model'],qs[_0xe904('0x32')](_0x13a35d[_0xe904('0x30')][_0xe904('0x32')]));_0x53ead1['attributes']=_0x53ead1[_0xe904('0x33')]['length']?_0x53ead1['attributes']:_0x33b664[_0xe904('0x2f')];if(_0x13a35d['query']['includeAll']){_0x53ead1[_0xe904('0x47')]=[{'all':!![]}];}_0x53ead1=_['merge']({},_0x53ead1,_0x13a35d[_0xe904('0x3e')]);return db[_0xe904('0x3f')][_0xe904('0x48')](_0x53ead1)[_0xe904('0x26')](handleEntityNotFound(_0x18a9e1,null))[_0xe904('0x26')](respondWithResult(_0x18a9e1,null))[_0xe904('0x43')](handleError(_0x18a9e1,null));};exports['create']=function(_0x241b1d,_0x2c7a13){return db[_0xe904('0x3f')][_0xe904('0x49')](_0x241b1d['body'],{})[_0xe904('0x26')](respondWithResult(_0x2c7a13,0xc9))['catch'](handleError(_0x2c7a13,null));};exports['update']=function(_0x2ed961,_0xf7fb86){if(_0x2ed961[_0xe904('0x4a')]['id']){delete _0x2ed961['body']['id'];}return db[_0xe904('0x3f')]['find']({'where':{'id':_0x2ed961[_0xe904('0x45')]['id']}})['then'](handleEntityNotFound(_0xf7fb86,null))[_0xe904('0x26')](saveUpdates(_0x2ed961[_0xe904('0x4a')],null))[_0xe904('0x26')](respondWithResult(_0xf7fb86,null))[_0xe904('0x43')](handleError(_0xf7fb86,null));};exports['destroy']=function(_0x54dc0c,_0x3bffa6){return db[_0xe904('0x3f')]['find']({'where':{'id':_0x54dc0c[_0xe904('0x45')]['id']}})[_0xe904('0x26')](handleEntityNotFound(_0x3bffa6,null))[_0xe904('0x26')](removeEntity(_0x3bffa6,null))[_0xe904('0x43')](handleError(_0x3bffa6,null));};