Built motion from commit 3e059bc2.|2.5.32
[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 _0xfc1e=['filter','options','ZendeskField','includeAll','findAll','catch','show','params','include','create','body','find','destroy','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','limit','undefined','count','reject','update','then','sendStatus','stack','name','send','map','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL'];(function(_0x2f247d,_0x5d3c83){var _0x23b638=function(_0x26deb0){while(--_0x26deb0){_0x2f247d['push'](_0x2f247d['shift']());}};_0x23b638(++_0x5d3c83);}(_0xfc1e,0x1c9));var _0xefc1=function(_0x329d13,_0x1aff27){_0x329d13=_0x329d13-0x0;var _0x33efd9=_0xfc1e[_0x329d13];return _0x33efd9;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xefc1('0x0'));var rp=require(_0xefc1('0x1'));var moment=require(_0xefc1('0x2'));var BPromise=require(_0xefc1('0x3'));var Mustache=require(_0xefc1('0x4'));var util=require('util');var path=require(_0xefc1('0x5'));var sox=require(_0xefc1('0x6'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xefc1('0x7'));var _=require(_0xefc1('0x8'));var squel=require(_0xefc1('0x9'));var crypto=require(_0xefc1('0xa'));var jsforce=require(_0xefc1('0xb'));var deskjs=require(_0xefc1('0xc'));var toCsv=require(_0xefc1('0xd'));var querystring=require(_0xefc1('0xe'));var Papa=require(_0xefc1('0xf'));var Redis=require(_0xefc1('0x10'));var authService=require(_0xefc1('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xefc1('0x12'));var hardwareService=require(_0xefc1('0x13'));var logger=require(_0xefc1('0x14'))(_0xefc1('0x15'));var utils=require(_0xefc1('0x16'));var config=require(_0xefc1('0x17'));var licenseUtil=require(_0xefc1('0x18'));var db=require(_0xefc1('0x19'))['db'];function respondWithStatusCode(_0x41dc08,_0x139fbf){_0x139fbf=_0x139fbf||0xcc;return function(_0x3530d0){if(_0x3530d0){return _0x41dc08['sendStatus'](_0x139fbf);}return _0x41dc08[_0xefc1('0x1a')](_0x139fbf)[_0xefc1('0x1b')]();};}function respondWithResult(_0x1c7ea5,_0x36633f){_0x36633f=_0x36633f||0xc8;return function(_0x32372b){if(_0x32372b){return _0x1c7ea5[_0xefc1('0x1a')](_0x36633f)[_0xefc1('0x1c')](_0x32372b);}};}function respondWithFilteredResult(_0x209334,_0x4d42cd){return function(_0x1e1418){if(_0x1e1418){var _0x1cc6d9=typeof _0x4d42cd[_0xefc1('0x1d')]==='undefined'&&typeof _0x4d42cd[_0xefc1('0x1e')]===_0xefc1('0x1f');var _0x352f28=_0x1e1418[_0xefc1('0x20')];var _0x257914=_0x1cc6d9?0x0:_0x4d42cd[_0xefc1('0x1d')];var _0x3b5a6e=_0x1cc6d9?_0x1e1418[_0xefc1('0x20')]:_0x4d42cd['offset']+_0x4d42cd[_0xefc1('0x1e')];var _0x1aaaa0;if(_0x3b5a6e>=_0x352f28){_0x3b5a6e=_0x352f28;_0x1aaaa0=0xc8;}else{_0x1aaaa0=0xce;}_0x209334[_0xefc1('0x1a')](_0x1aaaa0);return _0x209334['set']('Content-Range',_0x257914+'-'+_0x3b5a6e+'/'+_0x352f28)[_0xefc1('0x1c')](_0x1e1418);}return null;};}function patchUpdates(_0x492d7d){return function(_0x379c24){try{jsonpatch['apply'](_0x379c24,_0x492d7d,!![]);}catch(_0x1fd87f){return BPromise[_0xefc1('0x21')](_0x1fd87f);}return _0x379c24['save']();};}function saveUpdates(_0x2f5190,_0x2ea108){return function(_0x102576){if(_0x102576){return _0x102576[_0xefc1('0x22')](_0x2f5190)[_0xefc1('0x23')](function(_0xdeb673){return _0xdeb673;});}return null;};}function removeEntity(_0x5db459,_0x2f4935){return function(_0xd950ce){if(_0xd950ce){return _0xd950ce['destroy']()[_0xefc1('0x23')](function(){_0x5db459['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x21aa3b,_0x84a5c0){return function(_0x3eb944){if(!_0x3eb944){_0x21aa3b[_0xefc1('0x24')](0x194);}return _0x3eb944;};}function handleError(_0x452363,_0x3ee133){_0x3ee133=_0x3ee133||0x1f4;return function(_0x538145){logger['error'](_0x538145[_0xefc1('0x25')]);if(_0x538145[_0xefc1('0x26')]){delete _0x538145[_0xefc1('0x26')];}_0x452363[_0xefc1('0x1a')](_0x3ee133)[_0xefc1('0x27')](_0x538145);};}exports['index']=function(_0x33c2f7,_0x3f6e1a){var _0x55f900={},_0x486a5b={},_0x1c58e7={'count':0x0,'rows':[]};var _0x344ce8=_[_0xefc1('0x28')](db['ZendeskField'][_0xefc1('0x29')],function(_0x40196f){return{'name':_0x40196f[_0xefc1('0x2a')],'type':_0x40196f[_0xefc1('0x2b')][_0xefc1('0x2c')]};});_0x486a5b[_0xefc1('0x2d')]=_[_0xefc1('0x28')](_0x344ce8,_0xefc1('0x26'));_0x486a5b['query']=_[_0xefc1('0x2e')](_0x33c2f7[_0xefc1('0x2f')]);_0x486a5b[_0xefc1('0x30')]=_[_0xefc1('0x31')](_0x486a5b[_0xefc1('0x2d')],_0x486a5b[_0xefc1('0x2f')]);_0x55f900[_0xefc1('0x32')]=_[_0xefc1('0x31')](_0x486a5b['model'],qs[_0xefc1('0x33')](_0x33c2f7[_0xefc1('0x2f')][_0xefc1('0x33')]));_0x55f900[_0xefc1('0x32')]=_0x55f900['attributes'][_0xefc1('0x34')]?_0x55f900['attributes']:_0x486a5b[_0xefc1('0x2d')];if(!_0x33c2f7[_0xefc1('0x2f')][_0xefc1('0x35')](_0xefc1('0x36'))){_0x55f900['limit']=qs[_0xefc1('0x1e')](_0x33c2f7[_0xefc1('0x2f')][_0xefc1('0x1e')]);_0x55f900['offset']=qs[_0xefc1('0x1d')](_0x33c2f7['query']['offset']);}_0x55f900[_0xefc1('0x37')]=qs['sort'](_0x33c2f7[_0xefc1('0x2f')][_0xefc1('0x38')]);_0x55f900[_0xefc1('0x39')]=qs[_0xefc1('0x30')](_[_0xefc1('0x3a')](_0x33c2f7['query'],_0x486a5b[_0xefc1('0x30')]),_0x344ce8);if(_0x33c2f7[_0xefc1('0x2f')]['filter']){_0x55f900[_0xefc1('0x39')]=_[_0xefc1('0x3b')](_0x55f900[_0xefc1('0x39')],{'$or':_[_0xefc1('0x28')](_0x344ce8,function(_0x5b7908){if(_0x5b7908[_0xefc1('0x2b')]!==_0xefc1('0x3c')){var _0x1b899b={};_0x1b899b[_0x5b7908[_0xefc1('0x26')]]={'$like':'%'+_0x33c2f7[_0xefc1('0x2f')][_0xefc1('0x3d')]+'%'};return _0x1b899b;}})});}_0x55f900=_[_0xefc1('0x3b')]({},_0x55f900,_0x33c2f7[_0xefc1('0x3e')]);var _0xa6c759={'where':_0x55f900['where']};return db[_0xefc1('0x3f')][_0xefc1('0x20')](_0xa6c759)[_0xefc1('0x23')](function(_0x33ade1){_0x1c58e7[_0xefc1('0x20')]=_0x33ade1;if(_0x33c2f7[_0xefc1('0x2f')][_0xefc1('0x40')]){_0x55f900['include']=[{'all':!![]}];}return db[_0xefc1('0x3f')][_0xefc1('0x41')](_0x55f900);})[_0xefc1('0x23')](function(_0x44c944){_0x1c58e7['rows']=_0x44c944;return _0x1c58e7;})[_0xefc1('0x23')](respondWithFilteredResult(_0x3f6e1a,_0x55f900))[_0xefc1('0x42')](handleError(_0x3f6e1a,null));};exports[_0xefc1('0x43')]=function(_0x4dd2cc,_0x1cdb35){var _0x1f3e8e={'raw':!![],'where':{'id':_0x4dd2cc[_0xefc1('0x44')]['id']}},_0x7ff13e={};_0x7ff13e[_0xefc1('0x2d')]=_['keys'](db[_0xefc1('0x3f')]['rawAttributes']);_0x7ff13e[_0xefc1('0x2f')]=_[_0xefc1('0x2e')](_0x4dd2cc[_0xefc1('0x2f')]);_0x7ff13e[_0xefc1('0x30')]=_['intersection'](_0x7ff13e[_0xefc1('0x2d')],_0x7ff13e['query']);_0x1f3e8e[_0xefc1('0x32')]=_[_0xefc1('0x31')](_0x7ff13e['model'],qs[_0xefc1('0x33')](_0x4dd2cc[_0xefc1('0x2f')][_0xefc1('0x33')]));_0x1f3e8e[_0xefc1('0x32')]=_0x1f3e8e[_0xefc1('0x32')][_0xefc1('0x34')]?_0x1f3e8e[_0xefc1('0x32')]:_0x7ff13e[_0xefc1('0x2d')];if(_0x4dd2cc['query'][_0xefc1('0x40')]){_0x1f3e8e[_0xefc1('0x45')]=[{'all':!![]}];}_0x1f3e8e=_[_0xefc1('0x3b')]({},_0x1f3e8e,_0x4dd2cc['options']);return db[_0xefc1('0x3f')]['find'](_0x1f3e8e)[_0xefc1('0x23')](handleEntityNotFound(_0x1cdb35,null))[_0xefc1('0x23')](respondWithResult(_0x1cdb35,null))[_0xefc1('0x42')](handleError(_0x1cdb35,null));};exports[_0xefc1('0x46')]=function(_0x5c984c,_0x28a6d1){return db['ZendeskField'][_0xefc1('0x46')](_0x5c984c[_0xefc1('0x47')],{})[_0xefc1('0x23')](respondWithResult(_0x28a6d1,0xc9))[_0xefc1('0x42')](handleError(_0x28a6d1,null));};exports['update']=function(_0x50c8d5,_0x3d37cd){if(_0x50c8d5[_0xefc1('0x47')]['id']){delete _0x50c8d5[_0xefc1('0x47')]['id'];}return db[_0xefc1('0x3f')][_0xefc1('0x48')]({'where':{'id':_0x50c8d5[_0xefc1('0x44')]['id']}})['then'](handleEntityNotFound(_0x3d37cd,null))[_0xefc1('0x23')](saveUpdates(_0x50c8d5[_0xefc1('0x47')],null))[_0xefc1('0x23')](respondWithResult(_0x3d37cd,null))[_0xefc1('0x42')](handleError(_0x3d37cd,null));};exports[_0xefc1('0x49')]=function(_0x58bfd6,_0x90bc06){return db[_0xefc1('0x3f')][_0xefc1('0x48')]({'where':{'id':_0x58bfd6[_0xefc1('0x44')]['id']}})[_0xefc1('0x23')](handleEntityNotFound(_0x90bc06,null))['then'](removeEntity(_0x90bc06,null))['catch'](handleError(_0x90bc06,null));};