Built motion from commit 14588770.|2.5.38
[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 _0x5620=['VIRTUAL','merge','options','SugarcrmField','include','findAll','rows','show','params','includeAll','find','catch','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','update','then','destroy','stack','send','index','map','fieldName','type','name','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter'];(function(_0x18da77,_0x3976ac){var _0x25c82b=function(_0x1a2a9f){while(--_0x1a2a9f){_0x18da77['push'](_0x18da77['shift']());}};_0x25c82b(++_0x3976ac);}(_0x5620,0xa2));var _0x0562=function(_0x4aa662,_0x1cc90c){_0x4aa662=_0x4aa662-0x0;var _0x336478=_0x5620[_0x4aa662];return _0x336478;};'use strict';var emlformat=require(_0x0562('0x0'));var rimraf=require(_0x0562('0x1'));var zipdir=require(_0x0562('0x2'));var jsonpatch=require(_0x0562('0x3'));var rp=require(_0x0562('0x4'));var moment=require(_0x0562('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x0562('0x6'));var util=require(_0x0562('0x7'));var path=require('path');var sox=require(_0x0562('0x8'));var csv=require(_0x0562('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x0562('0xa'));var _=require(_0x0562('0xb'));var squel=require(_0x0562('0xc'));var crypto=require('crypto');var jsforce=require(_0x0562('0xd'));var deskjs=require(_0x0562('0xe'));var toCsv=require(_0x0562('0x9'));var querystring=require(_0x0562('0xf'));var Papa=require(_0x0562('0x10'));var Redis=require(_0x0562('0x11'));var authService=require(_0x0562('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x0562('0x13'));var hardwareService=require(_0x0562('0x14'));var logger=require(_0x0562('0x15'))('api');var utils=require(_0x0562('0x16'));var config=require(_0x0562('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x0562('0x18'))['db'];function respondWithStatusCode(_0x131379,_0x1a380b){_0x1a380b=_0x1a380b||0xcc;return function(_0x29f71d){if(_0x29f71d){return _0x131379[_0x0562('0x19')](_0x1a380b);}return _0x131379[_0x0562('0x1a')](_0x1a380b)[_0x0562('0x1b')]();};}function respondWithResult(_0x7abdab,_0x5e5440){_0x5e5440=_0x5e5440||0xc8;return function(_0x5a7089){if(_0x5a7089){return _0x7abdab['status'](_0x5e5440)[_0x0562('0x1c')](_0x5a7089);}};}function respondWithFilteredResult(_0x4c81fd,_0x4fa890){return function(_0x248263){if(_0x248263){var _0x3009c4=typeof _0x4fa890[_0x0562('0x1d')]===_0x0562('0x1e')&&typeof _0x4fa890[_0x0562('0x1f')]===_0x0562('0x1e');var _0x3dd53e=_0x248263['count'];var _0x43a79c=_0x3009c4?0x0:_0x4fa890[_0x0562('0x1d')];var _0x3bf7c0=_0x3009c4?_0x248263[_0x0562('0x20')]:_0x4fa890[_0x0562('0x1d')]+_0x4fa890[_0x0562('0x1f')];var _0x76d82f;if(_0x3bf7c0>=_0x3dd53e){_0x3bf7c0=_0x3dd53e;_0x76d82f=0xc8;}else{_0x76d82f=0xce;}_0x4c81fd[_0x0562('0x1a')](_0x76d82f);return _0x4c81fd[_0x0562('0x21')](_0x0562('0x22'),_0x43a79c+'-'+_0x3bf7c0+'/'+_0x3dd53e)[_0x0562('0x1c')](_0x248263);}return null;};}function patchUpdates(_0x34e0e4){return function(_0x2bc974){try{jsonpatch['apply'](_0x2bc974,_0x34e0e4,!![]);}catch(_0x57f351){return BPromise[_0x0562('0x23')](_0x57f351);}return _0x2bc974['save']();};}function saveUpdates(_0x547dce,_0x4ed4f8){return function(_0x6d6c30){if(_0x6d6c30){return _0x6d6c30[_0x0562('0x24')](_0x547dce)[_0x0562('0x25')](function(_0x1b9ec7){return _0x1b9ec7;});}return null;};}function removeEntity(_0x3ee522,_0x5a6063){return function(_0x2f87ab){if(_0x2f87ab){return _0x2f87ab[_0x0562('0x26')]()[_0x0562('0x25')](function(){_0x3ee522[_0x0562('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2ecfe3,_0xc266d2){return function(_0x4c639e){if(!_0x4c639e){_0x2ecfe3[_0x0562('0x19')](0x194);}return _0x4c639e;};}function handleError(_0x403cf8,_0x201bb4){_0x201bb4=_0x201bb4||0x1f4;return function(_0x5eacf0){logger['error'](_0x5eacf0[_0x0562('0x27')]);if(_0x5eacf0['name']){delete _0x5eacf0['name'];}_0x403cf8['status'](_0x201bb4)[_0x0562('0x28')](_0x5eacf0);};}exports[_0x0562('0x29')]=function(_0x20926e,_0x429752){var _0x1ebec1={},_0x3fa3c4={},_0x115a32={'count':0x0,'rows':[]};var _0x473377=_[_0x0562('0x2a')](db['SugarcrmField']['rawAttributes'],function(_0x46217d){return{'name':_0x46217d[_0x0562('0x2b')],'type':_0x46217d[_0x0562('0x2c')]['key']};});_0x3fa3c4['model']=_[_0x0562('0x2a')](_0x473377,_0x0562('0x2d'));_0x3fa3c4[_0x0562('0x2e')]=_[_0x0562('0x2f')](_0x20926e[_0x0562('0x2e')]);_0x3fa3c4[_0x0562('0x30')]=_[_0x0562('0x31')](_0x3fa3c4[_0x0562('0x32')],_0x3fa3c4[_0x0562('0x2e')]);_0x1ebec1[_0x0562('0x33')]=_[_0x0562('0x31')](_0x3fa3c4[_0x0562('0x32')],qs[_0x0562('0x34')](_0x20926e['query'][_0x0562('0x34')]));_0x1ebec1[_0x0562('0x33')]=_0x1ebec1[_0x0562('0x33')][_0x0562('0x35')]?_0x1ebec1['attributes']:_0x3fa3c4[_0x0562('0x32')];if(!_0x20926e[_0x0562('0x2e')][_0x0562('0x36')](_0x0562('0x37'))){_0x1ebec1[_0x0562('0x1f')]=qs[_0x0562('0x1f')](_0x20926e[_0x0562('0x2e')][_0x0562('0x1f')]);_0x1ebec1[_0x0562('0x1d')]=qs['offset'](_0x20926e[_0x0562('0x2e')]['offset']);}_0x1ebec1['order']=qs[_0x0562('0x38')](_0x20926e[_0x0562('0x2e')][_0x0562('0x38')]);_0x1ebec1[_0x0562('0x39')]=qs[_0x0562('0x30')](_[_0x0562('0x3a')](_0x20926e[_0x0562('0x2e')],_0x3fa3c4[_0x0562('0x30')]),_0x473377);if(_0x20926e[_0x0562('0x2e')][_0x0562('0x3b')]){_0x1ebec1[_0x0562('0x39')]=_['merge'](_0x1ebec1[_0x0562('0x39')],{'$or':_['map'](_0x473377,function(_0x5c3727){if(_0x5c3727[_0x0562('0x2c')]!==_0x0562('0x3c')){var _0x1de521={};_0x1de521[_0x5c3727[_0x0562('0x2d')]]={'$like':'%'+_0x20926e[_0x0562('0x2e')]['filter']+'%'};return _0x1de521;}})});}_0x1ebec1=_[_0x0562('0x3d')]({},_0x1ebec1,_0x20926e[_0x0562('0x3e')]);var _0x15d3cd={'where':_0x1ebec1['where']};return db[_0x0562('0x3f')][_0x0562('0x20')](_0x15d3cd)[_0x0562('0x25')](function(_0x1c6156){_0x115a32['count']=_0x1c6156;if(_0x20926e[_0x0562('0x2e')]['includeAll']){_0x1ebec1[_0x0562('0x40')]=[{'all':!![]}];}return db[_0x0562('0x3f')][_0x0562('0x41')](_0x1ebec1);})[_0x0562('0x25')](function(_0x57c627){_0x115a32[_0x0562('0x42')]=_0x57c627;return _0x115a32;})[_0x0562('0x25')](respondWithFilteredResult(_0x429752,_0x1ebec1))['catch'](handleError(_0x429752,null));};exports[_0x0562('0x43')]=function(_0x26404b,_0x1a9158){var _0x3f2eb5={'raw':!![],'where':{'id':_0x26404b[_0x0562('0x44')]['id']}},_0x11ad3c={};_0x11ad3c[_0x0562('0x32')]=_[_0x0562('0x2f')](db[_0x0562('0x3f')]['rawAttributes']);_0x11ad3c[_0x0562('0x2e')]=_[_0x0562('0x2f')](_0x26404b[_0x0562('0x2e')]);_0x11ad3c[_0x0562('0x30')]=_[_0x0562('0x31')](_0x11ad3c[_0x0562('0x32')],_0x11ad3c[_0x0562('0x2e')]);_0x3f2eb5['attributes']=_['intersection'](_0x11ad3c[_0x0562('0x32')],qs['fields'](_0x26404b[_0x0562('0x2e')]['fields']));_0x3f2eb5[_0x0562('0x33')]=_0x3f2eb5[_0x0562('0x33')][_0x0562('0x35')]?_0x3f2eb5['attributes']:_0x11ad3c[_0x0562('0x32')];if(_0x26404b[_0x0562('0x2e')][_0x0562('0x45')]){_0x3f2eb5[_0x0562('0x40')]=[{'all':!![]}];}_0x3f2eb5=_[_0x0562('0x3d')]({},_0x3f2eb5,_0x26404b[_0x0562('0x3e')]);return db[_0x0562('0x3f')][_0x0562('0x46')](_0x3f2eb5)[_0x0562('0x25')](handleEntityNotFound(_0x1a9158,null))['then'](respondWithResult(_0x1a9158,null))[_0x0562('0x47')](handleError(_0x1a9158,null));};exports[_0x0562('0x48')]=function(_0x17a084,_0x85e574){return db[_0x0562('0x3f')]['create'](_0x17a084['body'],{})[_0x0562('0x25')](respondWithResult(_0x85e574,0xc9))[_0x0562('0x47')](handleError(_0x85e574,null));};exports[_0x0562('0x24')]=function(_0x149312,_0x3625af){if(_0x149312[_0x0562('0x49')]['id']){delete _0x149312[_0x0562('0x49')]['id'];}return db[_0x0562('0x3f')]['find']({'where':{'id':_0x149312[_0x0562('0x44')]['id']}})[_0x0562('0x25')](handleEntityNotFound(_0x3625af,null))[_0x0562('0x25')](saveUpdates(_0x149312[_0x0562('0x49')],null))['then'](respondWithResult(_0x3625af,null))['catch'](handleError(_0x3625af,null));};exports['destroy']=function(_0x135dc4,_0x1c60f5){return db['SugarcrmField']['find']({'where':{'id':_0x135dc4[_0x0562('0x44')]['id']}})[_0x0562('0x25')](handleEntityNotFound(_0x1c60f5,null))[_0x0562('0x25')](removeEntity(_0x1c60f5,null))['catch'](handleError(_0x1c60f5,null));};