d9f13391971e4926cec3f7bb768f7553bfe540f5
[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 _0xcf03=['../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','SugarcrmField','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','params','length','find','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x465a0c,_0x19d4d5){var _0x1e202e=function(_0x27bd8a){while(--_0x27bd8a){_0x465a0c['push'](_0x465a0c['shift']());}};_0x1e202e(++_0x19d4d5);}(_0xcf03,0x11e));var _0x3cf0=function(_0x122e23,_0x58f40d){_0x122e23=_0x122e23-0x0;var _0x5a34ed=_0xcf03[_0x122e23];return _0x5a34ed;};'use strict';var pdf=require(_0x3cf0('0x0'));var emlformat=require(_0x3cf0('0x1'));var rimraf=require(_0x3cf0('0x2'));var zipdir=require(_0x3cf0('0x3'));var jsonpatch=require(_0x3cf0('0x4'));var rp=require('request-promise');var moment=require(_0x3cf0('0x5'));var BPromise=require(_0x3cf0('0x6'));var Mustache=require('mustache');var util=require(_0x3cf0('0x7'));var path=require(_0x3cf0('0x8'));var sox=require(_0x3cf0('0x9'));var csv=require(_0x3cf0('0xa'));var ejs=require(_0x3cf0('0xb'));var fs=require('fs');var _=require(_0x3cf0('0xc'));var squel=require(_0x3cf0('0xd'));var crypto=require('crypto');var jsforce=require(_0x3cf0('0xe'));var deskjs=require(_0x3cf0('0xf'));var toCsv=require('to-csv');var querystring=require(_0x3cf0('0x10'));var Papa=require('papaparse');var Redis=require(_0x3cf0('0x11'));var authService=require(_0x3cf0('0x12'));var qs=require(_0x3cf0('0x13'));var as=require(_0x3cf0('0x14'));var hardwareService=require(_0x3cf0('0x15'));var logger=require(_0x3cf0('0x16'))(_0x3cf0('0x17'));var utils=require(_0x3cf0('0x18'));var config=require(_0x3cf0('0x19'));var db=require(_0x3cf0('0x1a'))['db'];function respondWithStatusCode(_0x12c092,_0x360160){_0x360160=_0x360160||0xcc;return function(_0x471c31){if(_0x471c31){return _0x12c092[_0x3cf0('0x1b')](_0x360160);}return _0x12c092[_0x3cf0('0x1c')](_0x360160)[_0x3cf0('0x1d')]();};}function respondWithResult(_0x405f89,_0x18e904){_0x18e904=_0x18e904||0xc8;return function(_0x2ff148){if(_0x2ff148){return _0x405f89[_0x3cf0('0x1c')](_0x18e904)[_0x3cf0('0x1e')](_0x2ff148);}};}function respondWithFilteredResult(_0x34cbbb,_0x52f126){return function(_0x4ccf78){if(_0x4ccf78){var _0x8410cd=_0x4ccf78['count'],_0x428d00=_0x52f126['offset'],_0x10ae3b=_0x52f126[_0x3cf0('0x1f')]+_0x52f126[_0x3cf0('0x20')],_0x4d2480;if(_0x10ae3b>=_0x8410cd){_0x10ae3b=_0x8410cd;_0x4d2480=0xc8;}else{_0x4d2480=0xce;}_0x34cbbb[_0x3cf0('0x1c')](_0x4d2480);return _0x34cbbb['set']('Content-Range',_0x428d00+'-'+_0x10ae3b+'/'+_0x8410cd)['json'](_0x4ccf78);}return null;};}function patchUpdates(_0x29382e){return function(_0x59210b){try{jsonpatch[_0x3cf0('0x21')](_0x59210b,_0x29382e,!![]);}catch(_0x6be89c){return BPromise[_0x3cf0('0x22')](_0x6be89c);}return _0x59210b[_0x3cf0('0x23')]();};}function saveUpdates(_0x420d16,_0x367de9){return function(_0x539bb2){if(_0x539bb2){return _0x539bb2[_0x3cf0('0x24')](_0x420d16)[_0x3cf0('0x25')](function(_0x5cd1ea){return _0x5cd1ea;});}return null;};}function removeEntity(_0x298d51,_0x1ac253){return function(_0x165948){if(_0x165948){return _0x165948[_0x3cf0('0x26')]()['then'](function(){_0x298d51[_0x3cf0('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0xd30441,_0x404987){return function(_0x4caba4){if(!_0x4caba4){_0xd30441[_0x3cf0('0x1b')](0x194);}return _0x4caba4;};}function handleError(_0x532f55,_0x475343){_0x475343=_0x475343||0x1f4;return function(_0x1f2413){logger[_0x3cf0('0x27')](_0x1f2413[_0x3cf0('0x28')]);if(_0x1f2413[_0x3cf0('0x29')]){delete _0x1f2413[_0x3cf0('0x29')];}_0x532f55[_0x3cf0('0x1c')](_0x475343)[_0x3cf0('0x2a')](_0x1f2413);};}exports[_0x3cf0('0x2b')]=function(_0x38ce9f,_0x348558){var _0x333bff={},_0x465e2a={},_0x47acc1={'count':0x0,'rows':[]};var _0x2d441f=_[_0x3cf0('0x2c')](db[_0x3cf0('0x2d')][_0x3cf0('0x2e')],function(_0x35d789){return{'name':_0x35d789[_0x3cf0('0x2f')],'type':_0x35d789[_0x3cf0('0x30')][_0x3cf0('0x31')]};});_0x465e2a[_0x3cf0('0x32')]=_[_0x3cf0('0x2c')](_0x2d441f,_0x3cf0('0x29'));_0x465e2a[_0x3cf0('0x33')]=_[_0x3cf0('0x34')](_0x38ce9f[_0x3cf0('0x33')]);_0x465e2a[_0x3cf0('0x35')]=_[_0x3cf0('0x36')](_0x465e2a[_0x3cf0('0x32')],_0x465e2a['query']);_0x333bff['attributes']=_[_0x3cf0('0x36')](_0x465e2a[_0x3cf0('0x32')],qs[_0x3cf0('0x37')](_0x38ce9f[_0x3cf0('0x33')][_0x3cf0('0x37')]));_0x333bff[_0x3cf0('0x38')]=_0x333bff[_0x3cf0('0x38')]['length']?_0x333bff['attributes']:_0x465e2a[_0x3cf0('0x32')];if(!_0x38ce9f[_0x3cf0('0x33')][_0x3cf0('0x39')]('nolimit')){_0x333bff['limit']=qs['limit'](_0x38ce9f[_0x3cf0('0x33')][_0x3cf0('0x20')]);_0x333bff[_0x3cf0('0x1f')]=qs[_0x3cf0('0x1f')](_0x38ce9f['query']['offset']);}_0x333bff[_0x3cf0('0x3a')]=qs[_0x3cf0('0x3b')](_0x38ce9f[_0x3cf0('0x33')][_0x3cf0('0x3b')]);_0x333bff[_0x3cf0('0x3c')]=qs[_0x3cf0('0x35')](_[_0x3cf0('0x3d')](_0x38ce9f[_0x3cf0('0x33')],_0x465e2a['filters']),_0x2d441f);if(_0x38ce9f[_0x3cf0('0x33')][_0x3cf0('0x3e')]){_0x333bff['where']=_[_0x3cf0('0x3f')](_0x333bff['where'],{'$or':_[_0x3cf0('0x2c')](_0x2d441f,function(_0x5a851b){if(_0x5a851b[_0x3cf0('0x30')]!==_0x3cf0('0x40')){var _0x3c52dc={};_0x3c52dc[_0x5a851b[_0x3cf0('0x29')]]={'$like':'%'+_0x38ce9f[_0x3cf0('0x33')][_0x3cf0('0x3e')]+'%'};return _0x3c52dc;}})});}_0x333bff=_['merge']({},_0x333bff,_0x38ce9f[_0x3cf0('0x41')]);var _0xa3293e={'where':_0x333bff['where']};return db[_0x3cf0('0x2d')]['count'](_0xa3293e)['then'](function(_0x2bd4d9){_0x47acc1[_0x3cf0('0x42')]=_0x2bd4d9;if(_0x38ce9f[_0x3cf0('0x33')][_0x3cf0('0x43')]){_0x333bff[_0x3cf0('0x44')]=[{'all':!![]}];}return db['SugarcrmField'][_0x3cf0('0x45')](_0x333bff);})[_0x3cf0('0x25')](function(_0x3e9f4b){_0x47acc1[_0x3cf0('0x46')]=_0x3e9f4b;return _0x47acc1;})['then'](respondWithFilteredResult(_0x348558,_0x333bff))[_0x3cf0('0x47')](handleError(_0x348558,null));};exports['show']=function(_0x100311,_0x609502){var _0x155873={'raw':!![],'where':{'id':_0x100311[_0x3cf0('0x48')]['id']}},_0x91c48c={};_0x91c48c['model']=_['keys'](db['SugarcrmField']['rawAttributes']);_0x91c48c[_0x3cf0('0x33')]=_[_0x3cf0('0x34')](_0x100311[_0x3cf0('0x33')]);_0x91c48c[_0x3cf0('0x35')]=_['intersection'](_0x91c48c[_0x3cf0('0x32')],_0x91c48c['query']);_0x155873['attributes']=_[_0x3cf0('0x36')](_0x91c48c[_0x3cf0('0x32')],qs[_0x3cf0('0x37')](_0x100311[_0x3cf0('0x33')][_0x3cf0('0x37')]));_0x155873[_0x3cf0('0x38')]=_0x155873[_0x3cf0('0x38')][_0x3cf0('0x49')]?_0x155873['attributes']:_0x91c48c[_0x3cf0('0x32')];if(_0x100311['query']['includeAll']){_0x155873['include']=[{'all':!![]}];}_0x155873=_[_0x3cf0('0x3f')]({},_0x155873,_0x100311[_0x3cf0('0x41')]);return db[_0x3cf0('0x2d')][_0x3cf0('0x4a')](_0x155873)['then'](handleEntityNotFound(_0x609502,null))[_0x3cf0('0x25')](respondWithResult(_0x609502,null))[_0x3cf0('0x47')](handleError(_0x609502,null));};exports[_0x3cf0('0x4b')]=function(_0x19944f,_0x251c74){return db[_0x3cf0('0x2d')][_0x3cf0('0x4b')](_0x19944f['body'],{})['then'](respondWithResult(_0x251c74,0xc9))[_0x3cf0('0x47')](handleError(_0x251c74,null));};exports[_0x3cf0('0x24')]=function(_0x1a59c8,_0x524978){if(_0x1a59c8[_0x3cf0('0x4c')]['id']){delete _0x1a59c8[_0x3cf0('0x4c')]['id'];}return db[_0x3cf0('0x2d')][_0x3cf0('0x4a')]({'where':{'id':_0x1a59c8[_0x3cf0('0x48')]['id']}})['then'](handleEntityNotFound(_0x524978,null))[_0x3cf0('0x25')](saveUpdates(_0x1a59c8[_0x3cf0('0x4c')],null))['then'](respondWithResult(_0x524978,null))[_0x3cf0('0x47')](handleError(_0x524978,null));};exports['destroy']=function(_0x22186c,_0x5d1625){return db['SugarcrmField']['find']({'where':{'id':_0x22186c['params']['id']}})[_0x3cf0('0x25')](handleEntityNotFound(_0x5d1625,null))['then'](removeEntity(_0x5d1625,null))['catch'](handleError(_0x5d1625,null));};