Built motion from commit 85328c08.|2.5.50
[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 _0xe281=['reject','save','update','then','sendStatus','error','stack','name','send','index','map','fieldName','type','key','model','query','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','filters','pick','filter','options','SugarcrmField','includeAll','include','findAll','rows','catch','show','params','keys','merge','find','create','body','destroy','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','status','end','json','undefined','offset','count','limit','set','apply'];(function(_0xadc6d5,_0x406c40){var _0x500fae=function(_0x10b90b){while(--_0x10b90b){_0xadc6d5['push'](_0xadc6d5['shift']());}};_0x500fae(++_0x406c40);}(_0xe281,0xb8));var _0x1e28=function(_0x3947c9,_0x4d6c97){_0x3947c9=_0x3947c9-0x0;var _0x2e7871=_0xe281[_0x3947c9];return _0x2e7871;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x1e28('0x0'));var jsonpatch=require(_0x1e28('0x1'));var rp=require(_0x1e28('0x2'));var moment=require(_0x1e28('0x3'));var BPromise=require(_0x1e28('0x4'));var Mustache=require('mustache');var util=require(_0x1e28('0x5'));var path=require(_0x1e28('0x6'));var sox=require(_0x1e28('0x7'));var csv=require(_0x1e28('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x1e28('0x9'));var _=require('lodash');var squel=require(_0x1e28('0xa'));var crypto=require(_0x1e28('0xb'));var jsforce=require(_0x1e28('0xc'));var deskjs=require(_0x1e28('0xd'));var toCsv=require(_0x1e28('0x8'));var querystring=require(_0x1e28('0xe'));var Papa=require(_0x1e28('0xf'));var Redis=require(_0x1e28('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x1e28('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x1e28('0x12'))('api');var utils=require(_0x1e28('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x5b1d9c,_0x1e6b65){_0x1e6b65=_0x1e6b65||0xcc;return function(_0x9742a7){if(_0x9742a7){return _0x5b1d9c['sendStatus'](_0x1e6b65);}return _0x5b1d9c[_0x1e28('0x14')](_0x1e6b65)[_0x1e28('0x15')]();};}function respondWithResult(_0x4a6537,_0x45362b){_0x45362b=_0x45362b||0xc8;return function(_0x2bd7fe){if(_0x2bd7fe){return _0x4a6537[_0x1e28('0x14')](_0x45362b)[_0x1e28('0x16')](_0x2bd7fe);}};}function respondWithFilteredResult(_0x2b06a0,_0xffef51){return function(_0x15d752){if(_0x15d752){var _0x25cc58=typeof _0xffef51['offset']==='undefined'&&typeof _0xffef51['limit']===_0x1e28('0x17');var _0x166df2=_0x15d752['count'];var _0x35155b=_0x25cc58?0x0:_0xffef51[_0x1e28('0x18')];var _0x57fc87=_0x25cc58?_0x15d752[_0x1e28('0x19')]:_0xffef51[_0x1e28('0x18')]+_0xffef51[_0x1e28('0x1a')];var _0x43ef70;if(_0x57fc87>=_0x166df2){_0x57fc87=_0x166df2;_0x43ef70=0xc8;}else{_0x43ef70=0xce;}_0x2b06a0[_0x1e28('0x14')](_0x43ef70);return _0x2b06a0[_0x1e28('0x1b')]('Content-Range',_0x35155b+'-'+_0x57fc87+'/'+_0x166df2)[_0x1e28('0x16')](_0x15d752);}return null;};}function patchUpdates(_0x37f705){return function(_0x2be9a0){try{jsonpatch[_0x1e28('0x1c')](_0x2be9a0,_0x37f705,!![]);}catch(_0x22933d){return BPromise[_0x1e28('0x1d')](_0x22933d);}return _0x2be9a0[_0x1e28('0x1e')]();};}function saveUpdates(_0x4a1db6,_0x2c4315){return function(_0x4e9d54){if(_0x4e9d54){return _0x4e9d54[_0x1e28('0x1f')](_0x4a1db6)[_0x1e28('0x20')](function(_0x25dd04){return _0x25dd04;});}return null;};}function removeEntity(_0x40e6aa,_0x16924a){return function(_0x771204){if(_0x771204){return _0x771204['destroy']()[_0x1e28('0x20')](function(){_0x40e6aa['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x46098b,_0x3dc6d8){return function(_0x160830){if(!_0x160830){_0x46098b[_0x1e28('0x21')](0x194);}return _0x160830;};}function handleError(_0x242411,_0x2181dc){_0x2181dc=_0x2181dc||0x1f4;return function(_0x1b452e){logger[_0x1e28('0x22')](_0x1b452e[_0x1e28('0x23')]);if(_0x1b452e[_0x1e28('0x24')]){delete _0x1b452e[_0x1e28('0x24')];}_0x242411['status'](_0x2181dc)[_0x1e28('0x25')](_0x1b452e);};}exports[_0x1e28('0x26')]=function(_0x2eddea,_0x49106e){var _0x5eb351={},_0x3ad261={},_0x453904={'count':0x0,'rows':[]};var _0x245a60=_[_0x1e28('0x27')](db['SugarcrmField']['rawAttributes'],function(_0x489eb3){return{'name':_0x489eb3[_0x1e28('0x28')],'type':_0x489eb3[_0x1e28('0x29')][_0x1e28('0x2a')]};});_0x3ad261[_0x1e28('0x2b')]=_['map'](_0x245a60,'name');_0x3ad261[_0x1e28('0x2c')]=_['keys'](_0x2eddea['query']);_0x3ad261['filters']=_[_0x1e28('0x2d')](_0x3ad261['model'],_0x3ad261[_0x1e28('0x2c')]);_0x5eb351[_0x1e28('0x2e')]=_[_0x1e28('0x2d')](_0x3ad261[_0x1e28('0x2b')],qs['fields'](_0x2eddea[_0x1e28('0x2c')][_0x1e28('0x2f')]));_0x5eb351[_0x1e28('0x2e')]=_0x5eb351[_0x1e28('0x2e')][_0x1e28('0x30')]?_0x5eb351[_0x1e28('0x2e')]:_0x3ad261[_0x1e28('0x2b')];if(!_0x2eddea[_0x1e28('0x2c')][_0x1e28('0x31')]('nolimit')){_0x5eb351[_0x1e28('0x1a')]=qs['limit'](_0x2eddea[_0x1e28('0x2c')][_0x1e28('0x1a')]);_0x5eb351['offset']=qs['offset'](_0x2eddea[_0x1e28('0x2c')]['offset']);}_0x5eb351[_0x1e28('0x32')]=qs[_0x1e28('0x33')](_0x2eddea[_0x1e28('0x2c')][_0x1e28('0x33')]);_0x5eb351[_0x1e28('0x34')]=qs[_0x1e28('0x35')](_[_0x1e28('0x36')](_0x2eddea[_0x1e28('0x2c')],_0x3ad261['filters']),_0x245a60);if(_0x2eddea[_0x1e28('0x2c')]['filter']){_0x5eb351[_0x1e28('0x34')]=_['merge'](_0x5eb351['where'],{'$or':_['map'](_0x245a60,function(_0xc914ba){if(_0xc914ba[_0x1e28('0x29')]!=='VIRTUAL'){var _0x54888a={};_0x54888a[_0xc914ba['name']]={'$like':'%'+_0x2eddea[_0x1e28('0x2c')][_0x1e28('0x37')]+'%'};return _0x54888a;}})});}_0x5eb351=_['merge']({},_0x5eb351,_0x2eddea[_0x1e28('0x38')]);var _0x2c1e6e={'where':_0x5eb351[_0x1e28('0x34')]};return db[_0x1e28('0x39')]['count'](_0x2c1e6e)[_0x1e28('0x20')](function(_0x3a258c){_0x453904['count']=_0x3a258c;if(_0x2eddea[_0x1e28('0x2c')][_0x1e28('0x3a')]){_0x5eb351[_0x1e28('0x3b')]=[{'all':!![]}];}return db[_0x1e28('0x39')][_0x1e28('0x3c')](_0x5eb351);})['then'](function(_0x394213){_0x453904[_0x1e28('0x3d')]=_0x394213;return _0x453904;})[_0x1e28('0x20')](respondWithFilteredResult(_0x49106e,_0x5eb351))[_0x1e28('0x3e')](handleError(_0x49106e,null));};exports[_0x1e28('0x3f')]=function(_0x54a04d,_0x3e3d2e){var _0x1401f2={'raw':!![],'where':{'id':_0x54a04d[_0x1e28('0x40')]['id']}},_0x41bbd5={};_0x41bbd5[_0x1e28('0x2b')]=_[_0x1e28('0x41')](db[_0x1e28('0x39')]['rawAttributes']);_0x41bbd5['query']=_[_0x1e28('0x41')](_0x54a04d['query']);_0x41bbd5[_0x1e28('0x35')]=_[_0x1e28('0x2d')](_0x41bbd5[_0x1e28('0x2b')],_0x41bbd5[_0x1e28('0x2c')]);_0x1401f2[_0x1e28('0x2e')]=_[_0x1e28('0x2d')](_0x41bbd5[_0x1e28('0x2b')],qs[_0x1e28('0x2f')](_0x54a04d[_0x1e28('0x2c')][_0x1e28('0x2f')]));_0x1401f2['attributes']=_0x1401f2[_0x1e28('0x2e')][_0x1e28('0x30')]?_0x1401f2[_0x1e28('0x2e')]:_0x41bbd5['model'];if(_0x54a04d['query'][_0x1e28('0x3a')]){_0x1401f2[_0x1e28('0x3b')]=[{'all':!![]}];}_0x1401f2=_[_0x1e28('0x42')]({},_0x1401f2,_0x54a04d[_0x1e28('0x38')]);return db[_0x1e28('0x39')][_0x1e28('0x43')](_0x1401f2)[_0x1e28('0x20')](handleEntityNotFound(_0x3e3d2e,null))[_0x1e28('0x20')](respondWithResult(_0x3e3d2e,null))[_0x1e28('0x3e')](handleError(_0x3e3d2e,null));};exports[_0x1e28('0x44')]=function(_0x2bf516,_0x551718){return db[_0x1e28('0x39')]['create'](_0x2bf516[_0x1e28('0x45')],{})['then'](respondWithResult(_0x551718,0xc9))[_0x1e28('0x3e')](handleError(_0x551718,null));};exports[_0x1e28('0x1f')]=function(_0x2f18ac,_0x143b31){if(_0x2f18ac[_0x1e28('0x45')]['id']){delete _0x2f18ac[_0x1e28('0x45')]['id'];}return db[_0x1e28('0x39')][_0x1e28('0x43')]({'where':{'id':_0x2f18ac['params']['id']}})[_0x1e28('0x20')](handleEntityNotFound(_0x143b31,null))[_0x1e28('0x20')](saveUpdates(_0x2f18ac[_0x1e28('0x45')],null))['then'](respondWithResult(_0x143b31,null))[_0x1e28('0x3e')](handleError(_0x143b31,null));};exports[_0x1e28('0x46')]=function(_0x442f6b,_0x2799ba){return db[_0x1e28('0x39')][_0x1e28('0x43')]({'where':{'id':_0x442f6b[_0x1e28('0x40')]['id']}})['then'](handleEntityNotFound(_0x2799ba,null))[_0x1e28('0x20')](removeEntity(_0x2799ba,null))[_0x1e28('0x3e')](handleError(_0x2799ba,null));};