07e9ca664e8326038e122e103b8ff9a61a82ca87
[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 _0x6c1a=['attributes','fields','length','order','where','filter','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','merge','create','body','update','find','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','jsforce','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','send','index','map','SugarcrmField','rawAttributes','fieldName','type','model','keys','query','filters','intersection'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x6c1a,0x17c));var _0xa6c1=function(_0x2d5fa5,_0x5697d5){_0x2d5fa5=_0x2d5fa5-0x0;var _0xa52f42=_0x6c1a[_0x2d5fa5];return _0xa52f42;};'use strict';var pdf=require(_0xa6c1('0x0'));var emlformat=require(_0xa6c1('0x1'));var rimraf=require(_0xa6c1('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xa6c1('0x3'));var rp=require(_0xa6c1('0x4'));var moment=require(_0xa6c1('0x5'));var BPromise=require(_0xa6c1('0x6'));var Mustache=require(_0xa6c1('0x7'));var util=require(_0xa6c1('0x8'));var path=require('path');var sox=require(_0xa6c1('0x9'));var csv=require(_0xa6c1('0xa'));var ejs=require(_0xa6c1('0xb'));var fs=require('fs');var _=require(_0xa6c1('0xc'));var squel=require(_0xa6c1('0xd'));var crypto=require('crypto');var jsforce=require(_0xa6c1('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xa6c1('0xf'));var authService=require(_0xa6c1('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xa6c1('0x11'));var hardwareService=require(_0xa6c1('0x12'));var logger=require(_0xa6c1('0x13'))(_0xa6c1('0x14'));var utils=require('../../config/utils');var config=require(_0xa6c1('0x15'));var db=require(_0xa6c1('0x16'))['db'];function respondWithStatusCode(_0x2b97c2,_0x3eb4a0){_0x3eb4a0=_0x3eb4a0||0xcc;return function(_0x16b21d){if(_0x16b21d){return _0x2b97c2[_0xa6c1('0x17')](_0x3eb4a0);}return _0x2b97c2['status'](_0x3eb4a0)[_0xa6c1('0x18')]();};}function respondWithResult(_0x4e9bbf,_0x5df73a){_0x5df73a=_0x5df73a||0xc8;return function(_0x3cc22f){if(_0x3cc22f){return _0x4e9bbf[_0xa6c1('0x19')](_0x5df73a)[_0xa6c1('0x1a')](_0x3cc22f);}};}function respondWithFilteredResult(_0x1bddf0,_0x5267eb){return function(_0x2715f5){if(_0x2715f5){var _0x1478bc=_0x2715f5[_0xa6c1('0x1b')],_0x131b42=_0x5267eb[_0xa6c1('0x1c')],_0x415391=_0x5267eb[_0xa6c1('0x1c')]+_0x5267eb[_0xa6c1('0x1d')],_0x4c51ec;if(_0x415391>=_0x1478bc){_0x415391=_0x1478bc;_0x4c51ec=0xc8;}else{_0x4c51ec=0xce;}_0x1bddf0[_0xa6c1('0x19')](_0x4c51ec);return _0x1bddf0[_0xa6c1('0x1e')](_0xa6c1('0x1f'),_0x131b42+'-'+_0x415391+'/'+_0x1478bc)[_0xa6c1('0x1a')](_0x2715f5);}return null;};}function patchUpdates(_0x32e03b){return function(_0x11b0b0){try{jsonpatch[_0xa6c1('0x20')](_0x11b0b0,_0x32e03b,!![]);}catch(_0x27c087){return BPromise[_0xa6c1('0x21')](_0x27c087);}return _0x11b0b0[_0xa6c1('0x22')]();};}function saveUpdates(_0x58ed38,_0x5ee2d2){return function(_0x4ae7e3){if(_0x4ae7e3){return _0x4ae7e3['update'](_0x58ed38)[_0xa6c1('0x23')](function(_0x1a803c){return _0x1a803c;});}return null;};}function removeEntity(_0x5cb06a,_0x2b3076){return function(_0x4eb818){if(_0x4eb818){return _0x4eb818[_0xa6c1('0x24')]()[_0xa6c1('0x23')](function(){_0x5cb06a[_0xa6c1('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3fc911,_0x193b4d){return function(_0x4d57f1){if(!_0x4d57f1){_0x3fc911[_0xa6c1('0x17')](0x194);}return _0x4d57f1;};}function handleError(_0x195aac,_0x4b8838){_0x4b8838=_0x4b8838||0x1f4;return function(_0x1e9b81){logger[_0xa6c1('0x25')](_0x1e9b81[_0xa6c1('0x26')]);if(_0x1e9b81[_0xa6c1('0x27')]){delete _0x1e9b81['name'];}_0x195aac['status'](_0x4b8838)[_0xa6c1('0x28')](_0x1e9b81);};}exports[_0xa6c1('0x29')]=function(_0x34de00,_0x3dd148){var _0x5b9f91={},_0x9d8b2a={},_0x49fa28={'count':0x0,'rows':[]};var _0xecb857=_[_0xa6c1('0x2a')](db[_0xa6c1('0x2b')][_0xa6c1('0x2c')],function(_0x335f94){return{'name':_0x335f94[_0xa6c1('0x2d')],'type':_0x335f94[_0xa6c1('0x2e')]['key']};});_0x9d8b2a[_0xa6c1('0x2f')]=_[_0xa6c1('0x2a')](_0xecb857,_0xa6c1('0x27'));_0x9d8b2a['query']=_[_0xa6c1('0x30')](_0x34de00[_0xa6c1('0x31')]);_0x9d8b2a[_0xa6c1('0x32')]=_[_0xa6c1('0x33')](_0x9d8b2a[_0xa6c1('0x2f')],_0x9d8b2a[_0xa6c1('0x31')]);_0x5b9f91[_0xa6c1('0x34')]=_[_0xa6c1('0x33')](_0x9d8b2a[_0xa6c1('0x2f')],qs[_0xa6c1('0x35')](_0x34de00[_0xa6c1('0x31')]['fields']));_0x5b9f91[_0xa6c1('0x34')]=_0x5b9f91[_0xa6c1('0x34')][_0xa6c1('0x36')]?_0x5b9f91[_0xa6c1('0x34')]:_0x9d8b2a[_0xa6c1('0x2f')];if(!_0x34de00[_0xa6c1('0x31')]['hasOwnProperty']('nolimit')){_0x5b9f91[_0xa6c1('0x1d')]=qs[_0xa6c1('0x1d')](_0x34de00[_0xa6c1('0x31')][_0xa6c1('0x1d')]);_0x5b9f91[_0xa6c1('0x1c')]=qs[_0xa6c1('0x1c')](_0x34de00[_0xa6c1('0x31')]['offset']);}_0x5b9f91[_0xa6c1('0x37')]=qs['sort'](_0x34de00[_0xa6c1('0x31')]['sort']);_0x5b9f91[_0xa6c1('0x38')]=qs['filters'](_['pick'](_0x34de00[_0xa6c1('0x31')],_0x9d8b2a[_0xa6c1('0x32')]),_0xecb857);if(_0x34de00['query'][_0xa6c1('0x39')]){_0x5b9f91[_0xa6c1('0x38')]=_['merge'](_0x5b9f91['where'],{'$or':_[_0xa6c1('0x2a')](_0xecb857,function(_0x2505c7){if(_0x2505c7[_0xa6c1('0x2e')]!==_0xa6c1('0x3a')){var _0x4ed34d={};_0x4ed34d[_0x2505c7[_0xa6c1('0x27')]]={'$like':'%'+_0x34de00['query'][_0xa6c1('0x39')]+'%'};return _0x4ed34d;}})});}_0x5b9f91=_['merge']({},_0x5b9f91,_0x34de00[_0xa6c1('0x3b')]);var _0x1aebf6={'where':_0x5b9f91['where']};return db[_0xa6c1('0x2b')][_0xa6c1('0x1b')](_0x1aebf6)[_0xa6c1('0x23')](function(_0x467d3a){_0x49fa28[_0xa6c1('0x1b')]=_0x467d3a;if(_0x34de00[_0xa6c1('0x31')][_0xa6c1('0x3c')]){_0x5b9f91[_0xa6c1('0x3d')]=[{'all':!![]}];}return db[_0xa6c1('0x2b')][_0xa6c1('0x3e')](_0x5b9f91);})['then'](function(_0x987f21){_0x49fa28[_0xa6c1('0x3f')]=_0x987f21;return _0x49fa28;})[_0xa6c1('0x23')](respondWithFilteredResult(_0x3dd148,_0x5b9f91))[_0xa6c1('0x40')](handleError(_0x3dd148,null));};exports[_0xa6c1('0x41')]=function(_0x4e84d0,_0x7b7c01){var _0x2c7047={'raw':!![],'where':{'id':_0x4e84d0[_0xa6c1('0x42')]['id']}},_0x295b7e={};_0x295b7e[_0xa6c1('0x2f')]=_[_0xa6c1('0x30')](db[_0xa6c1('0x2b')]['rawAttributes']);_0x295b7e[_0xa6c1('0x31')]=_[_0xa6c1('0x30')](_0x4e84d0['query']);_0x295b7e[_0xa6c1('0x32')]=_['intersection'](_0x295b7e[_0xa6c1('0x2f')],_0x295b7e[_0xa6c1('0x31')]);_0x2c7047[_0xa6c1('0x34')]=_[_0xa6c1('0x33')](_0x295b7e[_0xa6c1('0x2f')],qs[_0xa6c1('0x35')](_0x4e84d0['query'][_0xa6c1('0x35')]));_0x2c7047[_0xa6c1('0x34')]=_0x2c7047[_0xa6c1('0x34')]['length']?_0x2c7047['attributes']:_0x295b7e[_0xa6c1('0x2f')];if(_0x4e84d0[_0xa6c1('0x31')][_0xa6c1('0x3c')]){_0x2c7047[_0xa6c1('0x3d')]=[{'all':!![]}];}_0x2c7047=_[_0xa6c1('0x43')]({},_0x2c7047,_0x4e84d0['options']);return db[_0xa6c1('0x2b')]['find'](_0x2c7047)[_0xa6c1('0x23')](handleEntityNotFound(_0x7b7c01,null))[_0xa6c1('0x23')](respondWithResult(_0x7b7c01,null))[_0xa6c1('0x40')](handleError(_0x7b7c01,null));};exports[_0xa6c1('0x44')]=function(_0x4eb6b6,_0x1fb53b){return db[_0xa6c1('0x2b')][_0xa6c1('0x44')](_0x4eb6b6[_0xa6c1('0x45')],{})[_0xa6c1('0x23')](respondWithResult(_0x1fb53b,0xc9))[_0xa6c1('0x40')](handleError(_0x1fb53b,null));};exports[_0xa6c1('0x46')]=function(_0x499a6a,_0x10d8eb){if(_0x499a6a[_0xa6c1('0x45')]['id']){delete _0x499a6a[_0xa6c1('0x45')]['id'];}return db['SugarcrmField'][_0xa6c1('0x47')]({'where':{'id':_0x499a6a['params']['id']}})[_0xa6c1('0x23')](handleEntityNotFound(_0x10d8eb,null))[_0xa6c1('0x23')](saveUpdates(_0x499a6a[_0xa6c1('0x45')],null))['then'](respondWithResult(_0x10d8eb,null))[_0xa6c1('0x40')](handleError(_0x10d8eb,null));};exports[_0xa6c1('0x24')]=function(_0x3473b9,_0x844190){return db[_0xa6c1('0x2b')][_0xa6c1('0x47')]({'where':{'id':_0x3473b9['params']['id']}})[_0xa6c1('0x23')](handleEntityNotFound(_0x844190,null))[_0xa6c1('0x23')](removeEntity(_0x844190,null))[_0xa6c1('0x40')](handleError(_0x844190,null));};