228358715f985a3a3672869df03f0b4e5dbc33ca
[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 _0x5b87=['rawAttributes','find','catch','create','body','update','params','html-pdf','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','sox','squel','crypto','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','then','destroy','stack','name','send','map','FreshsalesField','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','options','includeAll','include','show'];(function(_0x47aa64,_0xfb8a07){var _0x549c7a=function(_0x266165){while(--_0x266165){_0x47aa64['push'](_0x47aa64['shift']());}};_0x549c7a(++_0xfb8a07);}(_0x5b87,0x91));var _0x75b8=function(_0x14875a,_0x2dfd58){_0x14875a=_0x14875a-0x0;var _0xbadbf8=_0x5b87[_0x14875a];return _0xbadbf8;};'use strict';var pdf=require(_0x75b8('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x75b8('0x1'));var zipdir=require(_0x75b8('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x75b8('0x3'));var moment=require(_0x75b8('0x4'));var BPromise=require(_0x75b8('0x5'));var Mustache=require(_0x75b8('0x6'));var util=require('util');var path=require(_0x75b8('0x7'));var sox=require(_0x75b8('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x75b8('0x9'));var crypto=require(_0x75b8('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x75b8('0xb'));var querystring=require(_0x75b8('0xc'));var Papa=require(_0x75b8('0xd'));var Redis=require(_0x75b8('0xe'));var authService=require(_0x75b8('0xf'));var qs=require(_0x75b8('0x10'));var as=require(_0x75b8('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x75b8('0x12'))(_0x75b8('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x75b8('0x14'))['db'];function respondWithStatusCode(_0x46259e,_0x52a43c){_0x52a43c=_0x52a43c||0xcc;return function(_0x172345){if(_0x172345){return _0x46259e[_0x75b8('0x15')](_0x52a43c);}return _0x46259e[_0x75b8('0x16')](_0x52a43c)[_0x75b8('0x17')]();};}function respondWithResult(_0x3fc58f,_0xf6ef5e){_0xf6ef5e=_0xf6ef5e||0xc8;return function(_0x112354){if(_0x112354){return _0x3fc58f[_0x75b8('0x16')](_0xf6ef5e)[_0x75b8('0x18')](_0x112354);}};}function respondWithFilteredResult(_0x202f62,_0x5dd037){return function(_0x297f08){if(_0x297f08){var _0x11faae=_0x297f08[_0x75b8('0x19')],_0x597600=_0x5dd037[_0x75b8('0x1a')],_0x3cbeca=_0x5dd037[_0x75b8('0x1a')]+_0x5dd037[_0x75b8('0x1b')],_0x50cdb1;if(_0x3cbeca>=_0x11faae){_0x3cbeca=_0x11faae;_0x50cdb1=0xc8;}else{_0x50cdb1=0xce;}_0x202f62[_0x75b8('0x16')](_0x50cdb1);return _0x202f62[_0x75b8('0x1c')](_0x75b8('0x1d'),_0x597600+'-'+_0x3cbeca+'/'+_0x11faae)[_0x75b8('0x18')](_0x297f08);}return null;};}function patchUpdates(_0x1bc8fd){return function(_0xf71875){try{jsonpatch[_0x75b8('0x1e')](_0xf71875,_0x1bc8fd,!![]);}catch(_0x2d1ac8){return BPromise[_0x75b8('0x1f')](_0x2d1ac8);}return _0xf71875[_0x75b8('0x20')]();};}function saveUpdates(_0x194624,_0x17f826){return function(_0x52bad6){if(_0x52bad6){return _0x52bad6['update'](_0x194624)[_0x75b8('0x21')](function(_0x31fba1){return _0x31fba1;});}return null;};}function removeEntity(_0x204aeb,_0x436812){return function(_0x5ec7e4){if(_0x5ec7e4){return _0x5ec7e4[_0x75b8('0x22')]()[_0x75b8('0x21')](function(){_0x204aeb[_0x75b8('0x16')](0xcc)[_0x75b8('0x17')]();});}};}function handleEntityNotFound(_0x19a6ea,_0x107638){return function(_0xe4fbf4){if(!_0xe4fbf4){_0x19a6ea[_0x75b8('0x15')](0x194);}return _0xe4fbf4;};}function handleError(_0x3bd94b,_0x368067){_0x368067=_0x368067||0x1f4;return function(_0x448d1e){logger['error'](_0x448d1e[_0x75b8('0x23')]);if(_0x448d1e[_0x75b8('0x24')]){delete _0x448d1e[_0x75b8('0x24')];}_0x3bd94b['status'](_0x368067)[_0x75b8('0x25')](_0x448d1e);};}exports['index']=function(_0x376250,_0x1a07ee){var _0x59ac46={},_0x45869a={},_0x875432={'count':0x0,'rows':[]};var _0xf80cea=_[_0x75b8('0x26')](db[_0x75b8('0x27')]['rawAttributes'],function(_0x39b4bf){return{'name':_0x39b4bf[_0x75b8('0x28')],'type':_0x39b4bf[_0x75b8('0x29')][_0x75b8('0x2a')]};});_0x45869a[_0x75b8('0x2b')]=_[_0x75b8('0x26')](_0xf80cea,_0x75b8('0x24'));_0x45869a[_0x75b8('0x2c')]=_[_0x75b8('0x2d')](_0x376250[_0x75b8('0x2c')]);_0x45869a[_0x75b8('0x2e')]=_['intersection'](_0x45869a[_0x75b8('0x2b')],_0x45869a['query']);_0x59ac46[_0x75b8('0x2f')]=_[_0x75b8('0x30')](_0x45869a[_0x75b8('0x2b')],qs['fields'](_0x376250['query'][_0x75b8('0x31')]));_0x59ac46['attributes']=_0x59ac46['attributes'][_0x75b8('0x32')]?_0x59ac46['attributes']:_0x45869a[_0x75b8('0x2b')];if(!_0x376250['query'][_0x75b8('0x33')]('nolimit')){_0x59ac46['limit']=qs[_0x75b8('0x1b')](_0x376250[_0x75b8('0x2c')]['limit']);_0x59ac46[_0x75b8('0x1a')]=qs[_0x75b8('0x1a')](_0x376250[_0x75b8('0x2c')][_0x75b8('0x1a')]);}_0x59ac46[_0x75b8('0x34')]=qs[_0x75b8('0x35')](_0x376250[_0x75b8('0x2c')][_0x75b8('0x35')]);_0x59ac46[_0x75b8('0x36')]=qs['filters'](_[_0x75b8('0x37')](_0x376250[_0x75b8('0x2c')],_0x45869a[_0x75b8('0x2e')]),_0xf80cea);if(_0x376250[_0x75b8('0x2c')]['filter']){_0x59ac46['where']=_[_0x75b8('0x38')](_0x59ac46[_0x75b8('0x36')],{'$or':_[_0x75b8('0x26')](_0xf80cea,function(_0xe2bde4){if(_0xe2bde4[_0x75b8('0x29')]!==_0x75b8('0x39')){var _0x1a5061={};_0x1a5061[_0xe2bde4[_0x75b8('0x24')]]={'$like':'%'+_0x376250[_0x75b8('0x2c')]['filter']+'%'};return _0x1a5061;}})});}_0x59ac46=_[_0x75b8('0x38')]({},_0x59ac46,_0x376250[_0x75b8('0x3a')]);var _0x34ba36={'where':_0x59ac46[_0x75b8('0x36')]};return db['FreshsalesField'][_0x75b8('0x19')](_0x34ba36)['then'](function(_0x2fb6cc){_0x875432[_0x75b8('0x19')]=_0x2fb6cc;if(_0x376250[_0x75b8('0x2c')][_0x75b8('0x3b')]){_0x59ac46[_0x75b8('0x3c')]=[{'all':!![]}];}return db[_0x75b8('0x27')]['findAll'](_0x59ac46);})[_0x75b8('0x21')](function(_0x26f261){_0x875432['rows']=_0x26f261;return _0x875432;})[_0x75b8('0x21')](respondWithFilteredResult(_0x1a07ee,_0x59ac46))['catch'](handleError(_0x1a07ee,null));};exports[_0x75b8('0x3d')]=function(_0x5cc04,_0x20cec3){var _0x2fb291={'raw':!![],'where':{'id':_0x5cc04['params']['id']}},_0x2e5faf={};_0x2e5faf[_0x75b8('0x2b')]=_[_0x75b8('0x2d')](db['FreshsalesField'][_0x75b8('0x3e')]);_0x2e5faf[_0x75b8('0x2c')]=_[_0x75b8('0x2d')](_0x5cc04[_0x75b8('0x2c')]);_0x2e5faf[_0x75b8('0x2e')]=_[_0x75b8('0x30')](_0x2e5faf[_0x75b8('0x2b')],_0x2e5faf['query']);_0x2fb291['attributes']=_[_0x75b8('0x30')](_0x2e5faf[_0x75b8('0x2b')],qs[_0x75b8('0x31')](_0x5cc04[_0x75b8('0x2c')][_0x75b8('0x31')]));_0x2fb291[_0x75b8('0x2f')]=_0x2fb291[_0x75b8('0x2f')][_0x75b8('0x32')]?_0x2fb291[_0x75b8('0x2f')]:_0x2e5faf[_0x75b8('0x2b')];if(_0x5cc04['query']['includeAll']){_0x2fb291['include']=[{'all':!![]}];}_0x2fb291=_[_0x75b8('0x38')]({},_0x2fb291,_0x5cc04['options']);return db[_0x75b8('0x27')][_0x75b8('0x3f')](_0x2fb291)['then'](handleEntityNotFound(_0x20cec3,null))[_0x75b8('0x21')](respondWithResult(_0x20cec3,null))[_0x75b8('0x40')](handleError(_0x20cec3,null));};exports['create']=function(_0x4e14fa,_0x470670){return db[_0x75b8('0x27')][_0x75b8('0x41')](_0x4e14fa[_0x75b8('0x42')],{})[_0x75b8('0x21')](respondWithResult(_0x470670,0xc9))['catch'](handleError(_0x470670,null));};exports[_0x75b8('0x43')]=function(_0x5a5d10,_0xefa58b){if(_0x5a5d10[_0x75b8('0x42')]['id']){delete _0x5a5d10[_0x75b8('0x42')]['id'];}return db[_0x75b8('0x27')][_0x75b8('0x3f')]({'where':{'id':_0x5a5d10[_0x75b8('0x44')]['id']}})[_0x75b8('0x21')](handleEntityNotFound(_0xefa58b,null))[_0x75b8('0x21')](saveUpdates(_0x5a5d10[_0x75b8('0x42')],null))['then'](respondWithResult(_0xefa58b,null))[_0x75b8('0x40')](handleError(_0xefa58b,null));};exports[_0x75b8('0x22')]=function(_0x190005,_0x22d317){return db[_0x75b8('0x27')]['find']({'where':{'id':_0x190005[_0x75b8('0x44')]['id']}})[_0x75b8('0x21')](handleEntityNotFound(_0x22d317,null))[_0x75b8('0x21')](removeEntity(_0x22d317,null))['catch'](handleError(_0x22d317,null));};