Built motion from commit (unavailable).|2.5.6
[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 _0x3eea=['FreshdeskField','includeAll','include','findAll','rows','catch','show','params','rawAttributes','fields','find','create','body','update','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','squel','jsforce','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','end','json','count','offset','limit','status','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','send','index','type','key','model','map','query','keys','filters','intersection','attributes','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options'];(function(_0x50a267,_0x6fa593){var _0x105525=function(_0x423187){while(--_0x423187){_0x50a267['push'](_0x50a267['shift']());}};_0x105525(++_0x6fa593);}(_0x3eea,0x1ca));var _0xa3ee=function(_0x5efba9,_0x5e5921){_0x5efba9=_0x5efba9-0x0;var _0x14d9c5=_0x3eea[_0x5efba9];return _0x14d9c5;};'use strict';var pdf=require(_0xa3ee('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xa3ee('0x1'));var zipdir=require(_0xa3ee('0x2'));var jsonpatch=require(_0xa3ee('0x3'));var rp=require(_0xa3ee('0x4'));var moment=require(_0xa3ee('0x5'));var BPromise=require(_0xa3ee('0x6'));var Mustache=require(_0xa3ee('0x7'));var util=require(_0xa3ee('0x8'));var path=require(_0xa3ee('0x9'));var sox=require(_0xa3ee('0xa'));var csv=require(_0xa3ee('0xb'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xa3ee('0xc'));var crypto=require('crypto');var jsforce=require(_0xa3ee('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xa3ee('0xb'));var querystring=require('querystring');var Papa=require(_0xa3ee('0xe'));var Redis=require('ioredis');var authService=require(_0xa3ee('0xf'));var qs=require(_0xa3ee('0x10'));var as=require(_0xa3ee('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xa3ee('0x12'))(_0xa3ee('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xa3ee('0x14'));var db=require(_0xa3ee('0x15'))['db'];function respondWithStatusCode(_0x403518,_0x4363d1){_0x4363d1=_0x4363d1||0xcc;return function(_0x594c88){if(_0x594c88){return _0x403518[_0xa3ee('0x16')](_0x4363d1);}return _0x403518['status'](_0x4363d1)[_0xa3ee('0x17')]();};}function respondWithResult(_0x20535f,_0x2c34cf){_0x2c34cf=_0x2c34cf||0xc8;return function(_0x150e20){if(_0x150e20){return _0x20535f['status'](_0x2c34cf)[_0xa3ee('0x18')](_0x150e20);}};}function respondWithFilteredResult(_0x23df7d,_0x5da681){return function(_0x5358aa){if(_0x5358aa){var _0x4b2c66=_0x5358aa[_0xa3ee('0x19')],_0x40decb=_0x5da681['offset'],_0x7277cd=_0x5da681[_0xa3ee('0x1a')]+_0x5da681[_0xa3ee('0x1b')],_0x354dd5;if(_0x7277cd>=_0x4b2c66){_0x7277cd=_0x4b2c66;_0x354dd5=0xc8;}else{_0x354dd5=0xce;}_0x23df7d[_0xa3ee('0x1c')](_0x354dd5);return _0x23df7d[_0xa3ee('0x1d')](_0xa3ee('0x1e'),_0x40decb+'-'+_0x7277cd+'/'+_0x4b2c66)['json'](_0x5358aa);}return null;};}function patchUpdates(_0x377b9d){return function(_0x18b738){try{jsonpatch[_0xa3ee('0x1f')](_0x18b738,_0x377b9d,!![]);}catch(_0xad8187){return BPromise[_0xa3ee('0x20')](_0xad8187);}return _0x18b738[_0xa3ee('0x21')]();};}function saveUpdates(_0x4f8c56,_0x3f5d70){return function(_0x446971){if(_0x446971){return _0x446971['update'](_0x4f8c56)[_0xa3ee('0x22')](function(_0x4e7f32){return _0x4e7f32;});}return null;};}function removeEntity(_0x2fab5,_0x29df43){return function(_0x1d3022){if(_0x1d3022){return _0x1d3022[_0xa3ee('0x23')]()[_0xa3ee('0x22')](function(){_0x2fab5[_0xa3ee('0x1c')](0xcc)[_0xa3ee('0x17')]();});}};}function handleEntityNotFound(_0x12108e,_0x5ae0a1){return function(_0x3aa81d){if(!_0x3aa81d){_0x12108e['sendStatus'](0x194);}return _0x3aa81d;};}function handleError(_0x1998b9,_0x1dca29){_0x1dca29=_0x1dca29||0x1f4;return function(_0x157071){logger[_0xa3ee('0x24')](_0x157071[_0xa3ee('0x25')]);if(_0x157071['name']){delete _0x157071[_0xa3ee('0x26')];}_0x1998b9[_0xa3ee('0x1c')](_0x1dca29)[_0xa3ee('0x27')](_0x157071);};}exports[_0xa3ee('0x28')]=function(_0x42e97c,_0xa9e4d6){var _0x443507={},_0x30b12b={},_0xea54fe={'count':0x0,'rows':[]};var _0x298cb4=_['map'](db['FreshdeskField']['rawAttributes'],function(_0x78e581){return{'name':_0x78e581['fieldName'],'type':_0x78e581[_0xa3ee('0x29')][_0xa3ee('0x2a')]};});_0x30b12b[_0xa3ee('0x2b')]=_[_0xa3ee('0x2c')](_0x298cb4,_0xa3ee('0x26'));_0x30b12b[_0xa3ee('0x2d')]=_[_0xa3ee('0x2e')](_0x42e97c[_0xa3ee('0x2d')]);_0x30b12b[_0xa3ee('0x2f')]=_[_0xa3ee('0x30')](_0x30b12b['model'],_0x30b12b[_0xa3ee('0x2d')]);_0x443507['attributes']=_[_0xa3ee('0x30')](_0x30b12b[_0xa3ee('0x2b')],qs['fields'](_0x42e97c[_0xa3ee('0x2d')]['fields']));_0x443507[_0xa3ee('0x31')]=_0x443507['attributes'][_0xa3ee('0x32')]?_0x443507[_0xa3ee('0x31')]:_0x30b12b[_0xa3ee('0x2b')];if(!_0x42e97c[_0xa3ee('0x2d')][_0xa3ee('0x33')]('nolimit')){_0x443507[_0xa3ee('0x1b')]=qs[_0xa3ee('0x1b')](_0x42e97c[_0xa3ee('0x2d')]['limit']);_0x443507[_0xa3ee('0x1a')]=qs['offset'](_0x42e97c[_0xa3ee('0x2d')]['offset']);}_0x443507[_0xa3ee('0x34')]=qs['sort'](_0x42e97c[_0xa3ee('0x2d')][_0xa3ee('0x35')]);_0x443507[_0xa3ee('0x36')]=qs[_0xa3ee('0x2f')](_[_0xa3ee('0x37')](_0x42e97c[_0xa3ee('0x2d')],_0x30b12b[_0xa3ee('0x2f')]),_0x298cb4);if(_0x42e97c[_0xa3ee('0x2d')][_0xa3ee('0x38')]){_0x443507[_0xa3ee('0x36')]=_[_0xa3ee('0x39')](_0x443507[_0xa3ee('0x36')],{'$or':_[_0xa3ee('0x2c')](_0x298cb4,function(_0x595b55){if(_0x595b55[_0xa3ee('0x29')]!==_0xa3ee('0x3a')){var _0x2aec25={};_0x2aec25[_0x595b55[_0xa3ee('0x26')]]={'$like':'%'+_0x42e97c['query'][_0xa3ee('0x38')]+'%'};return _0x2aec25;}})});}_0x443507=_[_0xa3ee('0x39')]({},_0x443507,_0x42e97c[_0xa3ee('0x3b')]);var _0x5b95e3={'where':_0x443507[_0xa3ee('0x36')]};return db[_0xa3ee('0x3c')]['count'](_0x5b95e3)[_0xa3ee('0x22')](function(_0x3ecbe6){_0xea54fe['count']=_0x3ecbe6;if(_0x42e97c[_0xa3ee('0x2d')][_0xa3ee('0x3d')]){_0x443507[_0xa3ee('0x3e')]=[{'all':!![]}];}return db[_0xa3ee('0x3c')][_0xa3ee('0x3f')](_0x443507);})[_0xa3ee('0x22')](function(_0x2ca04f){_0xea54fe[_0xa3ee('0x40')]=_0x2ca04f;return _0xea54fe;})[_0xa3ee('0x22')](respondWithFilteredResult(_0xa9e4d6,_0x443507))[_0xa3ee('0x41')](handleError(_0xa9e4d6,null));};exports[_0xa3ee('0x42')]=function(_0x549d74,_0x5aa4b3){var _0x548534={'raw':!![],'where':{'id':_0x549d74[_0xa3ee('0x43')]['id']}},_0x45aeec={};_0x45aeec['model']=_[_0xa3ee('0x2e')](db[_0xa3ee('0x3c')][_0xa3ee('0x44')]);_0x45aeec['query']=_[_0xa3ee('0x2e')](_0x549d74['query']);_0x45aeec[_0xa3ee('0x2f')]=_[_0xa3ee('0x30')](_0x45aeec[_0xa3ee('0x2b')],_0x45aeec[_0xa3ee('0x2d')]);_0x548534[_0xa3ee('0x31')]=_[_0xa3ee('0x30')](_0x45aeec[_0xa3ee('0x2b')],qs[_0xa3ee('0x45')](_0x549d74[_0xa3ee('0x2d')][_0xa3ee('0x45')]));_0x548534[_0xa3ee('0x31')]=_0x548534[_0xa3ee('0x31')][_0xa3ee('0x32')]?_0x548534[_0xa3ee('0x31')]:_0x45aeec[_0xa3ee('0x2b')];if(_0x549d74[_0xa3ee('0x2d')][_0xa3ee('0x3d')]){_0x548534[_0xa3ee('0x3e')]=[{'all':!![]}];}_0x548534=_['merge']({},_0x548534,_0x549d74[_0xa3ee('0x3b')]);return db[_0xa3ee('0x3c')][_0xa3ee('0x46')](_0x548534)[_0xa3ee('0x22')](handleEntityNotFound(_0x5aa4b3,null))['then'](respondWithResult(_0x5aa4b3,null))[_0xa3ee('0x41')](handleError(_0x5aa4b3,null));};exports['create']=function(_0x3d6512,_0x3679b5){return db[_0xa3ee('0x3c')][_0xa3ee('0x47')](_0x3d6512[_0xa3ee('0x48')],{})[_0xa3ee('0x22')](respondWithResult(_0x3679b5,0xc9))[_0xa3ee('0x41')](handleError(_0x3679b5,null));};exports[_0xa3ee('0x49')]=function(_0x3c3677,_0xd6160e){if(_0x3c3677['body']['id']){delete _0x3c3677[_0xa3ee('0x48')]['id'];}return db['FreshdeskField']['find']({'where':{'id':_0x3c3677[_0xa3ee('0x43')]['id']}})[_0xa3ee('0x22')](handleEntityNotFound(_0xd6160e,null))[_0xa3ee('0x22')](saveUpdates(_0x3c3677[_0xa3ee('0x48')],null))[_0xa3ee('0x22')](respondWithResult(_0xd6160e,null))[_0xa3ee('0x41')](handleError(_0xd6160e,null));};exports[_0xa3ee('0x23')]=function(_0x501dad,_0x2d67f7){return db[_0xa3ee('0x3c')]['find']({'where':{'id':_0x501dad[_0xa3ee('0x43')]['id']}})[_0xa3ee('0x22')](handleEntityNotFound(_0x2d67f7,null))[_0xa3ee('0x22')](removeEntity(_0x2d67f7,null))['catch'](handleError(_0x2d67f7,null));};