94e079fbb242fa3047c612856f3c35723ea75c8b
[motion2.git] / server / api / intFreshdeskField / intFreshdeskField.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 _0x75cf=['../../config/license/util','../../mysqldb','sendStatus','end','status','json','count','offset','Content-Range','apply','save','update','then','destroy','error','stack','name','send','index','map','FreshdeskField','rawAttributes','fieldName','type','query','keys','intersection','model','fields','attributes','length','nolimit','limit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','catch','show','params','includeAll','find','create','body','html-pdf','eml-format','zip-dir','fast-json-patch','moment','util','path','sox','ejs','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils'];(function(_0x4aa082,_0x30ed5d){var _0x89703f=function(_0x500d5a){while(--_0x500d5a){_0x4aa082['push'](_0x4aa082['shift']());}};_0x89703f(++_0x30ed5d);}(_0x75cf,0x18a));var _0xf75c=function(_0x56da19,_0x1390d5){_0x56da19=_0x56da19-0x0;var _0x5dbe49=_0x75cf[_0x56da19];return _0x5dbe49;};'use strict';var pdf=require(_0xf75c('0x0'));var emlformat=require(_0xf75c('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xf75c('0x2'));var jsonpatch=require(_0xf75c('0x3'));var rp=require('request-promise');var moment=require(_0xf75c('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf75c('0x5'));var path=require(_0xf75c('0x6'));var sox=require(_0xf75c('0x7'));var csv=require('to-csv');var ejs=require(_0xf75c('0x8'));var fs=require('fs');var _=require(_0xf75c('0x9'));var squel=require(_0xf75c('0xa'));var crypto=require(_0xf75c('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf75c('0xc'));var toCsv=require(_0xf75c('0xd'));var querystring=require(_0xf75c('0xe'));var Papa=require(_0xf75c('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xf75c('0x10'));var as=require(_0xf75c('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf75c('0x12'));var utils=require(_0xf75c('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0xf75c('0x14'));var db=require(_0xf75c('0x15'))['db'];function respondWithStatusCode(_0x441bc6,_0x4d6b33){_0x4d6b33=_0x4d6b33||0xcc;return function(_0xdf9aa5){if(_0xdf9aa5){return _0x441bc6[_0xf75c('0x16')](_0x4d6b33);}return _0x441bc6['status'](_0x4d6b33)[_0xf75c('0x17')]();};}function respondWithResult(_0x4f2909,_0x20dec0){_0x20dec0=_0x20dec0||0xc8;return function(_0x30df09){if(_0x30df09){return _0x4f2909[_0xf75c('0x18')](_0x20dec0)[_0xf75c('0x19')](_0x30df09);}};}function respondWithFilteredResult(_0x3e753d,_0x427809){return function(_0xae2398){if(_0xae2398){var _0x4071c6=_0xae2398[_0xf75c('0x1a')],_0x11d98f=_0x427809[_0xf75c('0x1b')],_0x5a13d6=_0x427809[_0xf75c('0x1b')]+_0x427809['limit'],_0x671055;if(_0x5a13d6>=_0x4071c6){_0x5a13d6=_0x4071c6;_0x671055=0xc8;}else{_0x671055=0xce;}_0x3e753d[_0xf75c('0x18')](_0x671055);return _0x3e753d['set'](_0xf75c('0x1c'),_0x11d98f+'-'+_0x5a13d6+'/'+_0x4071c6)[_0xf75c('0x19')](_0xae2398);}return null;};}function patchUpdates(_0x43df5e){return function(_0x36de1b){try{jsonpatch[_0xf75c('0x1d')](_0x36de1b,_0x43df5e,!![]);}catch(_0xed4bc1){return BPromise['reject'](_0xed4bc1);}return _0x36de1b[_0xf75c('0x1e')]();};}function saveUpdates(_0x1c61d9,_0x57496b){return function(_0x16ca37){if(_0x16ca37){return _0x16ca37[_0xf75c('0x1f')](_0x1c61d9)[_0xf75c('0x20')](function(_0x49af47){return _0x49af47;});}return null;};}function removeEntity(_0x1dfe0b,_0x2954e8){return function(_0x13eb28){if(_0x13eb28){return _0x13eb28[_0xf75c('0x21')]()[_0xf75c('0x20')](function(){_0x1dfe0b[_0xf75c('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1ef226,_0x3119db){return function(_0xe9b56b){if(!_0xe9b56b){_0x1ef226[_0xf75c('0x16')](0x194);}return _0xe9b56b;};}function handleError(_0x13d29a,_0xa712c1){_0xa712c1=_0xa712c1||0x1f4;return function(_0x39105f){logger[_0xf75c('0x22')](_0x39105f[_0xf75c('0x23')]);if(_0x39105f[_0xf75c('0x24')]){delete _0x39105f[_0xf75c('0x24')];}_0x13d29a[_0xf75c('0x18')](_0xa712c1)[_0xf75c('0x25')](_0x39105f);};}exports[_0xf75c('0x26')]=function(_0x524c80,_0x2f0c09){var _0x5d5d42={},_0x38a3bb={},_0x1c60e2={'count':0x0,'rows':[]};var _0xbd389c=_[_0xf75c('0x27')](db[_0xf75c('0x28')][_0xf75c('0x29')],function(_0x1e8a7a){return{'name':_0x1e8a7a[_0xf75c('0x2a')],'type':_0x1e8a7a[_0xf75c('0x2b')]['key']};});_0x38a3bb['model']=_[_0xf75c('0x27')](_0xbd389c,_0xf75c('0x24'));_0x38a3bb[_0xf75c('0x2c')]=_[_0xf75c('0x2d')](_0x524c80[_0xf75c('0x2c')]);_0x38a3bb['filters']=_[_0xf75c('0x2e')](_0x38a3bb[_0xf75c('0x2f')],_0x38a3bb['query']);_0x5d5d42['attributes']=_[_0xf75c('0x2e')](_0x38a3bb[_0xf75c('0x2f')],qs[_0xf75c('0x30')](_0x524c80[_0xf75c('0x2c')][_0xf75c('0x30')]));_0x5d5d42[_0xf75c('0x31')]=_0x5d5d42['attributes'][_0xf75c('0x32')]?_0x5d5d42[_0xf75c('0x31')]:_0x38a3bb[_0xf75c('0x2f')];if(!_0x524c80[_0xf75c('0x2c')]['hasOwnProperty'](_0xf75c('0x33'))){_0x5d5d42[_0xf75c('0x34')]=qs[_0xf75c('0x34')](_0x524c80['query'][_0xf75c('0x34')]);_0x5d5d42[_0xf75c('0x1b')]=qs[_0xf75c('0x1b')](_0x524c80[_0xf75c('0x2c')][_0xf75c('0x1b')]);}_0x5d5d42[_0xf75c('0x35')]=qs[_0xf75c('0x36')](_0x524c80[_0xf75c('0x2c')][_0xf75c('0x36')]);_0x5d5d42[_0xf75c('0x37')]=qs['filters'](_[_0xf75c('0x38')](_0x524c80[_0xf75c('0x2c')],_0x38a3bb[_0xf75c('0x39')]),_0xbd389c);if(_0x524c80[_0xf75c('0x2c')][_0xf75c('0x3a')]){_0x5d5d42[_0xf75c('0x37')]=_[_0xf75c('0x3b')](_0x5d5d42[_0xf75c('0x37')],{'$or':_[_0xf75c('0x27')](_0xbd389c,function(_0x549bf5){if(_0x549bf5[_0xf75c('0x2b')]!==_0xf75c('0x3c')){var _0x125bc0={};_0x125bc0[_0x549bf5[_0xf75c('0x24')]]={'$like':'%'+_0x524c80['query'][_0xf75c('0x3a')]+'%'};return _0x125bc0;}})});}_0x5d5d42=_[_0xf75c('0x3b')]({},_0x5d5d42,_0x524c80[_0xf75c('0x3d')]);var _0x574b18={'where':_0x5d5d42[_0xf75c('0x37')]};return db[_0xf75c('0x28')]['count'](_0x574b18)['then'](function(_0x1f9553){_0x1c60e2[_0xf75c('0x1a')]=_0x1f9553;if(_0x524c80[_0xf75c('0x2c')]['includeAll']){_0x5d5d42['include']=[{'all':!![]}];}return db[_0xf75c('0x28')]['findAll'](_0x5d5d42);})[_0xf75c('0x20')](function(_0x5d00f1){_0x1c60e2['rows']=_0x5d00f1;return _0x1c60e2;})[_0xf75c('0x20')](respondWithFilteredResult(_0x2f0c09,_0x5d5d42))[_0xf75c('0x3e')](handleError(_0x2f0c09,null));};exports[_0xf75c('0x3f')]=function(_0x2d5335,_0x2d4dc6){var _0x2191cd={'raw':!![],'where':{'id':_0x2d5335[_0xf75c('0x40')]['id']}},_0x365365={};_0x365365[_0xf75c('0x2f')]=_[_0xf75c('0x2d')](db['FreshdeskField'][_0xf75c('0x29')]);_0x365365[_0xf75c('0x2c')]=_[_0xf75c('0x2d')](_0x2d5335['query']);_0x365365[_0xf75c('0x39')]=_[_0xf75c('0x2e')](_0x365365[_0xf75c('0x2f')],_0x365365[_0xf75c('0x2c')]);_0x2191cd[_0xf75c('0x31')]=_['intersection'](_0x365365[_0xf75c('0x2f')],qs['fields'](_0x2d5335[_0xf75c('0x2c')][_0xf75c('0x30')]));_0x2191cd[_0xf75c('0x31')]=_0x2191cd[_0xf75c('0x31')]['length']?_0x2191cd[_0xf75c('0x31')]:_0x365365[_0xf75c('0x2f')];if(_0x2d5335[_0xf75c('0x2c')][_0xf75c('0x41')]){_0x2191cd['include']=[{'all':!![]}];}_0x2191cd=_[_0xf75c('0x3b')]({},_0x2191cd,_0x2d5335[_0xf75c('0x3d')]);return db[_0xf75c('0x28')][_0xf75c('0x42')](_0x2191cd)[_0xf75c('0x20')](handleEntityNotFound(_0x2d4dc6,null))[_0xf75c('0x20')](respondWithResult(_0x2d4dc6,null))['catch'](handleError(_0x2d4dc6,null));};exports[_0xf75c('0x43')]=function(_0x650800,_0x59eb91){return db['FreshdeskField']['create'](_0x650800[_0xf75c('0x44')],{})[_0xf75c('0x20')](respondWithResult(_0x59eb91,0xc9))[_0xf75c('0x3e')](handleError(_0x59eb91,null));};exports[_0xf75c('0x1f')]=function(_0x5361b3,_0x56c867){if(_0x5361b3[_0xf75c('0x44')]['id']){delete _0x5361b3[_0xf75c('0x44')]['id'];}return db[_0xf75c('0x28')]['find']({'where':{'id':_0x5361b3[_0xf75c('0x40')]['id']}})['then'](handleEntityNotFound(_0x56c867,null))['then'](saveUpdates(_0x5361b3[_0xf75c('0x44')],null))[_0xf75c('0x20')](respondWithResult(_0x56c867,null))[_0xf75c('0x3e')](handleError(_0x56c867,null));};exports[_0xf75c('0x21')]=function(_0x301575,_0x54a718){return db[_0xf75c('0x28')][_0xf75c('0x42')]({'where':{'id':_0x301575['params']['id']}})[_0xf75c('0x20')](handleEntityNotFound(_0x54a718,null))['then'](removeEntity(_0x54a718,null))[_0xf75c('0x3e')](handleError(_0x54a718,null));};