c8d6195f40923c6b0b8ae195d1968899a7403b91
[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 _0xd101=['../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','update','then','destroy','stack','name','send','index','map','type','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','limit','order','sort','filter','where','merge','options','SugarcrmField','includeAll','findAll','rows','catch','show','keys','include','find','create','body','params','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils'];(function(_0x50c0f4,_0x1dde55){var _0x574dcd=function(_0x48e6bc){while(--_0x48e6bc){_0x50c0f4['push'](_0x50c0f4['shift']());}};_0x574dcd(++_0x1dde55);}(_0xd101,0xc1));var _0x1d10=function(_0x3bebea,_0x5dcfc9){_0x3bebea=_0x3bebea-0x0;var _0x45aed7=_0xd101[_0x3bebea];return _0x45aed7;};'use strict';var pdf=require(_0x1d10('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x1d10('0x1'));var zipdir=require(_0x1d10('0x2'));var jsonpatch=require(_0x1d10('0x3'));var rp=require(_0x1d10('0x4'));var moment=require(_0x1d10('0x5'));var BPromise=require(_0x1d10('0x6'));var Mustache=require(_0x1d10('0x7'));var util=require(_0x1d10('0x8'));var path=require('path');var sox=require(_0x1d10('0x9'));var csv=require(_0x1d10('0xa'));var ejs=require(_0x1d10('0xb'));var fs=require('fs');var _=require(_0x1d10('0xc'));var squel=require(_0x1d10('0xd'));var crypto=require(_0x1d10('0xe'));var jsforce=require(_0x1d10('0xf'));var deskjs=require(_0x1d10('0x10'));var toCsv=require(_0x1d10('0xa'));var querystring=require(_0x1d10('0x11'));var Papa=require(_0x1d10('0x12'));var Redis=require(_0x1d10('0x13'));var authService=require(_0x1d10('0x14'));var qs=require(_0x1d10('0x15'));var as=require(_0x1d10('0x16'));var hardwareService=require(_0x1d10('0x17'));var logger=require(_0x1d10('0x18'))('api');var utils=require(_0x1d10('0x19'));var config=require(_0x1d10('0x1a'));var licenseUtil=require(_0x1d10('0x1b'));var db=require(_0x1d10('0x1c'))['db'];function respondWithStatusCode(_0x268506,_0x5b71d8){_0x5b71d8=_0x5b71d8||0xcc;return function(_0x3f6bd8){if(_0x3f6bd8){return _0x268506[_0x1d10('0x1d')](_0x5b71d8);}return _0x268506[_0x1d10('0x1e')](_0x5b71d8)[_0x1d10('0x1f')]();};}function respondWithResult(_0x2224ff,_0x183bc4){_0x183bc4=_0x183bc4||0xc8;return function(_0x56bc3d){if(_0x56bc3d){return _0x2224ff[_0x1d10('0x1e')](_0x183bc4)[_0x1d10('0x20')](_0x56bc3d);}};}function respondWithFilteredResult(_0x306953,_0x2ad3c0){return function(_0x4f014a){if(_0x4f014a){var _0x3aedf7=_0x4f014a[_0x1d10('0x21')],_0x3fe555=_0x2ad3c0[_0x1d10('0x22')],_0x41152c=_0x2ad3c0[_0x1d10('0x22')]+_0x2ad3c0['limit'],_0x3f2f2b;if(_0x41152c>=_0x3aedf7){_0x41152c=_0x3aedf7;_0x3f2f2b=0xc8;}else{_0x3f2f2b=0xce;}_0x306953[_0x1d10('0x1e')](_0x3f2f2b);return _0x306953[_0x1d10('0x23')](_0x1d10('0x24'),_0x3fe555+'-'+_0x41152c+'/'+_0x3aedf7)[_0x1d10('0x20')](_0x4f014a);}return null;};}function patchUpdates(_0x42e1a8){return function(_0x5e61f8){try{jsonpatch['apply'](_0x5e61f8,_0x42e1a8,!![]);}catch(_0x44a253){return BPromise['reject'](_0x44a253);}return _0x5e61f8['save']();};}function saveUpdates(_0x5774f9,_0x237b92){return function(_0x2496bc){if(_0x2496bc){return _0x2496bc[_0x1d10('0x25')](_0x5774f9)[_0x1d10('0x26')](function(_0x4ce84a){return _0x4ce84a;});}return null;};}function removeEntity(_0x5e5315,_0x140147){return function(_0x5da6cf){if(_0x5da6cf){return _0x5da6cf[_0x1d10('0x27')]()[_0x1d10('0x26')](function(){_0x5e5315[_0x1d10('0x1e')](0xcc)[_0x1d10('0x1f')]();});}};}function handleEntityNotFound(_0x127b37,_0x3601ba){return function(_0x2305c8){if(!_0x2305c8){_0x127b37[_0x1d10('0x1d')](0x194);}return _0x2305c8;};}function handleError(_0x4168e,_0x84055f){_0x84055f=_0x84055f||0x1f4;return function(_0xf1e4c8){logger['error'](_0xf1e4c8[_0x1d10('0x28')]);if(_0xf1e4c8[_0x1d10('0x29')]){delete _0xf1e4c8[_0x1d10('0x29')];}_0x4168e[_0x1d10('0x1e')](_0x84055f)[_0x1d10('0x2a')](_0xf1e4c8);};}exports[_0x1d10('0x2b')]=function(_0x38f583,_0xaa8ab6){var _0x4f7837={},_0x355e10={},_0x24eb47={'count':0x0,'rows':[]};var _0x59b5eb=_[_0x1d10('0x2c')](db['SugarcrmField']['rawAttributes'],function(_0x41b5b8){return{'name':_0x41b5b8['fieldName'],'type':_0x41b5b8[_0x1d10('0x2d')][_0x1d10('0x2e')]};});_0x355e10[_0x1d10('0x2f')]=_[_0x1d10('0x2c')](_0x59b5eb,_0x1d10('0x29'));_0x355e10[_0x1d10('0x30')]=_['keys'](_0x38f583['query']);_0x355e10[_0x1d10('0x31')]=_[_0x1d10('0x32')](_0x355e10[_0x1d10('0x2f')],_0x355e10[_0x1d10('0x30')]);_0x4f7837[_0x1d10('0x33')]=_[_0x1d10('0x32')](_0x355e10[_0x1d10('0x2f')],qs[_0x1d10('0x34')](_0x38f583[_0x1d10('0x30')][_0x1d10('0x34')]));_0x4f7837['attributes']=_0x4f7837[_0x1d10('0x33')]['length']?_0x4f7837[_0x1d10('0x33')]:_0x355e10[_0x1d10('0x2f')];if(!_0x38f583['query'][_0x1d10('0x35')]('nolimit')){_0x4f7837[_0x1d10('0x36')]=qs[_0x1d10('0x36')](_0x38f583[_0x1d10('0x30')][_0x1d10('0x36')]);_0x4f7837[_0x1d10('0x22')]=qs['offset'](_0x38f583['query'][_0x1d10('0x22')]);}_0x4f7837[_0x1d10('0x37')]=qs[_0x1d10('0x38')](_0x38f583['query']['sort']);_0x4f7837['where']=qs[_0x1d10('0x31')](_['pick'](_0x38f583[_0x1d10('0x30')],_0x355e10[_0x1d10('0x31')]),_0x59b5eb);if(_0x38f583[_0x1d10('0x30')][_0x1d10('0x39')]){_0x4f7837['where']=_['merge'](_0x4f7837[_0x1d10('0x3a')],{'$or':_[_0x1d10('0x2c')](_0x59b5eb,function(_0x1080b4){if(_0x1080b4[_0x1d10('0x2d')]!=='VIRTUAL'){var _0x41a77c={};_0x41a77c[_0x1080b4['name']]={'$like':'%'+_0x38f583[_0x1d10('0x30')][_0x1d10('0x39')]+'%'};return _0x41a77c;}})});}_0x4f7837=_[_0x1d10('0x3b')]({},_0x4f7837,_0x38f583[_0x1d10('0x3c')]);var _0x38addd={'where':_0x4f7837[_0x1d10('0x3a')]};return db[_0x1d10('0x3d')][_0x1d10('0x21')](_0x38addd)[_0x1d10('0x26')](function(_0x2d9acc){_0x24eb47[_0x1d10('0x21')]=_0x2d9acc;if(_0x38f583[_0x1d10('0x30')][_0x1d10('0x3e')]){_0x4f7837['include']=[{'all':!![]}];}return db['SugarcrmField'][_0x1d10('0x3f')](_0x4f7837);})[_0x1d10('0x26')](function(_0x3be3b0){_0x24eb47[_0x1d10('0x40')]=_0x3be3b0;return _0x24eb47;})[_0x1d10('0x26')](respondWithFilteredResult(_0xaa8ab6,_0x4f7837))[_0x1d10('0x41')](handleError(_0xaa8ab6,null));};exports[_0x1d10('0x42')]=function(_0x4ebd4a,_0x1a67e9){var _0xf1fc47={'raw':!![],'where':{'id':_0x4ebd4a['params']['id']}},_0xd8e8cc={};_0xd8e8cc[_0x1d10('0x2f')]=_[_0x1d10('0x43')](db[_0x1d10('0x3d')]['rawAttributes']);_0xd8e8cc['query']=_[_0x1d10('0x43')](_0x4ebd4a[_0x1d10('0x30')]);_0xd8e8cc[_0x1d10('0x31')]=_[_0x1d10('0x32')](_0xd8e8cc[_0x1d10('0x2f')],_0xd8e8cc[_0x1d10('0x30')]);_0xf1fc47[_0x1d10('0x33')]=_['intersection'](_0xd8e8cc[_0x1d10('0x2f')],qs[_0x1d10('0x34')](_0x4ebd4a['query'][_0x1d10('0x34')]));_0xf1fc47['attributes']=_0xf1fc47[_0x1d10('0x33')]['length']?_0xf1fc47['attributes']:_0xd8e8cc[_0x1d10('0x2f')];if(_0x4ebd4a[_0x1d10('0x30')][_0x1d10('0x3e')]){_0xf1fc47[_0x1d10('0x44')]=[{'all':!![]}];}_0xf1fc47=_[_0x1d10('0x3b')]({},_0xf1fc47,_0x4ebd4a[_0x1d10('0x3c')]);return db[_0x1d10('0x3d')][_0x1d10('0x45')](_0xf1fc47)[_0x1d10('0x26')](handleEntityNotFound(_0x1a67e9,null))['then'](respondWithResult(_0x1a67e9,null))['catch'](handleError(_0x1a67e9,null));};exports[_0x1d10('0x46')]=function(_0x38bcba,_0x121792){return db[_0x1d10('0x3d')][_0x1d10('0x46')](_0x38bcba[_0x1d10('0x47')],{})['then'](respondWithResult(_0x121792,0xc9))[_0x1d10('0x41')](handleError(_0x121792,null));};exports[_0x1d10('0x25')]=function(_0x304342,_0x31fc7b){if(_0x304342[_0x1d10('0x47')]['id']){delete _0x304342[_0x1d10('0x47')]['id'];}return db[_0x1d10('0x3d')][_0x1d10('0x45')]({'where':{'id':_0x304342[_0x1d10('0x48')]['id']}})[_0x1d10('0x26')](handleEntityNotFound(_0x31fc7b,null))[_0x1d10('0x26')](saveUpdates(_0x304342[_0x1d10('0x47')],null))[_0x1d10('0x26')](respondWithResult(_0x31fc7b,null))[_0x1d10('0x41')](handleError(_0x31fc7b,null));};exports['destroy']=function(_0x560b6f,_0x33fc18){return db['SugarcrmField']['find']({'where':{'id':_0x560b6f[_0x1d10('0x48')]['id']}})[_0x1d10('0x26')](handleEntityNotFound(_0x33fc18,null))[_0x1d10('0x26')](removeEntity(_0x33fc18,null))[_0x1d10('0x41')](handleError(_0x33fc18,null));};