Built motion from commit (unavailable).|2.5.7
[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 _0x44f6=['model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','then','params','find','catch','create','body','html-pdf','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','apply','save','destroy','error','name','send','index','map','FreshdeskField','rawAttributes','fieldName'];(function(_0x4fc9e6,_0xc51915){var _0x551d28=function(_0x1a603b){while(--_0x1a603b){_0x4fc9e6['push'](_0x4fc9e6['shift']());}};_0x551d28(++_0xc51915);}(_0x44f6,0xa4));var _0x644f=function(_0x5627e1,_0x1b2dbf){_0x5627e1=_0x5627e1-0x0;var _0x2f013f=_0x44f6[_0x5627e1];return _0x2f013f;};'use strict';var pdf=require(_0x644f('0x0'));var emlformat=require(_0x644f('0x1'));var rimraf=require(_0x644f('0x2'));var zipdir=require(_0x644f('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x644f('0x4'));var BPromise=require(_0x644f('0x5'));var Mustache=require(_0x644f('0x6'));var util=require(_0x644f('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x644f('0x8'));var ejs=require(_0x644f('0x9'));var fs=require('fs');var _=require(_0x644f('0xa'));var squel=require(_0x644f('0xb'));var crypto=require(_0x644f('0xc'));var jsforce=require(_0x644f('0xd'));var deskjs=require(_0x644f('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x644f('0xf'));var authService=require(_0x644f('0x10'));var qs=require(_0x644f('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x644f('0x12'))(_0x644f('0x13'));var utils=require(_0x644f('0x14'));var config=require(_0x644f('0x15'));var licenseUtil=require(_0x644f('0x16'));var db=require(_0x644f('0x17'))['db'];function respondWithStatusCode(_0x5a1efc,_0x2f333b){_0x2f333b=_0x2f333b||0xcc;return function(_0x2181e0){if(_0x2181e0){return _0x5a1efc[_0x644f('0x18')](_0x2f333b);}return _0x5a1efc[_0x644f('0x19')](_0x2f333b)[_0x644f('0x1a')]();};}function respondWithResult(_0x4e2126,_0x524aa3){_0x524aa3=_0x524aa3||0xc8;return function(_0x4122b6){if(_0x4122b6){return _0x4e2126[_0x644f('0x19')](_0x524aa3)[_0x644f('0x1b')](_0x4122b6);}};}function respondWithFilteredResult(_0x38555b,_0x2c321c){return function(_0x19b638){if(_0x19b638){var _0x14ef50=_0x19b638[_0x644f('0x1c')],_0x370f4c=_0x2c321c['offset'],_0x355c94=_0x2c321c[_0x644f('0x1d')]+_0x2c321c[_0x644f('0x1e')],_0xf092a6;if(_0x355c94>=_0x14ef50){_0x355c94=_0x14ef50;_0xf092a6=0xc8;}else{_0xf092a6=0xce;}_0x38555b['status'](_0xf092a6);return _0x38555b[_0x644f('0x1f')]('Content-Range',_0x370f4c+'-'+_0x355c94+'/'+_0x14ef50)[_0x644f('0x1b')](_0x19b638);}return null;};}function patchUpdates(_0x2ad65d){return function(_0x3a3604){try{jsonpatch[_0x644f('0x20')](_0x3a3604,_0x2ad65d,!![]);}catch(_0x283c26){return BPromise['reject'](_0x283c26);}return _0x3a3604[_0x644f('0x21')]();};}function saveUpdates(_0x456a89,_0x2740b2){return function(_0x20935a){if(_0x20935a){return _0x20935a['update'](_0x456a89)['then'](function(_0x335082){return _0x335082;});}return null;};}function removeEntity(_0x3e052f,_0x1396a5){return function(_0x5a7219){if(_0x5a7219){return _0x5a7219[_0x644f('0x22')]()['then'](function(){_0x3e052f[_0x644f('0x19')](0xcc)[_0x644f('0x1a')]();});}};}function handleEntityNotFound(_0x140167,_0x2b9810){return function(_0x1217ec){if(!_0x1217ec){_0x140167[_0x644f('0x18')](0x194);}return _0x1217ec;};}function handleError(_0x57617c,_0x3e59ad){_0x3e59ad=_0x3e59ad||0x1f4;return function(_0x293592){logger[_0x644f('0x23')](_0x293592['stack']);if(_0x293592[_0x644f('0x24')]){delete _0x293592[_0x644f('0x24')];}_0x57617c[_0x644f('0x19')](_0x3e59ad)[_0x644f('0x25')](_0x293592);};}exports[_0x644f('0x26')]=function(_0x450ef5,_0x58f086){var _0x3a80dc={},_0x218bac={},_0x18baa1={'count':0x0,'rows':[]};var _0x564356=_[_0x644f('0x27')](db[_0x644f('0x28')][_0x644f('0x29')],function(_0x35c549){return{'name':_0x35c549[_0x644f('0x2a')],'type':_0x35c549['type']['key']};});_0x218bac[_0x644f('0x2b')]=_['map'](_0x564356,_0x644f('0x24'));_0x218bac[_0x644f('0x2c')]=_[_0x644f('0x2d')](_0x450ef5[_0x644f('0x2c')]);_0x218bac[_0x644f('0x2e')]=_[_0x644f('0x2f')](_0x218bac['model'],_0x218bac[_0x644f('0x2c')]);_0x3a80dc[_0x644f('0x30')]=_[_0x644f('0x2f')](_0x218bac[_0x644f('0x2b')],qs['fields'](_0x450ef5['query'][_0x644f('0x31')]));_0x3a80dc[_0x644f('0x30')]=_0x3a80dc[_0x644f('0x30')][_0x644f('0x32')]?_0x3a80dc['attributes']:_0x218bac[_0x644f('0x2b')];if(!_0x450ef5['query'][_0x644f('0x33')](_0x644f('0x34'))){_0x3a80dc[_0x644f('0x1e')]=qs[_0x644f('0x1e')](_0x450ef5[_0x644f('0x2c')][_0x644f('0x1e')]);_0x3a80dc['offset']=qs['offset'](_0x450ef5[_0x644f('0x2c')]['offset']);}_0x3a80dc['order']=qs[_0x644f('0x35')](_0x450ef5[_0x644f('0x2c')][_0x644f('0x35')]);_0x3a80dc[_0x644f('0x36')]=qs[_0x644f('0x2e')](_['pick'](_0x450ef5[_0x644f('0x2c')],_0x218bac[_0x644f('0x2e')]),_0x564356);if(_0x450ef5[_0x644f('0x2c')][_0x644f('0x37')]){_0x3a80dc[_0x644f('0x36')]=_[_0x644f('0x38')](_0x3a80dc[_0x644f('0x36')],{'$or':_[_0x644f('0x27')](_0x564356,function(_0x5e1bd0){if(_0x5e1bd0['type']!==_0x644f('0x39')){var _0x35d555={};_0x35d555[_0x5e1bd0[_0x644f('0x24')]]={'$like':'%'+_0x450ef5[_0x644f('0x2c')][_0x644f('0x37')]+'%'};return _0x35d555;}})});}_0x3a80dc=_['merge']({},_0x3a80dc,_0x450ef5[_0x644f('0x3a')]);var _0x93e74f={'where':_0x3a80dc[_0x644f('0x36')]};return db[_0x644f('0x28')][_0x644f('0x1c')](_0x93e74f)['then'](function(_0x17387d){_0x18baa1[_0x644f('0x1c')]=_0x17387d;if(_0x450ef5[_0x644f('0x2c')][_0x644f('0x3b')]){_0x3a80dc[_0x644f('0x3c')]=[{'all':!![]}];}return db[_0x644f('0x28')][_0x644f('0x3d')](_0x3a80dc);})['then'](function(_0x2367a4){_0x18baa1[_0x644f('0x3e')]=_0x2367a4;return _0x18baa1;})[_0x644f('0x3f')](respondWithFilteredResult(_0x58f086,_0x3a80dc))['catch'](handleError(_0x58f086,null));};exports['show']=function(_0x1e9e68,_0x5ab96c){var _0x40183e={'raw':!![],'where':{'id':_0x1e9e68[_0x644f('0x40')]['id']}},_0x206c72={};_0x206c72['model']=_['keys'](db[_0x644f('0x28')]['rawAttributes']);_0x206c72[_0x644f('0x2c')]=_[_0x644f('0x2d')](_0x1e9e68[_0x644f('0x2c')]);_0x206c72[_0x644f('0x2e')]=_[_0x644f('0x2f')](_0x206c72[_0x644f('0x2b')],_0x206c72[_0x644f('0x2c')]);_0x40183e[_0x644f('0x30')]=_['intersection'](_0x206c72['model'],qs['fields'](_0x1e9e68[_0x644f('0x2c')]['fields']));_0x40183e[_0x644f('0x30')]=_0x40183e[_0x644f('0x30')][_0x644f('0x32')]?_0x40183e[_0x644f('0x30')]:_0x206c72[_0x644f('0x2b')];if(_0x1e9e68['query'][_0x644f('0x3b')]){_0x40183e[_0x644f('0x3c')]=[{'all':!![]}];}_0x40183e=_[_0x644f('0x38')]({},_0x40183e,_0x1e9e68['options']);return db[_0x644f('0x28')][_0x644f('0x41')](_0x40183e)['then'](handleEntityNotFound(_0x5ab96c,null))[_0x644f('0x3f')](respondWithResult(_0x5ab96c,null))[_0x644f('0x42')](handleError(_0x5ab96c,null));};exports[_0x644f('0x43')]=function(_0x18eb6f,_0x53d081){return db[_0x644f('0x28')]['create'](_0x18eb6f[_0x644f('0x44')],{})[_0x644f('0x3f')](respondWithResult(_0x53d081,0xc9))['catch'](handleError(_0x53d081,null));};exports['update']=function(_0x59f64c,_0x53dc67){if(_0x59f64c[_0x644f('0x44')]['id']){delete _0x59f64c['body']['id'];}return db[_0x644f('0x28')]['find']({'where':{'id':_0x59f64c[_0x644f('0x40')]['id']}})[_0x644f('0x3f')](handleEntityNotFound(_0x53dc67,null))[_0x644f('0x3f')](saveUpdates(_0x59f64c['body'],null))[_0x644f('0x3f')](respondWithResult(_0x53dc67,null))[_0x644f('0x42')](handleError(_0x53dc67,null));};exports['destroy']=function(_0x52b38b,_0xb8984){return db['FreshdeskField'][_0x644f('0x41')]({'where':{'id':_0x52b38b[_0x644f('0x40')]['id']}})[_0x644f('0x3f')](handleEntityNotFound(_0xb8984,null))[_0x644f('0x3f')](removeEntity(_0xb8984,null))['catch'](handleError(_0xb8984,null));};