Built motion from commit (unavailable).|2.2.1
[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 _0xf561=['send','index','rawAttributes','model','keys','query','dateEnd','dateStart','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','add','day','merge','filter','map','type','VIRTUAL','field','SugarcrmField','count','includeAll','findAll','rows','catch','show','params','include','options','find','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','set','reject','update','then','error','stack','name'];(function(_0x25fa7e,_0x28e9df){var _0x32617c=function(_0x4d8b22){while(--_0x4d8b22){_0x25fa7e['push'](_0x25fa7e['shift']());}};_0x32617c(++_0x28e9df);}(_0xf561,0xc0));var _0x1f56=function(_0x1dc7c4,_0x803bb1){_0x1dc7c4=_0x1dc7c4-0x0;var _0xded053=_0xf561[_0x1dc7c4];return _0xded053;};'use strict';var pdf=require(_0x1f56('0x0'));var emlformat=require(_0x1f56('0x1'));var rimraf=require(_0x1f56('0x2'));var zipdir=require(_0x1f56('0x3'));var jsonpatch=require(_0x1f56('0x4'));var rp=require(_0x1f56('0x5'));var moment=require('moment');var BPromise=require(_0x1f56('0x6'));var Mustache=require('mustache');var util=require(_0x1f56('0x7'));var path=require('path');var sox=require(_0x1f56('0x8'));var csv=require(_0x1f56('0x9'));var ejs=require(_0x1f56('0xa'));var fs=require('fs');var _=require(_0x1f56('0xb'));var squel=require(_0x1f56('0xc'));var crypto=require(_0x1f56('0xd'));var jsforce=require(_0x1f56('0xe'));var deskjs=require(_0x1f56('0xf'));var toCsv=require(_0x1f56('0x9'));var querystring=require(_0x1f56('0x10'));var Papa=require('papaparse');var Redis=require(_0x1f56('0x11'));var qs=require(_0x1f56('0x12'));var logger=require(_0x1f56('0x13'))(_0x1f56('0x14'));var utils=require('../../config/utils');var config=require(_0x1f56('0x15'));var db=require(_0x1f56('0x16'))['db'];function respondWithStatusCode(_0x13e29f,_0x3e32aa){_0x3e32aa=_0x3e32aa||0xcc;return function(_0x12c937){if(_0x12c937){return _0x13e29f[_0x1f56('0x17')](_0x3e32aa);}return _0x13e29f[_0x1f56('0x18')](_0x3e32aa)[_0x1f56('0x19')]();};}function respondWithResult(_0x1dd00a,_0x5c44e8){_0x5c44e8=_0x5c44e8||0xc8;return function(_0x561ec9){if(_0x561ec9){return _0x1dd00a[_0x1f56('0x18')](_0x5c44e8)[_0x1f56('0x1a')](_0x561ec9);}};}function respondWithFilteredResult(_0x22ec44,_0x3b1cbb){return function(_0x53ebb2){if(_0x53ebb2){var _0x519960=_0x53ebb2['count'],_0x26772c=_0x3b1cbb['offset'],_0x13297a=_0x3b1cbb[_0x1f56('0x1b')]+_0x3b1cbb[_0x1f56('0x1c')],_0x196051;if(_0x13297a>=_0x519960){_0x13297a=_0x519960;_0x196051=0xc8;}else{_0x196051=0xce;}_0x22ec44['status'](_0x196051);return _0x22ec44[_0x1f56('0x1d')]('Content-Range',_0x26772c+'-'+_0x13297a+'/'+_0x519960)[_0x1f56('0x1a')](_0x53ebb2);}return null;};}function patchUpdates(_0x303dc8){return function(_0x501970){try{jsonpatch['apply'](_0x501970,_0x303dc8,!![]);}catch(_0x416d6b){return BPromise[_0x1f56('0x1e')](_0x416d6b);}return _0x501970['save']();};}function saveUpdates(_0xa1277e,_0x35a269){return function(_0x19a243){if(_0x19a243){return _0x19a243[_0x1f56('0x1f')](_0xa1277e)['then'](function(_0xe8907e){return _0xe8907e;});}return null;};}function removeEntity(_0x50fa4e,_0x454982){return function(_0x51202b){if(_0x51202b){return _0x51202b['destroy']()[_0x1f56('0x20')](function(){_0x50fa4e['status'](0xcc)[_0x1f56('0x19')]();});}};}function handleEntityNotFound(_0x3eb97a,_0x87169a){return function(_0x3c38f0){if(!_0x3c38f0){_0x3eb97a[_0x1f56('0x17')](0x194);}return _0x3c38f0;};}function handleError(_0x403932,_0x4626d7){_0x4626d7=_0x4626d7||0x1f4;return function(_0x10f566){logger[_0x1f56('0x21')](_0x10f566[_0x1f56('0x22')]);if(_0x10f566[_0x1f56('0x23')]){delete _0x10f566[_0x1f56('0x23')];}_0x403932[_0x1f56('0x18')](_0x4626d7)[_0x1f56('0x24')](_0x10f566);};}exports[_0x1f56('0x25')]=function(_0x3acfad,_0x4157ff){var _0x146027={},_0x3244ea={},_0x4cf450={'count':0x0,'rows':[]};var _0x2f7be2=db['SugarcrmField'][_0x1f56('0x26')];_0x3244ea[_0x1f56('0x27')]=_[_0x1f56('0x28')](_0x2f7be2);var _0xf3341d={'dateStart':_0x3acfad['query']['dateStart'],'dateEnd':_0x3acfad[_0x1f56('0x29')][_0x1f56('0x2a')]};delete _0x3acfad[_0x1f56('0x29')][_0x1f56('0x2b')];delete _0x3acfad[_0x1f56('0x29')][_0x1f56('0x2a')];_0x3244ea[_0x1f56('0x29')]=_[_0x1f56('0x28')](_0x3acfad[_0x1f56('0x29')]);_0x3244ea['filters']=_[_0x1f56('0x2c')](_0x3244ea['model'],_0x3244ea[_0x1f56('0x29')]);_0x146027[_0x1f56('0x2d')]=_['intersection'](_0x3244ea[_0x1f56('0x27')],qs['fields'](_0x3acfad['query'][_0x1f56('0x2e')]));_0x146027['attributes']=_0x146027[_0x1f56('0x2d')][_0x1f56('0x2f')]?_0x146027[_0x1f56('0x2d')]:_0x3244ea[_0x1f56('0x27')];if(!_0x3acfad[_0x1f56('0x29')][_0x1f56('0x30')](_0x1f56('0x31'))){_0x146027['limit']=qs[_0x1f56('0x1c')](_0x3acfad['query'][_0x1f56('0x1c')]);_0x146027['offset']=qs[_0x1f56('0x1b')](_0x3acfad[_0x1f56('0x29')][_0x1f56('0x1b')]);}_0x146027[_0x1f56('0x32')]=qs[_0x1f56('0x33')](_0x3acfad[_0x1f56('0x29')][_0x1f56('0x33')]);_0x146027[_0x1f56('0x34')]=qs[_0x1f56('0x35')](_[_0x1f56('0x36')](_0x3acfad['query'],_0x3244ea[_0x1f56('0x35')]));if(_0xf3341d[_0x1f56('0x2b')]){if(_0xf3341d[_0x1f56('0x2a')]){_0xf3341d[_0x1f56('0x2a')]=moment(_0xf3341d[_0x1f56('0x2a')])[_0x1f56('0x37')](0x1,_0x1f56('0x38'));}else{_0xf3341d[_0x1f56('0x2a')]=moment(_0xf3341d[_0x1f56('0x2b')])['add'](0x1,'day');}_[_0x1f56('0x39')](_0x146027[_0x1f56('0x34')],{'createdAt':{'$gte':_0xf3341d[_0x1f56('0x2b')],'$lte':_0xf3341d[_0x1f56('0x2a')]}});}if(_0x3acfad[_0x1f56('0x29')][_0x1f56('0x3a')]){_0x146027[_0x1f56('0x34')]=_[_0x1f56('0x39')](_0x146027[_0x1f56('0x34')],{'$or':_[_0x1f56('0x3b')](_0x2f7be2,function(_0x287550){if(_0x287550[_0x1f56('0x3c')]['key']!==_0x1f56('0x3d')){var _0x4fa0f2={};_0x4fa0f2[_0x287550[_0x1f56('0x3e')]]={'$like':'%'+_0x3acfad[_0x1f56('0x29')][_0x1f56('0x3a')]+'%'};return _0x4fa0f2;}})});}_0x146027=_[_0x1f56('0x39')]({},_0x146027,_0x3acfad['options']);var _0x1311ad={'where':_0x146027[_0x1f56('0x34')]};return db[_0x1f56('0x3f')][_0x1f56('0x40')](_0x1311ad)[_0x1f56('0x20')](function(_0x2052bd){_0x4cf450[_0x1f56('0x40')]=_0x2052bd;if(_0x3acfad['query'][_0x1f56('0x41')]){_0x146027['include']=[{'all':!![]}];}return db[_0x1f56('0x3f')][_0x1f56('0x42')](_0x146027);})[_0x1f56('0x20')](function(_0x32ec9d){_0x4cf450[_0x1f56('0x43')]=_0x32ec9d;return _0x4cf450;})['then'](respondWithFilteredResult(_0x4157ff,_0x146027))[_0x1f56('0x44')](handleError(_0x4157ff,null));};exports[_0x1f56('0x45')]=function(_0x280d63,_0xef17c1){var _0x44ecc7={'raw':!![],'where':{'id':_0x280d63[_0x1f56('0x46')]['id']}},_0x2d9b9b={};_0x2d9b9b['model']=_['keys'](db['SugarcrmField']['rawAttributes']);_0x2d9b9b[_0x1f56('0x29')]=_[_0x1f56('0x28')](_0x280d63[_0x1f56('0x29')]);_0x2d9b9b['filters']=_[_0x1f56('0x2c')](_0x2d9b9b[_0x1f56('0x27')],_0x2d9b9b[_0x1f56('0x29')]);_0x44ecc7[_0x1f56('0x2d')]=_[_0x1f56('0x2c')](_0x2d9b9b[_0x1f56('0x27')],qs[_0x1f56('0x2e')](_0x280d63['query'][_0x1f56('0x2e')]));_0x44ecc7[_0x1f56('0x2d')]=_0x44ecc7['attributes'][_0x1f56('0x2f')]?_0x44ecc7[_0x1f56('0x2d')]:_0x2d9b9b['model'];if(_0x280d63[_0x1f56('0x29')][_0x1f56('0x41')]){_0x44ecc7[_0x1f56('0x47')]=[{'all':!![]}];}_0x44ecc7=_[_0x1f56('0x39')]({},_0x44ecc7,_0x280d63[_0x1f56('0x48')]);return db[_0x1f56('0x3f')][_0x1f56('0x49')](_0x44ecc7)[_0x1f56('0x20')](handleEntityNotFound(_0xef17c1,null))[_0x1f56('0x20')](respondWithResult(_0xef17c1,null))[_0x1f56('0x44')](handleError(_0xef17c1,null));};exports['create']=function(_0x1a23aa,_0x4b2d96){return db['SugarcrmField'][_0x1f56('0x4a')](_0x1a23aa['body'],{})[_0x1f56('0x20')](respondWithResult(_0x4b2d96,0xc9))['catch'](handleError(_0x4b2d96,null));};exports[_0x1f56('0x1f')]=function(_0x20a918,_0xac79b4){if(_0x20a918[_0x1f56('0x4b')]['id']){delete _0x20a918['body']['id'];}return db[_0x1f56('0x3f')][_0x1f56('0x49')]({'where':{'id':_0x20a918[_0x1f56('0x46')]['id']}})[_0x1f56('0x20')](handleEntityNotFound(_0xac79b4,null))[_0x1f56('0x20')](saveUpdates(_0x20a918[_0x1f56('0x4b')],null))['then'](respondWithResult(_0xac79b4,null))[_0x1f56('0x44')](handleError(_0xac79b4,null));};exports['destroy']=function(_0x319bf0,_0x30f27a){return db['SugarcrmField'][_0x1f56('0x49')]({'where':{'id':_0x319bf0[_0x1f56('0x46')]['id']}})[_0x1f56('0x20')](handleEntityNotFound(_0x30f27a,null))[_0x1f56('0x20')](removeEntity(_0x30f27a,null))['catch'](handleError(_0x30f27a,null));};