b4c32f20242737a31d20428917c66ecb82769287
[motion2.git] / server / api / intZendeskField / intZendeskField.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 _0x588f=['fields','length','order','sort','pick','filter','where','merge','VIRTUAL','include','findAll','rows','catch','params','includeAll','options','find','create','body','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','undefined','offset','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','stack','name','send','index','map','ZendeskField','rawAttributes','fieldName','type','key','model','keys','filters','intersection','query','attributes'];(function(_0x57b54c,_0x54ce0d){var _0x59cc19=function(_0xa33bc6){while(--_0xa33bc6){_0x57b54c['push'](_0x57b54c['shift']());}};_0x59cc19(++_0x54ce0d);}(_0x588f,0x194));var _0xf588=function(_0x3fe2be,_0x24cfba){_0x3fe2be=_0x3fe2be-0x0;var _0x16b3ca=_0x588f[_0x3fe2be];return _0x16b3ca;};'use strict';var emlformat=require(_0xf588('0x0'));var rimraf=require(_0xf588('0x1'));var zipdir=require(_0xf588('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf588('0x3'));var moment=require('moment');var BPromise=require(_0xf588('0x4'));var Mustache=require(_0xf588('0x5'));var util=require(_0xf588('0x6'));var path=require(_0xf588('0x7'));var sox=require(_0xf588('0x8'));var csv=require(_0xf588('0x9'));var ejs=require(_0xf588('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf588('0xb'));var squel=require(_0xf588('0xc'));var crypto=require(_0xf588('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xf588('0x9'));var querystring=require(_0xf588('0xe'));var Papa=require('papaparse');var Redis=require(_0xf588('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xf588('0x10'));var as=require(_0xf588('0x11'));var hardwareService=require(_0xf588('0x12'));var logger=require(_0xf588('0x13'))(_0xf588('0x14'));var utils=require(_0xf588('0x15'));var config=require(_0xf588('0x16'));var licenseUtil=require(_0xf588('0x17'));var db=require(_0xf588('0x18'))['db'];function respondWithStatusCode(_0x490786,_0x3fecd9){_0x3fecd9=_0x3fecd9||0xcc;return function(_0x60dfa0){if(_0x60dfa0){return _0x490786['sendStatus'](_0x3fecd9);}return _0x490786[_0xf588('0x19')](_0x3fecd9)[_0xf588('0x1a')]();};}function respondWithResult(_0x40bc93,_0x5a20b){_0x5a20b=_0x5a20b||0xc8;return function(_0x37eed7){if(_0x37eed7){return _0x40bc93[_0xf588('0x19')](_0x5a20b)[_0xf588('0x1b')](_0x37eed7);}};}function respondWithFilteredResult(_0x47f959,_0x4ec945){return function(_0x16dea0){if(_0x16dea0){var _0x4f7d57=typeof _0x4ec945['offset']===_0xf588('0x1c')&&typeof _0x4ec945['limit']==='undefined';var _0x3fa21f=_0x16dea0['count'];var _0x5eda34=_0x4f7d57?0x0:_0x4ec945[_0xf588('0x1d')];var _0x2f4697=_0x4f7d57?_0x16dea0[_0xf588('0x1e')]:_0x4ec945[_0xf588('0x1d')]+_0x4ec945[_0xf588('0x1f')];var _0x1144cd;if(_0x2f4697>=_0x3fa21f){_0x2f4697=_0x3fa21f;_0x1144cd=0xc8;}else{_0x1144cd=0xce;}_0x47f959[_0xf588('0x19')](_0x1144cd);return _0x47f959[_0xf588('0x20')](_0xf588('0x21'),_0x5eda34+'-'+_0x2f4697+'/'+_0x3fa21f)[_0xf588('0x1b')](_0x16dea0);}return null;};}function patchUpdates(_0x57431d){return function(_0x5619bf){try{jsonpatch[_0xf588('0x22')](_0x5619bf,_0x57431d,!![]);}catch(_0x4e27b5){return BPromise[_0xf588('0x23')](_0x4e27b5);}return _0x5619bf[_0xf588('0x24')]();};}function saveUpdates(_0xcc230c,_0x4efb55){return function(_0x3ea065){if(_0x3ea065){return _0x3ea065[_0xf588('0x25')](_0xcc230c)[_0xf588('0x26')](function(_0x3a5a7d){return _0x3a5a7d;});}return null;};}function removeEntity(_0x28ac2a,_0x1fcd7f){return function(_0x27c6fc){if(_0x27c6fc){return _0x27c6fc[_0xf588('0x27')]()[_0xf588('0x26')](function(){_0x28ac2a[_0xf588('0x19')](0xcc)[_0xf588('0x1a')]();});}};}function handleEntityNotFound(_0x48579b,_0xc77b4c){return function(_0x41eac5){if(!_0x41eac5){_0x48579b[_0xf588('0x28')](0x194);}return _0x41eac5;};}function handleError(_0x32e9be,_0x59117f){_0x59117f=_0x59117f||0x1f4;return function(_0x5d222d){logger[_0xf588('0x29')](_0x5d222d[_0xf588('0x2a')]);if(_0x5d222d[_0xf588('0x2b')]){delete _0x5d222d[_0xf588('0x2b')];}_0x32e9be['status'](_0x59117f)[_0xf588('0x2c')](_0x5d222d);};}exports[_0xf588('0x2d')]=function(_0x23c2fb,_0x2d2a55){var _0x6e5b4={},_0x17cece={},_0x2dfb10={'count':0x0,'rows':[]};var _0x181bc2=_[_0xf588('0x2e')](db[_0xf588('0x2f')][_0xf588('0x30')],function(_0x5adc34){return{'name':_0x5adc34[_0xf588('0x31')],'type':_0x5adc34[_0xf588('0x32')][_0xf588('0x33')]};});_0x17cece[_0xf588('0x34')]=_[_0xf588('0x2e')](_0x181bc2,'name');_0x17cece['query']=_[_0xf588('0x35')](_0x23c2fb['query']);_0x17cece[_0xf588('0x36')]=_[_0xf588('0x37')](_0x17cece[_0xf588('0x34')],_0x17cece[_0xf588('0x38')]);_0x6e5b4[_0xf588('0x39')]=_[_0xf588('0x37')](_0x17cece[_0xf588('0x34')],qs[_0xf588('0x3a')](_0x23c2fb[_0xf588('0x38')][_0xf588('0x3a')]));_0x6e5b4[_0xf588('0x39')]=_0x6e5b4[_0xf588('0x39')][_0xf588('0x3b')]?_0x6e5b4[_0xf588('0x39')]:_0x17cece['model'];if(!_0x23c2fb[_0xf588('0x38')]['hasOwnProperty']('nolimit')){_0x6e5b4['limit']=qs['limit'](_0x23c2fb[_0xf588('0x38')][_0xf588('0x1f')]);_0x6e5b4[_0xf588('0x1d')]=qs[_0xf588('0x1d')](_0x23c2fb[_0xf588('0x38')][_0xf588('0x1d')]);}_0x6e5b4[_0xf588('0x3c')]=qs[_0xf588('0x3d')](_0x23c2fb[_0xf588('0x38')][_0xf588('0x3d')]);_0x6e5b4['where']=qs[_0xf588('0x36')](_[_0xf588('0x3e')](_0x23c2fb[_0xf588('0x38')],_0x17cece[_0xf588('0x36')]),_0x181bc2);if(_0x23c2fb[_0xf588('0x38')][_0xf588('0x3f')]){_0x6e5b4[_0xf588('0x40')]=_[_0xf588('0x41')](_0x6e5b4[_0xf588('0x40')],{'$or':_[_0xf588('0x2e')](_0x181bc2,function(_0x1ba73a){if(_0x1ba73a['type']!==_0xf588('0x42')){var _0x2e32d6={};_0x2e32d6[_0x1ba73a[_0xf588('0x2b')]]={'$like':'%'+_0x23c2fb['query'][_0xf588('0x3f')]+'%'};return _0x2e32d6;}})});}_0x6e5b4=_['merge']({},_0x6e5b4,_0x23c2fb['options']);var _0x2a9aac={'where':_0x6e5b4['where']};return db[_0xf588('0x2f')][_0xf588('0x1e')](_0x2a9aac)[_0xf588('0x26')](function(_0x311f8a){_0x2dfb10[_0xf588('0x1e')]=_0x311f8a;if(_0x23c2fb['query']['includeAll']){_0x6e5b4[_0xf588('0x43')]=[{'all':!![]}];}return db['ZendeskField'][_0xf588('0x44')](_0x6e5b4);})['then'](function(_0x443474){_0x2dfb10[_0xf588('0x45')]=_0x443474;return _0x2dfb10;})['then'](respondWithFilteredResult(_0x2d2a55,_0x6e5b4))[_0xf588('0x46')](handleError(_0x2d2a55,null));};exports['show']=function(_0x5aa3ad,_0x233a81){var _0x5ea801={'raw':!![],'where':{'id':_0x5aa3ad[_0xf588('0x47')]['id']}},_0x4615c7={};_0x4615c7['model']=_['keys'](db['ZendeskField'][_0xf588('0x30')]);_0x4615c7[_0xf588('0x38')]=_['keys'](_0x5aa3ad[_0xf588('0x38')]);_0x4615c7[_0xf588('0x36')]=_['intersection'](_0x4615c7[_0xf588('0x34')],_0x4615c7[_0xf588('0x38')]);_0x5ea801[_0xf588('0x39')]=_['intersection'](_0x4615c7[_0xf588('0x34')],qs['fields'](_0x5aa3ad[_0xf588('0x38')][_0xf588('0x3a')]));_0x5ea801[_0xf588('0x39')]=_0x5ea801[_0xf588('0x39')][_0xf588('0x3b')]?_0x5ea801['attributes']:_0x4615c7[_0xf588('0x34')];if(_0x5aa3ad['query'][_0xf588('0x48')]){_0x5ea801['include']=[{'all':!![]}];}_0x5ea801=_[_0xf588('0x41')]({},_0x5ea801,_0x5aa3ad[_0xf588('0x49')]);return db[_0xf588('0x2f')][_0xf588('0x4a')](_0x5ea801)[_0xf588('0x26')](handleEntityNotFound(_0x233a81,null))[_0xf588('0x26')](respondWithResult(_0x233a81,null))[_0xf588('0x46')](handleError(_0x233a81,null));};exports[_0xf588('0x4b')]=function(_0x2fc543,_0x210fb6){return db[_0xf588('0x2f')][_0xf588('0x4b')](_0x2fc543[_0xf588('0x4c')],{})[_0xf588('0x26')](respondWithResult(_0x210fb6,0xc9))[_0xf588('0x46')](handleError(_0x210fb6,null));};exports[_0xf588('0x25')]=function(_0x2ada7b,_0x3e6c38){if(_0x2ada7b[_0xf588('0x4c')]['id']){delete _0x2ada7b['body']['id'];}return db[_0xf588('0x2f')][_0xf588('0x4a')]({'where':{'id':_0x2ada7b[_0xf588('0x47')]['id']}})['then'](handleEntityNotFound(_0x3e6c38,null))[_0xf588('0x26')](saveUpdates(_0x2ada7b['body'],null))['then'](respondWithResult(_0x3e6c38,null))[_0xf588('0x46')](handleError(_0x3e6c38,null));};exports[_0xf588('0x27')]=function(_0x3a2b34,_0x218987){return db['ZendeskField'][_0xf588('0x4a')]({'where':{'id':_0x3a2b34[_0xf588('0x47')]['id']}})['then'](handleEntityNotFound(_0x218987,null))['then'](removeEntity(_0x218987,null))[_0xf588('0x46')](handleError(_0x218987,null));};