Built motion from commit (unavailable).|2.5.27
[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 _0x27f7=['jsforce','desk.js','to-csv','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','count','offset','limit','Content-Range','json','reject','save','update','then','destroy','error','stack','name','send','index','map','SugarcrmField','fieldName','model','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','merge','VIRTUAL','filter','options','include','findAll','rows','catch','show','keys','find','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','fs-extra','lodash','squel','crypto'];(function(_0x37bcd8,_0x27bed9){var _0x422480=function(_0x510db3){while(--_0x510db3){_0x37bcd8['push'](_0x37bcd8['shift']());}};_0x422480(++_0x27bed9);}(_0x27f7,0xcc));var _0x727f=function(_0x2f916e,_0x11011d){_0x2f916e=_0x2f916e-0x0;var _0x3eb589=_0x27f7[_0x2f916e];return _0x3eb589;};'use strict';var emlformat=require(_0x727f('0x0'));var rimraf=require(_0x727f('0x1'));var zipdir=require(_0x727f('0x2'));var jsonpatch=require(_0x727f('0x3'));var rp=require(_0x727f('0x4'));var moment=require('moment');var BPromise=require(_0x727f('0x5'));var Mustache=require('mustache');var util=require(_0x727f('0x6'));var path=require(_0x727f('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x727f('0x8'));var _=require(_0x727f('0x9'));var squel=require(_0x727f('0xa'));var crypto=require(_0x727f('0xb'));var jsforce=require(_0x727f('0xc'));var deskjs=require(_0x727f('0xd'));var toCsv=require(_0x727f('0xe'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x727f('0xf'));var authService=require(_0x727f('0x10'));var qs=require(_0x727f('0x11'));var as=require(_0x727f('0x12'));var hardwareService=require(_0x727f('0x13'));var logger=require(_0x727f('0x14'))(_0x727f('0x15'));var utils=require(_0x727f('0x16'));var config=require(_0x727f('0x17'));var licenseUtil=require(_0x727f('0x18'));var db=require(_0x727f('0x19'))['db'];function respondWithStatusCode(_0x3a41d0,_0x27685f){_0x27685f=_0x27685f||0xcc;return function(_0x53a43e){if(_0x53a43e){return _0x3a41d0[_0x727f('0x1a')](_0x27685f);}return _0x3a41d0[_0x727f('0x1b')](_0x27685f)[_0x727f('0x1c')]();};}function respondWithResult(_0x3da157,_0x4e806a){_0x4e806a=_0x4e806a||0xc8;return function(_0x2fedf1){if(_0x2fedf1){return _0x3da157['status'](_0x4e806a)['json'](_0x2fedf1);}};}function respondWithFilteredResult(_0x548d7a,_0x418a37){return function(_0x2e7037){if(_0x2e7037){var _0x5716cb=_0x2e7037[_0x727f('0x1d')],_0x1ed186=_0x418a37['offset'],_0x3dd7e5=_0x418a37[_0x727f('0x1e')]+_0x418a37[_0x727f('0x1f')],_0x3a026a;if(_0x3dd7e5>=_0x5716cb){_0x3dd7e5=_0x5716cb;_0x3a026a=0xc8;}else{_0x3a026a=0xce;}_0x548d7a[_0x727f('0x1b')](_0x3a026a);return _0x548d7a['set'](_0x727f('0x20'),_0x1ed186+'-'+_0x3dd7e5+'/'+_0x5716cb)[_0x727f('0x21')](_0x2e7037);}return null;};}function patchUpdates(_0x2a5557){return function(_0x49bca2){try{jsonpatch['apply'](_0x49bca2,_0x2a5557,!![]);}catch(_0x1583cf){return BPromise[_0x727f('0x22')](_0x1583cf);}return _0x49bca2[_0x727f('0x23')]();};}function saveUpdates(_0x4777d6,_0x264cbf){return function(_0x50805b){if(_0x50805b){return _0x50805b[_0x727f('0x24')](_0x4777d6)[_0x727f('0x25')](function(_0x5748d6){return _0x5748d6;});}return null;};}function removeEntity(_0xf1f1fc,_0x33ac4d){return function(_0x1e0813){if(_0x1e0813){return _0x1e0813[_0x727f('0x26')]()['then'](function(){_0xf1f1fc[_0x727f('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5bcaed,_0x53620e){return function(_0x2d6ef0){if(!_0x2d6ef0){_0x5bcaed[_0x727f('0x1a')](0x194);}return _0x2d6ef0;};}function handleError(_0x56cfa2,_0x41b7c1){_0x41b7c1=_0x41b7c1||0x1f4;return function(_0x29d5f2){logger[_0x727f('0x27')](_0x29d5f2[_0x727f('0x28')]);if(_0x29d5f2[_0x727f('0x29')]){delete _0x29d5f2[_0x727f('0x29')];}_0x56cfa2['status'](_0x41b7c1)[_0x727f('0x2a')](_0x29d5f2);};}exports[_0x727f('0x2b')]=function(_0x541bb4,_0x29442f){var _0x3ef439={},_0xa1be9={},_0x3d72ee={'count':0x0,'rows':[]};var _0xf03e05=_[_0x727f('0x2c')](db[_0x727f('0x2d')]['rawAttributes'],function(_0x56255f){return{'name':_0x56255f[_0x727f('0x2e')],'type':_0x56255f['type']['key']};});_0xa1be9[_0x727f('0x2f')]=_[_0x727f('0x2c')](_0xf03e05,_0x727f('0x29'));_0xa1be9[_0x727f('0x30')]=_['keys'](_0x541bb4[_0x727f('0x30')]);_0xa1be9[_0x727f('0x31')]=_[_0x727f('0x32')](_0xa1be9[_0x727f('0x2f')],_0xa1be9[_0x727f('0x30')]);_0x3ef439[_0x727f('0x33')]=_[_0x727f('0x32')](_0xa1be9[_0x727f('0x2f')],qs[_0x727f('0x34')](_0x541bb4[_0x727f('0x30')][_0x727f('0x34')]));_0x3ef439[_0x727f('0x33')]=_0x3ef439[_0x727f('0x33')][_0x727f('0x35')]?_0x3ef439[_0x727f('0x33')]:_0xa1be9[_0x727f('0x2f')];if(!_0x541bb4['query']['hasOwnProperty'](_0x727f('0x36'))){_0x3ef439[_0x727f('0x1f')]=qs[_0x727f('0x1f')](_0x541bb4[_0x727f('0x30')][_0x727f('0x1f')]);_0x3ef439[_0x727f('0x1e')]=qs[_0x727f('0x1e')](_0x541bb4['query']['offset']);}_0x3ef439[_0x727f('0x37')]=qs[_0x727f('0x38')](_0x541bb4[_0x727f('0x30')][_0x727f('0x38')]);_0x3ef439[_0x727f('0x39')]=qs['filters'](_['pick'](_0x541bb4[_0x727f('0x30')],_0xa1be9[_0x727f('0x31')]),_0xf03e05);if(_0x541bb4['query']['filter']){_0x3ef439[_0x727f('0x39')]=_[_0x727f('0x3a')](_0x3ef439[_0x727f('0x39')],{'$or':_[_0x727f('0x2c')](_0xf03e05,function(_0x522fa6){if(_0x522fa6['type']!==_0x727f('0x3b')){var _0x34af3a={};_0x34af3a[_0x522fa6[_0x727f('0x29')]]={'$like':'%'+_0x541bb4[_0x727f('0x30')][_0x727f('0x3c')]+'%'};return _0x34af3a;}})});}_0x3ef439=_[_0x727f('0x3a')]({},_0x3ef439,_0x541bb4[_0x727f('0x3d')]);var _0x4a3f03={'where':_0x3ef439[_0x727f('0x39')]};return db[_0x727f('0x2d')][_0x727f('0x1d')](_0x4a3f03)[_0x727f('0x25')](function(_0x3b9121){_0x3d72ee[_0x727f('0x1d')]=_0x3b9121;if(_0x541bb4[_0x727f('0x30')]['includeAll']){_0x3ef439[_0x727f('0x3e')]=[{'all':!![]}];}return db[_0x727f('0x2d')][_0x727f('0x3f')](_0x3ef439);})[_0x727f('0x25')](function(_0x4de4c1){_0x3d72ee[_0x727f('0x40')]=_0x4de4c1;return _0x3d72ee;})[_0x727f('0x25')](respondWithFilteredResult(_0x29442f,_0x3ef439))[_0x727f('0x41')](handleError(_0x29442f,null));};exports[_0x727f('0x42')]=function(_0xac577,_0x2623c4){var _0x1d0918={'raw':!![],'where':{'id':_0xac577['params']['id']}},_0x251364={};_0x251364[_0x727f('0x2f')]=_['keys'](db[_0x727f('0x2d')]['rawAttributes']);_0x251364[_0x727f('0x30')]=_[_0x727f('0x43')](_0xac577[_0x727f('0x30')]);_0x251364[_0x727f('0x31')]=_[_0x727f('0x32')](_0x251364[_0x727f('0x2f')],_0x251364[_0x727f('0x30')]);_0x1d0918['attributes']=_['intersection'](_0x251364['model'],qs['fields'](_0xac577[_0x727f('0x30')][_0x727f('0x34')]));_0x1d0918['attributes']=_0x1d0918[_0x727f('0x33')][_0x727f('0x35')]?_0x1d0918[_0x727f('0x33')]:_0x251364[_0x727f('0x2f')];if(_0xac577[_0x727f('0x30')]['includeAll']){_0x1d0918[_0x727f('0x3e')]=[{'all':!![]}];}_0x1d0918=_[_0x727f('0x3a')]({},_0x1d0918,_0xac577['options']);return db[_0x727f('0x2d')][_0x727f('0x44')](_0x1d0918)['then'](handleEntityNotFound(_0x2623c4,null))[_0x727f('0x25')](respondWithResult(_0x2623c4,null))[_0x727f('0x41')](handleError(_0x2623c4,null));};exports[_0x727f('0x45')]=function(_0x5ef5d2,_0x2f067c){return db[_0x727f('0x2d')]['create'](_0x5ef5d2[_0x727f('0x46')],{})[_0x727f('0x25')](respondWithResult(_0x2f067c,0xc9))['catch'](handleError(_0x2f067c,null));};exports[_0x727f('0x24')]=function(_0x426813,_0x37c93d){if(_0x426813[_0x727f('0x46')]['id']){delete _0x426813[_0x727f('0x46')]['id'];}return db[_0x727f('0x2d')][_0x727f('0x44')]({'where':{'id':_0x426813[_0x727f('0x47')]['id']}})[_0x727f('0x25')](handleEntityNotFound(_0x37c93d,null))['then'](saveUpdates(_0x426813[_0x727f('0x46')],null))[_0x727f('0x25')](respondWithResult(_0x37c93d,null))[_0x727f('0x41')](handleError(_0x37c93d,null));};exports['destroy']=function(_0x498de5,_0x1f3833){return db[_0x727f('0x2d')]['find']({'where':{'id':_0x498de5[_0x727f('0x47')]['id']}})[_0x727f('0x25')](handleEntityNotFound(_0x1f3833,null))[_0x727f('0x25')](removeEntity(_0x1f3833,null))['catch'](handleError(_0x1f3833,null));};