90f0201bf419bd0b262fed744357589bf1b5427e
[motion2.git] / server / api / intFreshsalesField / intFreshsalesField.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 _0x6bfc=['ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','then','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','FreshsalesField','includeAll','include','rows','show','params','intersection','options','find','catch','create','body','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring'];(function(_0x2eb70f,_0x437dec){var _0x517f7e=function(_0x4a2520){while(--_0x4a2520){_0x2eb70f['push'](_0x2eb70f['shift']());}};_0x517f7e(++_0x437dec);}(_0x6bfc,0x16c));var _0xc6bf=function(_0x571559,_0x23ae55){_0x571559=_0x571559-0x0;var _0x55eec2=_0x6bfc[_0x571559];return _0x55eec2;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xc6bf('0x0'));var zipdir=require(_0xc6bf('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xc6bf('0x2'));var moment=require(_0xc6bf('0x3'));var BPromise=require(_0xc6bf('0x4'));var Mustache=require('mustache');var util=require(_0xc6bf('0x5'));var path=require(_0xc6bf('0x6'));var sox=require(_0xc6bf('0x7'));var csv=require(_0xc6bf('0x8'));var ejs=require(_0xc6bf('0x9'));var fs=require('fs');var fs_extra=require(_0xc6bf('0xa'));var _=require(_0xc6bf('0xb'));var squel=require(_0xc6bf('0xc'));var crypto=require('crypto');var jsforce=require(_0xc6bf('0xd'));var deskjs=require(_0xc6bf('0xe'));var toCsv=require(_0xc6bf('0x8'));var querystring=require(_0xc6bf('0xf'));var Papa=require('papaparse');var Redis=require(_0xc6bf('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xc6bf('0x11'));var hardwareService=require(_0xc6bf('0x12'));var logger=require(_0xc6bf('0x13'))(_0xc6bf('0x14'));var utils=require('../../config/utils');var config=require(_0xc6bf('0x15'));var licenseUtil=require(_0xc6bf('0x16'));var db=require(_0xc6bf('0x17'))['db'];function respondWithStatusCode(_0x932f63,_0x4dc8c0){_0x4dc8c0=_0x4dc8c0||0xcc;return function(_0xab33ce){if(_0xab33ce){return _0x932f63[_0xc6bf('0x18')](_0x4dc8c0);}return _0x932f63[_0xc6bf('0x19')](_0x4dc8c0)[_0xc6bf('0x1a')]();};}function respondWithResult(_0xfd469e,_0x3cca7c){_0x3cca7c=_0x3cca7c||0xc8;return function(_0x2acd12){if(_0x2acd12){return _0xfd469e[_0xc6bf('0x19')](_0x3cca7c)['json'](_0x2acd12);}};}function respondWithFilteredResult(_0x53abc8,_0x36ea66){return function(_0x4d033f){if(_0x4d033f){var _0x178303=typeof _0x36ea66[_0xc6bf('0x1b')]===_0xc6bf('0x1c')&&typeof _0x36ea66[_0xc6bf('0x1d')]===_0xc6bf('0x1c');var _0x3d74a7=_0x4d033f[_0xc6bf('0x1e')];var _0x1edffc=_0x178303?0x0:_0x36ea66['offset'];var _0x6f46b=_0x178303?_0x4d033f[_0xc6bf('0x1e')]:_0x36ea66[_0xc6bf('0x1b')]+_0x36ea66[_0xc6bf('0x1d')];var _0x51d6ac;if(_0x6f46b>=_0x3d74a7){_0x6f46b=_0x3d74a7;_0x51d6ac=0xc8;}else{_0x51d6ac=0xce;}_0x53abc8[_0xc6bf('0x19')](_0x51d6ac);return _0x53abc8[_0xc6bf('0x1f')](_0xc6bf('0x20'),_0x1edffc+'-'+_0x6f46b+'/'+_0x3d74a7)[_0xc6bf('0x21')](_0x4d033f);}return null;};}function patchUpdates(_0x2cfbaf){return function(_0xc8596c){try{jsonpatch[_0xc6bf('0x22')](_0xc8596c,_0x2cfbaf,!![]);}catch(_0x38d004){return BPromise[_0xc6bf('0x23')](_0x38d004);}return _0xc8596c[_0xc6bf('0x24')]();};}function saveUpdates(_0x593b07,_0x46091a){return function(_0x4f3c10){if(_0x4f3c10){return _0x4f3c10['update'](_0x593b07)[_0xc6bf('0x25')](function(_0x2970ce){return _0x2970ce;});}return null;};}function removeEntity(_0x20c3dc,_0x29c6e3){return function(_0x599c65){if(_0x599c65){return _0x599c65[_0xc6bf('0x26')]()['then'](function(){_0x20c3dc[_0xc6bf('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1227a7,_0x5b8f8c){return function(_0x1493db){if(!_0x1493db){_0x1227a7['sendStatus'](0x194);}return _0x1493db;};}function handleError(_0x6425d,_0x4f9502){_0x4f9502=_0x4f9502||0x1f4;return function(_0x3dba39){logger[_0xc6bf('0x27')](_0x3dba39[_0xc6bf('0x28')]);if(_0x3dba39[_0xc6bf('0x29')]){delete _0x3dba39[_0xc6bf('0x29')];}_0x6425d[_0xc6bf('0x19')](_0x4f9502)[_0xc6bf('0x2a')](_0x3dba39);};}exports[_0xc6bf('0x2b')]=function(_0x3d27b5,_0x1b65e8){var _0x41d982={},_0xf74b2c={},_0x165959={'count':0x0,'rows':[]};var _0x4baaec=_[_0xc6bf('0x2c')](db['FreshsalesField'][_0xc6bf('0x2d')],function(_0x351f71){return{'name':_0x351f71[_0xc6bf('0x2e')],'type':_0x351f71[_0xc6bf('0x2f')][_0xc6bf('0x30')]};});_0xf74b2c[_0xc6bf('0x31')]=_[_0xc6bf('0x2c')](_0x4baaec,_0xc6bf('0x29'));_0xf74b2c[_0xc6bf('0x32')]=_[_0xc6bf('0x33')](_0x3d27b5[_0xc6bf('0x32')]);_0xf74b2c[_0xc6bf('0x34')]=_['intersection'](_0xf74b2c[_0xc6bf('0x31')],_0xf74b2c[_0xc6bf('0x32')]);_0x41d982[_0xc6bf('0x35')]=_['intersection'](_0xf74b2c[_0xc6bf('0x31')],qs[_0xc6bf('0x36')](_0x3d27b5[_0xc6bf('0x32')][_0xc6bf('0x36')]));_0x41d982[_0xc6bf('0x35')]=_0x41d982[_0xc6bf('0x35')][_0xc6bf('0x37')]?_0x41d982[_0xc6bf('0x35')]:_0xf74b2c[_0xc6bf('0x31')];if(!_0x3d27b5['query']['hasOwnProperty'](_0xc6bf('0x38'))){_0x41d982[_0xc6bf('0x1d')]=qs['limit'](_0x3d27b5[_0xc6bf('0x32')][_0xc6bf('0x1d')]);_0x41d982[_0xc6bf('0x1b')]=qs[_0xc6bf('0x1b')](_0x3d27b5[_0xc6bf('0x32')][_0xc6bf('0x1b')]);}_0x41d982[_0xc6bf('0x39')]=qs['sort'](_0x3d27b5['query'][_0xc6bf('0x3a')]);_0x41d982[_0xc6bf('0x3b')]=qs[_0xc6bf('0x34')](_[_0xc6bf('0x3c')](_0x3d27b5[_0xc6bf('0x32')],_0xf74b2c['filters']),_0x4baaec);if(_0x3d27b5[_0xc6bf('0x32')][_0xc6bf('0x3d')]){_0x41d982['where']=_[_0xc6bf('0x3e')](_0x41d982['where'],{'$or':_[_0xc6bf('0x2c')](_0x4baaec,function(_0x3d88ec){if(_0x3d88ec['type']!==_0xc6bf('0x3f')){var _0x4c5b5e={};_0x4c5b5e[_0x3d88ec[_0xc6bf('0x29')]]={'$like':'%'+_0x3d27b5[_0xc6bf('0x32')][_0xc6bf('0x3d')]+'%'};return _0x4c5b5e;}})});}_0x41d982=_[_0xc6bf('0x3e')]({},_0x41d982,_0x3d27b5['options']);var _0x579e20={'where':_0x41d982[_0xc6bf('0x3b')]};return db[_0xc6bf('0x40')][_0xc6bf('0x1e')](_0x579e20)['then'](function(_0x45483b){_0x165959[_0xc6bf('0x1e')]=_0x45483b;if(_0x3d27b5['query'][_0xc6bf('0x41')]){_0x41d982[_0xc6bf('0x42')]=[{'all':!![]}];}return db[_0xc6bf('0x40')]['findAll'](_0x41d982);})[_0xc6bf('0x25')](function(_0xc5682a){_0x165959[_0xc6bf('0x43')]=_0xc5682a;return _0x165959;})[_0xc6bf('0x25')](respondWithFilteredResult(_0x1b65e8,_0x41d982))['catch'](handleError(_0x1b65e8,null));};exports[_0xc6bf('0x44')]=function(_0x17fbb8,_0x3fdb26){var _0x38ca26={'raw':!![],'where':{'id':_0x17fbb8[_0xc6bf('0x45')]['id']}},_0x23156f={};_0x23156f[_0xc6bf('0x31')]=_[_0xc6bf('0x33')](db[_0xc6bf('0x40')][_0xc6bf('0x2d')]);_0x23156f[_0xc6bf('0x32')]=_[_0xc6bf('0x33')](_0x17fbb8[_0xc6bf('0x32')]);_0x23156f[_0xc6bf('0x34')]=_['intersection'](_0x23156f['model'],_0x23156f[_0xc6bf('0x32')]);_0x38ca26[_0xc6bf('0x35')]=_[_0xc6bf('0x46')](_0x23156f[_0xc6bf('0x31')],qs[_0xc6bf('0x36')](_0x17fbb8['query'][_0xc6bf('0x36')]));_0x38ca26[_0xc6bf('0x35')]=_0x38ca26[_0xc6bf('0x35')]['length']?_0x38ca26[_0xc6bf('0x35')]:_0x23156f[_0xc6bf('0x31')];if(_0x17fbb8[_0xc6bf('0x32')][_0xc6bf('0x41')]){_0x38ca26['include']=[{'all':!![]}];}_0x38ca26=_[_0xc6bf('0x3e')]({},_0x38ca26,_0x17fbb8[_0xc6bf('0x47')]);return db[_0xc6bf('0x40')][_0xc6bf('0x48')](_0x38ca26)[_0xc6bf('0x25')](handleEntityNotFound(_0x3fdb26,null))[_0xc6bf('0x25')](respondWithResult(_0x3fdb26,null))[_0xc6bf('0x49')](handleError(_0x3fdb26,null));};exports[_0xc6bf('0x4a')]=function(_0x110a86,_0x38fcc5){return db['FreshsalesField'][_0xc6bf('0x4a')](_0x110a86['body'],{})[_0xc6bf('0x25')](respondWithResult(_0x38fcc5,0xc9))[_0xc6bf('0x49')](handleError(_0x38fcc5,null));};exports['update']=function(_0x50727b,_0x10d0cf){if(_0x50727b[_0xc6bf('0x4b')]['id']){delete _0x50727b['body']['id'];}return db[_0xc6bf('0x40')]['find']({'where':{'id':_0x50727b[_0xc6bf('0x45')]['id']}})[_0xc6bf('0x25')](handleEntityNotFound(_0x10d0cf,null))[_0xc6bf('0x25')](saveUpdates(_0x50727b[_0xc6bf('0x4b')],null))[_0xc6bf('0x25')](respondWithResult(_0x10d0cf,null))[_0xc6bf('0x49')](handleError(_0x10d0cf,null));};exports['destroy']=function(_0x446b6b,_0x26f5ee){return db[_0xc6bf('0x40')][_0xc6bf('0x48')]({'where':{'id':_0x446b6b[_0xc6bf('0x45')]['id']}})[_0xc6bf('0x25')](handleEntityNotFound(_0x26f5ee,null))[_0xc6bf('0x25')](removeEntity(_0x26f5ee,null))['catch'](handleError(_0x26f5ee,null));};