Built motion from commit e0fa946e.|2.6.5
[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 _0xc29b=['request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','Content-Range','apply','reject','save','update','then','destroy','name','index','map','FreshdeskField','fieldName','type','key','model','query','keys','filters','attributes','fields','length','offset','sort','where','pick','VIRTUAL','filter','options','findAll','rows','catch','show','params','rawAttributes','intersection','includeAll','include','create','body','find','eml-format','rimraf','zip-dir'];(function(_0x13abe5,_0x5c0e84){var _0x5af069=function(_0x75d306){while(--_0x75d306){_0x13abe5['push'](_0x13abe5['shift']());}};_0x5af069(++_0x5c0e84);}(_0xc29b,0x12d));var _0xbc29=function(_0x44ae24,_0x18af27){_0x44ae24=_0x44ae24-0x0;var _0x4cfb1e=_0xc29b[_0x44ae24];return _0x4cfb1e;};'use strict';var emlformat=require(_0xbc29('0x0'));var rimraf=require(_0xbc29('0x1'));var zipdir=require(_0xbc29('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xbc29('0x3'));var moment=require(_0xbc29('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xbc29('0x5'));var util=require(_0xbc29('0x6'));var path=require(_0xbc29('0x7'));var sox=require(_0xbc29('0x8'));var csv=require(_0xbc29('0x9'));var ejs=require(_0xbc29('0xa'));var fs=require('fs');var fs_extra=require(_0xbc29('0xb'));var _=require(_0xbc29('0xc'));var squel=require(_0xbc29('0xd'));var crypto=require(_0xbc29('0xe'));var jsforce=require(_0xbc29('0xf'));var deskjs=require(_0xbc29('0x10'));var toCsv=require(_0xbc29('0x9'));var querystring=require(_0xbc29('0x11'));var Papa=require(_0xbc29('0x12'));var Redis=require(_0xbc29('0x13'));var authService=require(_0xbc29('0x14'));var qs=require(_0xbc29('0x15'));var as=require(_0xbc29('0x16'));var hardwareService=require(_0xbc29('0x17'));var logger=require('../../config/logger')(_0xbc29('0x18'));var utils=require(_0xbc29('0x19'));var config=require(_0xbc29('0x1a'));var licenseUtil=require(_0xbc29('0x1b'));var db=require(_0xbc29('0x1c'))['db'];function respondWithStatusCode(_0x2794c6,_0x352c9e){_0x352c9e=_0x352c9e||0xcc;return function(_0x5e581f){if(_0x5e581f){return _0x2794c6[_0xbc29('0x1d')](_0x352c9e);}return _0x2794c6[_0xbc29('0x1e')](_0x352c9e)[_0xbc29('0x1f')]();};}function respondWithResult(_0x515ea8,_0x483fbe){_0x483fbe=_0x483fbe||0xc8;return function(_0x1892fc){if(_0x1892fc){return _0x515ea8['status'](_0x483fbe)[_0xbc29('0x20')](_0x1892fc);}};}function respondWithFilteredResult(_0x3f0264,_0x46eb03){return function(_0x490030){if(_0x490030){var _0x3b31b1=typeof _0x46eb03['offset']===_0xbc29('0x21')&&typeof _0x46eb03[_0xbc29('0x22')]===_0xbc29('0x21');var _0x1e7f15=_0x490030[_0xbc29('0x23')];var _0x42b0be=_0x3b31b1?0x0:_0x46eb03['offset'];var _0x9e84e3=_0x3b31b1?_0x490030[_0xbc29('0x23')]:_0x46eb03['offset']+_0x46eb03['limit'];var _0x30c251;if(_0x9e84e3>=_0x1e7f15){_0x9e84e3=_0x1e7f15;_0x30c251=0xc8;}else{_0x30c251=0xce;}_0x3f0264['status'](_0x30c251);return _0x3f0264['set'](_0xbc29('0x24'),_0x42b0be+'-'+_0x9e84e3+'/'+_0x1e7f15)[_0xbc29('0x20')](_0x490030);}return null;};}function patchUpdates(_0x1912ea){return function(_0x371adc){try{jsonpatch[_0xbc29('0x25')](_0x371adc,_0x1912ea,!![]);}catch(_0x3b6304){return BPromise[_0xbc29('0x26')](_0x3b6304);}return _0x371adc[_0xbc29('0x27')]();};}function saveUpdates(_0x5cdc9e,_0x115592){return function(_0x35920d){if(_0x35920d){return _0x35920d[_0xbc29('0x28')](_0x5cdc9e)[_0xbc29('0x29')](function(_0x1ae3f2){return _0x1ae3f2;});}return null;};}function removeEntity(_0x5c6f6d,_0x24523f){return function(_0x3ca9dc){if(_0x3ca9dc){return _0x3ca9dc[_0xbc29('0x2a')]()[_0xbc29('0x29')](function(){_0x5c6f6d['status'](0xcc)[_0xbc29('0x1f')]();});}};}function handleEntityNotFound(_0x3ad136,_0x536bd2){return function(_0xd3d9a5){if(!_0xd3d9a5){_0x3ad136[_0xbc29('0x1d')](0x194);}return _0xd3d9a5;};}function handleError(_0x511fa7,_0x4983b5){_0x4983b5=_0x4983b5||0x1f4;return function(_0x2c7b63){logger['error'](_0x2c7b63['stack']);if(_0x2c7b63[_0xbc29('0x2b')]){delete _0x2c7b63[_0xbc29('0x2b')];}_0x511fa7[_0xbc29('0x1e')](_0x4983b5)['send'](_0x2c7b63);};}exports[_0xbc29('0x2c')]=function(_0x3febdf,_0x1e11b3){var _0x2f23c2={},_0x1797c9={},_0x549cb5={'count':0x0,'rows':[]};var _0x55971f=_[_0xbc29('0x2d')](db[_0xbc29('0x2e')]['rawAttributes'],function(_0x2d89e1){return{'name':_0x2d89e1[_0xbc29('0x2f')],'type':_0x2d89e1[_0xbc29('0x30')][_0xbc29('0x31')]};});_0x1797c9[_0xbc29('0x32')]=_[_0xbc29('0x2d')](_0x55971f,'name');_0x1797c9[_0xbc29('0x33')]=_[_0xbc29('0x34')](_0x3febdf[_0xbc29('0x33')]);_0x1797c9[_0xbc29('0x35')]=_['intersection'](_0x1797c9[_0xbc29('0x32')],_0x1797c9[_0xbc29('0x33')]);_0x2f23c2[_0xbc29('0x36')]=_['intersection'](_0x1797c9['model'],qs[_0xbc29('0x37')](_0x3febdf[_0xbc29('0x33')][_0xbc29('0x37')]));_0x2f23c2['attributes']=_0x2f23c2[_0xbc29('0x36')][_0xbc29('0x38')]?_0x2f23c2[_0xbc29('0x36')]:_0x1797c9[_0xbc29('0x32')];if(!_0x3febdf['query']['hasOwnProperty']('nolimit')){_0x2f23c2[_0xbc29('0x22')]=qs[_0xbc29('0x22')](_0x3febdf[_0xbc29('0x33')]['limit']);_0x2f23c2['offset']=qs[_0xbc29('0x39')](_0x3febdf[_0xbc29('0x33')]['offset']);}_0x2f23c2['order']=qs[_0xbc29('0x3a')](_0x3febdf[_0xbc29('0x33')][_0xbc29('0x3a')]);_0x2f23c2[_0xbc29('0x3b')]=qs[_0xbc29('0x35')](_[_0xbc29('0x3c')](_0x3febdf['query'],_0x1797c9['filters']),_0x55971f);if(_0x3febdf[_0xbc29('0x33')]['filter']){_0x2f23c2[_0xbc29('0x3b')]=_['merge'](_0x2f23c2[_0xbc29('0x3b')],{'$or':_[_0xbc29('0x2d')](_0x55971f,function(_0x37afc4){if(_0x37afc4[_0xbc29('0x30')]!==_0xbc29('0x3d')){var _0x1d2e98={};_0x1d2e98[_0x37afc4[_0xbc29('0x2b')]]={'$like':'%'+_0x3febdf[_0xbc29('0x33')][_0xbc29('0x3e')]+'%'};return _0x1d2e98;}})});}_0x2f23c2=_['merge']({},_0x2f23c2,_0x3febdf[_0xbc29('0x3f')]);var _0x202804={'where':_0x2f23c2[_0xbc29('0x3b')]};return db[_0xbc29('0x2e')][_0xbc29('0x23')](_0x202804)['then'](function(_0x1e91bd){_0x549cb5[_0xbc29('0x23')]=_0x1e91bd;if(_0x3febdf[_0xbc29('0x33')]['includeAll']){_0x2f23c2['include']=[{'all':!![]}];}return db[_0xbc29('0x2e')][_0xbc29('0x40')](_0x2f23c2);})[_0xbc29('0x29')](function(_0xf8bd18){_0x549cb5[_0xbc29('0x41')]=_0xf8bd18;return _0x549cb5;})[_0xbc29('0x29')](respondWithFilteredResult(_0x1e11b3,_0x2f23c2))[_0xbc29('0x42')](handleError(_0x1e11b3,null));};exports[_0xbc29('0x43')]=function(_0x38f119,_0x3522f1){var _0x86bad5={'raw':!![],'where':{'id':_0x38f119[_0xbc29('0x44')]['id']}},_0x33508d={};_0x33508d['model']=_[_0xbc29('0x34')](db['FreshdeskField'][_0xbc29('0x45')]);_0x33508d[_0xbc29('0x33')]=_[_0xbc29('0x34')](_0x38f119[_0xbc29('0x33')]);_0x33508d['filters']=_[_0xbc29('0x46')](_0x33508d[_0xbc29('0x32')],_0x33508d[_0xbc29('0x33')]);_0x86bad5[_0xbc29('0x36')]=_[_0xbc29('0x46')](_0x33508d['model'],qs[_0xbc29('0x37')](_0x38f119[_0xbc29('0x33')][_0xbc29('0x37')]));_0x86bad5[_0xbc29('0x36')]=_0x86bad5[_0xbc29('0x36')]['length']?_0x86bad5['attributes']:_0x33508d[_0xbc29('0x32')];if(_0x38f119[_0xbc29('0x33')][_0xbc29('0x47')]){_0x86bad5[_0xbc29('0x48')]=[{'all':!![]}];}_0x86bad5=_['merge']({},_0x86bad5,_0x38f119[_0xbc29('0x3f')]);return db[_0xbc29('0x2e')]['find'](_0x86bad5)[_0xbc29('0x29')](handleEntityNotFound(_0x3522f1,null))['then'](respondWithResult(_0x3522f1,null))[_0xbc29('0x42')](handleError(_0x3522f1,null));};exports['create']=function(_0x54a625,_0x2866b2){return db[_0xbc29('0x2e')][_0xbc29('0x49')](_0x54a625[_0xbc29('0x4a')],{})['then'](respondWithResult(_0x2866b2,0xc9))[_0xbc29('0x42')](handleError(_0x2866b2,null));};exports['update']=function(_0x55c0cc,_0x2ff594){if(_0x55c0cc[_0xbc29('0x4a')]['id']){delete _0x55c0cc[_0xbc29('0x4a')]['id'];}return db[_0xbc29('0x2e')][_0xbc29('0x4b')]({'where':{'id':_0x55c0cc[_0xbc29('0x44')]['id']}})[_0xbc29('0x29')](handleEntityNotFound(_0x2ff594,null))[_0xbc29('0x29')](saveUpdates(_0x55c0cc['body'],null))[_0xbc29('0x29')](respondWithResult(_0x2ff594,null))[_0xbc29('0x42')](handleError(_0x2ff594,null));};exports[_0xbc29('0x2a')]=function(_0x599ba7,_0x3f4323){return db[_0xbc29('0x2e')]['find']({'where':{'id':_0x599ba7[_0xbc29('0x44')]['id']}})[_0xbc29('0x29')](handleEntityNotFound(_0x3f4323,null))[_0xbc29('0x29')](removeEntity(_0x3f4323,null))[_0xbc29('0x42')](handleError(_0x3f4323,null));};