Built motion from commit 9e1ec266.|2.6.28
[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 _0xf7f0=['papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','undefined','limit','count','offset','set','apply','reject','save','update','destroy','then','name','send','index','FreshsalesField','rawAttributes','fieldName','type','query','filters','model','intersection','fields','attributes','length','nolimit','order','sort','filter','where','merge','VIRTUAL','options','include','findAll','rows','catch','show','params','keys','includeAll','find','create','body','eml-format','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring'];(function(_0x339711,_0x29c2bb){var _0x121590=function(_0x4e62dc){while(--_0x4e62dc){_0x339711['push'](_0x339711['shift']());}};_0x121590(++_0x29c2bb);}(_0xf7f0,0x113));var _0x0f7f=function(_0x59bed0,_0xad50a5){_0x59bed0=_0x59bed0-0x0;var _0x2e5d4c=_0xf7f0[_0x59bed0];return _0x2e5d4c;};'use strict';var emlformat=require(_0x0f7f('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x0f7f('0x1'));var moment=require(_0x0f7f('0x2'));var BPromise=require(_0x0f7f('0x3'));var Mustache=require(_0x0f7f('0x4'));var util=require(_0x0f7f('0x5'));var path=require(_0x0f7f('0x6'));var sox=require(_0x0f7f('0x7'));var csv=require(_0x0f7f('0x8'));var ejs=require(_0x0f7f('0x9'));var fs=require('fs');var fs_extra=require(_0x0f7f('0xa'));var _=require(_0x0f7f('0xb'));var squel=require(_0x0f7f('0xc'));var crypto=require(_0x0f7f('0xd'));var jsforce=require(_0x0f7f('0xe'));var deskjs=require(_0x0f7f('0xf'));var toCsv=require(_0x0f7f('0x8'));var querystring=require(_0x0f7f('0x10'));var Papa=require(_0x0f7f('0x11'));var Redis=require('ioredis');var authService=require(_0x0f7f('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x0f7f('0x13'));var hardwareService=require(_0x0f7f('0x14'));var logger=require(_0x0f7f('0x15'))('api');var utils=require(_0x0f7f('0x16'));var config=require(_0x0f7f('0x17'));var licenseUtil=require(_0x0f7f('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x579c65,_0x481961){_0x481961=_0x481961||0xcc;return function(_0x413ba3){if(_0x413ba3){return _0x579c65[_0x0f7f('0x19')](_0x481961);}return _0x579c65[_0x0f7f('0x1a')](_0x481961)[_0x0f7f('0x1b')]();};}function respondWithResult(_0x36c535,_0x280464){_0x280464=_0x280464||0xc8;return function(_0x5df588){if(_0x5df588){return _0x36c535[_0x0f7f('0x1a')](_0x280464)[_0x0f7f('0x1c')](_0x5df588);}};}function respondWithFilteredResult(_0x2d612b,_0x443c73){return function(_0x3aa7cf){if(_0x3aa7cf){var _0x17d24d=typeof _0x443c73['offset']===_0x0f7f('0x1d')&&typeof _0x443c73[_0x0f7f('0x1e')]===_0x0f7f('0x1d');var _0x479050=_0x3aa7cf[_0x0f7f('0x1f')];var _0x5b8769=_0x17d24d?0x0:_0x443c73[_0x0f7f('0x20')];var _0x3604d3=_0x17d24d?_0x3aa7cf[_0x0f7f('0x1f')]:_0x443c73[_0x0f7f('0x20')]+_0x443c73[_0x0f7f('0x1e')];var _0x17e0fe;if(_0x3604d3>=_0x479050){_0x3604d3=_0x479050;_0x17e0fe=0xc8;}else{_0x17e0fe=0xce;}_0x2d612b[_0x0f7f('0x1a')](_0x17e0fe);return _0x2d612b[_0x0f7f('0x21')]('Content-Range',_0x5b8769+'-'+_0x3604d3+'/'+_0x479050)[_0x0f7f('0x1c')](_0x3aa7cf);}return null;};}function patchUpdates(_0x425392){return function(_0x21c43e){try{jsonpatch[_0x0f7f('0x22')](_0x21c43e,_0x425392,!![]);}catch(_0x284843){return BPromise[_0x0f7f('0x23')](_0x284843);}return _0x21c43e[_0x0f7f('0x24')]();};}function saveUpdates(_0x5d7023,_0x104ec0){return function(_0xc2625){if(_0xc2625){return _0xc2625[_0x0f7f('0x25')](_0x5d7023)['then'](function(_0x3d562b){return _0x3d562b;});}return null;};}function removeEntity(_0x430326,_0x5a93df){return function(_0x3ca422){if(_0x3ca422){return _0x3ca422[_0x0f7f('0x26')]()[_0x0f7f('0x27')](function(){_0x430326['status'](0xcc)[_0x0f7f('0x1b')]();});}};}function handleEntityNotFound(_0x23f034,_0x124603){return function(_0x22dab4){if(!_0x22dab4){_0x23f034[_0x0f7f('0x19')](0x194);}return _0x22dab4;};}function handleError(_0x228237,_0x27b000){_0x27b000=_0x27b000||0x1f4;return function(_0xe5b7f8){logger['error'](_0xe5b7f8['stack']);if(_0xe5b7f8[_0x0f7f('0x28')]){delete _0xe5b7f8[_0x0f7f('0x28')];}_0x228237['status'](_0x27b000)[_0x0f7f('0x29')](_0xe5b7f8);};}exports[_0x0f7f('0x2a')]=function(_0x124616,_0x5892d1){var _0x4130c3={},_0x2cbdec={},_0x143e24={'count':0x0,'rows':[]};var _0x19c813=_['map'](db[_0x0f7f('0x2b')][_0x0f7f('0x2c')],function(_0x38eea2){return{'name':_0x38eea2[_0x0f7f('0x2d')],'type':_0x38eea2[_0x0f7f('0x2e')]['key']};});_0x2cbdec['model']=_['map'](_0x19c813,'name');_0x2cbdec[_0x0f7f('0x2f')]=_['keys'](_0x124616[_0x0f7f('0x2f')]);_0x2cbdec[_0x0f7f('0x30')]=_['intersection'](_0x2cbdec[_0x0f7f('0x31')],_0x2cbdec[_0x0f7f('0x2f')]);_0x4130c3['attributes']=_[_0x0f7f('0x32')](_0x2cbdec[_0x0f7f('0x31')],qs[_0x0f7f('0x33')](_0x124616[_0x0f7f('0x2f')][_0x0f7f('0x33')]));_0x4130c3[_0x0f7f('0x34')]=_0x4130c3[_0x0f7f('0x34')][_0x0f7f('0x35')]?_0x4130c3[_0x0f7f('0x34')]:_0x2cbdec[_0x0f7f('0x31')];if(!_0x124616[_0x0f7f('0x2f')]['hasOwnProperty'](_0x0f7f('0x36'))){_0x4130c3[_0x0f7f('0x1e')]=qs[_0x0f7f('0x1e')](_0x124616[_0x0f7f('0x2f')][_0x0f7f('0x1e')]);_0x4130c3[_0x0f7f('0x20')]=qs[_0x0f7f('0x20')](_0x124616[_0x0f7f('0x2f')]['offset']);}_0x4130c3[_0x0f7f('0x37')]=qs['sort'](_0x124616[_0x0f7f('0x2f')][_0x0f7f('0x38')]);_0x4130c3['where']=qs[_0x0f7f('0x30')](_['pick'](_0x124616[_0x0f7f('0x2f')],_0x2cbdec[_0x0f7f('0x30')]),_0x19c813);if(_0x124616[_0x0f7f('0x2f')][_0x0f7f('0x39')]){_0x4130c3[_0x0f7f('0x3a')]=_[_0x0f7f('0x3b')](_0x4130c3[_0x0f7f('0x3a')],{'$or':_['map'](_0x19c813,function(_0x3f4513){if(_0x3f4513['type']!==_0x0f7f('0x3c')){var _0x24e24c={};_0x24e24c[_0x3f4513[_0x0f7f('0x28')]]={'$like':'%'+_0x124616['query']['filter']+'%'};return _0x24e24c;}})});}_0x4130c3=_[_0x0f7f('0x3b')]({},_0x4130c3,_0x124616[_0x0f7f('0x3d')]);var _0x4fb171={'where':_0x4130c3['where']};return db[_0x0f7f('0x2b')]['count'](_0x4fb171)[_0x0f7f('0x27')](function(_0x4a3746){_0x143e24[_0x0f7f('0x1f')]=_0x4a3746;if(_0x124616[_0x0f7f('0x2f')]['includeAll']){_0x4130c3[_0x0f7f('0x3e')]=[{'all':!![]}];}return db[_0x0f7f('0x2b')][_0x0f7f('0x3f')](_0x4130c3);})[_0x0f7f('0x27')](function(_0x38e211){_0x143e24[_0x0f7f('0x40')]=_0x38e211;return _0x143e24;})[_0x0f7f('0x27')](respondWithFilteredResult(_0x5892d1,_0x4130c3))[_0x0f7f('0x41')](handleError(_0x5892d1,null));};exports[_0x0f7f('0x42')]=function(_0x89bc74,_0x5c6c3a){var _0x17d8b8={'raw':!![],'where':{'id':_0x89bc74[_0x0f7f('0x43')]['id']}},_0x1f33cd={};_0x1f33cd['model']=_[_0x0f7f('0x44')](db[_0x0f7f('0x2b')][_0x0f7f('0x2c')]);_0x1f33cd[_0x0f7f('0x2f')]=_[_0x0f7f('0x44')](_0x89bc74[_0x0f7f('0x2f')]);_0x1f33cd[_0x0f7f('0x30')]=_['intersection'](_0x1f33cd[_0x0f7f('0x31')],_0x1f33cd[_0x0f7f('0x2f')]);_0x17d8b8[_0x0f7f('0x34')]=_[_0x0f7f('0x32')](_0x1f33cd[_0x0f7f('0x31')],qs[_0x0f7f('0x33')](_0x89bc74[_0x0f7f('0x2f')][_0x0f7f('0x33')]));_0x17d8b8['attributes']=_0x17d8b8[_0x0f7f('0x34')][_0x0f7f('0x35')]?_0x17d8b8['attributes']:_0x1f33cd[_0x0f7f('0x31')];if(_0x89bc74['query'][_0x0f7f('0x45')]){_0x17d8b8[_0x0f7f('0x3e')]=[{'all':!![]}];}_0x17d8b8=_[_0x0f7f('0x3b')]({},_0x17d8b8,_0x89bc74['options']);return db[_0x0f7f('0x2b')][_0x0f7f('0x46')](_0x17d8b8)[_0x0f7f('0x27')](handleEntityNotFound(_0x5c6c3a,null))[_0x0f7f('0x27')](respondWithResult(_0x5c6c3a,null))['catch'](handleError(_0x5c6c3a,null));};exports[_0x0f7f('0x47')]=function(_0x3eaa55,_0x3dd83f){return db[_0x0f7f('0x2b')]['create'](_0x3eaa55[_0x0f7f('0x48')],{})[_0x0f7f('0x27')](respondWithResult(_0x3dd83f,0xc9))[_0x0f7f('0x41')](handleError(_0x3dd83f,null));};exports[_0x0f7f('0x25')]=function(_0x7558fe,_0x2d93bf){if(_0x7558fe[_0x0f7f('0x48')]['id']){delete _0x7558fe[_0x0f7f('0x48')]['id'];}return db[_0x0f7f('0x2b')][_0x0f7f('0x46')]({'where':{'id':_0x7558fe[_0x0f7f('0x43')]['id']}})['then'](handleEntityNotFound(_0x2d93bf,null))[_0x0f7f('0x27')](saveUpdates(_0x7558fe['body'],null))[_0x0f7f('0x27')](respondWithResult(_0x2d93bf,null))['catch'](handleError(_0x2d93bf,null));};exports['destroy']=function(_0x270eb3,_0xf857da){return db[_0x0f7f('0x2b')][_0x0f7f('0x46')]({'where':{'id':_0x270eb3['params']['id']}})[_0x0f7f('0x27')](handleEntityNotFound(_0xf857da,null))[_0x0f7f('0x27')](removeEntity(_0xf857da,null))['catch'](handleError(_0xf857da,null));};