ee1eb46c23704d7fa07a8b938d8e5ae5b76033a8
[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 _0xc8bf=['moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','squel','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','count','limit','set','apply','reject','save','then','error','stack','name','send','index','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','filter','map','VIRTUAL','merge','options','ZendeskField','includeAll','findAll','rows','catch','show','params','include','find','create','body','update','destroy','eml-format','rimraf','zip-dir','fast-json-patch','request-promise'];(function(_0x43d558,_0x4bae4f){var _0x2cb7a9=function(_0x33dd08){while(--_0x33dd08){_0x43d558['push'](_0x43d558['shift']());}};_0x2cb7a9(++_0x4bae4f);}(_0xc8bf,0x181));var _0xfc8b=function(_0x313e7c,_0x52f808){_0x313e7c=_0x313e7c-0x0;var _0x3ea27f=_0xc8bf[_0x313e7c];return _0x3ea27f;};'use strict';var emlformat=require(_0xfc8b('0x0'));var rimraf=require(_0xfc8b('0x1'));var zipdir=require(_0xfc8b('0x2'));var jsonpatch=require(_0xfc8b('0x3'));var rp=require(_0xfc8b('0x4'));var moment=require(_0xfc8b('0x5'));var BPromise=require(_0xfc8b('0x6'));var Mustache=require(_0xfc8b('0x7'));var util=require('util');var path=require(_0xfc8b('0x8'));var sox=require(_0xfc8b('0x9'));var csv=require(_0xfc8b('0xa'));var ejs=require(_0xfc8b('0xb'));var fs=require('fs');var fs_extra=require(_0xfc8b('0xc'));var _=require('lodash');var squel=require(_0xfc8b('0xd'));var crypto=require('crypto');var jsforce=require(_0xfc8b('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xfc8b('0xa'));var querystring=require('querystring');var Papa=require(_0xfc8b('0xf'));var Redis=require(_0xfc8b('0x10'));var authService=require(_0xfc8b('0x11'));var qs=require(_0xfc8b('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xfc8b('0x13'));var logger=require('../../config/logger')(_0xfc8b('0x14'));var utils=require(_0xfc8b('0x15'));var config=require(_0xfc8b('0x16'));var licenseUtil=require(_0xfc8b('0x17'));var db=require(_0xfc8b('0x18'))['db'];function respondWithStatusCode(_0x2d16a2,_0x36c122){_0x36c122=_0x36c122||0xcc;return function(_0x15a126){if(_0x15a126){return _0x2d16a2[_0xfc8b('0x19')](_0x36c122);}return _0x2d16a2['status'](_0x36c122)[_0xfc8b('0x1a')]();};}function respondWithResult(_0x1a9572,_0x5c7958){_0x5c7958=_0x5c7958||0xc8;return function(_0x78eb76){if(_0x78eb76){return _0x1a9572[_0xfc8b('0x1b')](_0x5c7958)[_0xfc8b('0x1c')](_0x78eb76);}};}function respondWithFilteredResult(_0x1c3141,_0x206039){return function(_0x1a32a0){if(_0x1a32a0){var _0x4bfee8=typeof _0x206039[_0xfc8b('0x1d')]===_0xfc8b('0x1e')&&typeof _0x206039['limit']===_0xfc8b('0x1e');var _0x3e4bc5=_0x1a32a0[_0xfc8b('0x1f')];var _0x49a80f=_0x4bfee8?0x0:_0x206039[_0xfc8b('0x1d')];var _0x3ef7c5=_0x4bfee8?_0x1a32a0['count']:_0x206039[_0xfc8b('0x1d')]+_0x206039[_0xfc8b('0x20')];var _0x36f38a;if(_0x3ef7c5>=_0x3e4bc5){_0x3ef7c5=_0x3e4bc5;_0x36f38a=0xc8;}else{_0x36f38a=0xce;}_0x1c3141[_0xfc8b('0x1b')](_0x36f38a);return _0x1c3141[_0xfc8b('0x21')]('Content-Range',_0x49a80f+'-'+_0x3ef7c5+'/'+_0x3e4bc5)['json'](_0x1a32a0);}return null;};}function patchUpdates(_0x8af353){return function(_0x348b06){try{jsonpatch[_0xfc8b('0x22')](_0x348b06,_0x8af353,!![]);}catch(_0x40bbc3){return BPromise[_0xfc8b('0x23')](_0x40bbc3);}return _0x348b06[_0xfc8b('0x24')]();};}function saveUpdates(_0x1da466,_0x3ad123){return function(_0x50ac51){if(_0x50ac51){return _0x50ac51['update'](_0x1da466)[_0xfc8b('0x25')](function(_0x5f3afd){return _0x5f3afd;});}return null;};}function removeEntity(_0x9ca658,_0x416f04){return function(_0x38add3){if(_0x38add3){return _0x38add3['destroy']()[_0xfc8b('0x25')](function(){_0x9ca658['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x50dd73,_0x59b2bf){return function(_0x5345ed){if(!_0x5345ed){_0x50dd73[_0xfc8b('0x19')](0x194);}return _0x5345ed;};}function handleError(_0x29e056,_0x44514c){_0x44514c=_0x44514c||0x1f4;return function(_0x59c0dd){logger[_0xfc8b('0x26')](_0x59c0dd[_0xfc8b('0x27')]);if(_0x59c0dd[_0xfc8b('0x28')]){delete _0x59c0dd[_0xfc8b('0x28')];}_0x29e056['status'](_0x44514c)[_0xfc8b('0x29')](_0x59c0dd);};}exports[_0xfc8b('0x2a')]=function(_0x52b3ba,_0x346578){var _0x2f468c={},_0x5837bb={},_0x75ff72={'count':0x0,'rows':[]};var _0x108d66=_['map'](db['ZendeskField'][_0xfc8b('0x2b')],function(_0x5821e0){return{'name':_0x5821e0[_0xfc8b('0x2c')],'type':_0x5821e0[_0xfc8b('0x2d')][_0xfc8b('0x2e')]};});_0x5837bb[_0xfc8b('0x2f')]=_['map'](_0x108d66,_0xfc8b('0x28'));_0x5837bb['query']=_[_0xfc8b('0x30')](_0x52b3ba[_0xfc8b('0x31')]);_0x5837bb[_0xfc8b('0x32')]=_[_0xfc8b('0x33')](_0x5837bb[_0xfc8b('0x2f')],_0x5837bb[_0xfc8b('0x31')]);_0x2f468c['attributes']=_['intersection'](_0x5837bb[_0xfc8b('0x2f')],qs[_0xfc8b('0x34')](_0x52b3ba['query'][_0xfc8b('0x34')]));_0x2f468c['attributes']=_0x2f468c[_0xfc8b('0x35')]['length']?_0x2f468c[_0xfc8b('0x35')]:_0x5837bb[_0xfc8b('0x2f')];if(!_0x52b3ba[_0xfc8b('0x31')][_0xfc8b('0x36')](_0xfc8b('0x37'))){_0x2f468c[_0xfc8b('0x20')]=qs[_0xfc8b('0x20')](_0x52b3ba[_0xfc8b('0x31')]['limit']);_0x2f468c[_0xfc8b('0x1d')]=qs[_0xfc8b('0x1d')](_0x52b3ba['query'][_0xfc8b('0x1d')]);}_0x2f468c[_0xfc8b('0x38')]=qs[_0xfc8b('0x39')](_0x52b3ba['query']['sort']);_0x2f468c[_0xfc8b('0x3a')]=qs[_0xfc8b('0x32')](_[_0xfc8b('0x3b')](_0x52b3ba['query'],_0x5837bb[_0xfc8b('0x32')]),_0x108d66);if(_0x52b3ba[_0xfc8b('0x31')][_0xfc8b('0x3c')]){_0x2f468c[_0xfc8b('0x3a')]=_['merge'](_0x2f468c[_0xfc8b('0x3a')],{'$or':_[_0xfc8b('0x3d')](_0x108d66,function(_0x2d4b3b){if(_0x2d4b3b[_0xfc8b('0x2d')]!==_0xfc8b('0x3e')){var _0x28d963={};_0x28d963[_0x2d4b3b['name']]={'$like':'%'+_0x52b3ba[_0xfc8b('0x31')]['filter']+'%'};return _0x28d963;}})});}_0x2f468c=_[_0xfc8b('0x3f')]({},_0x2f468c,_0x52b3ba[_0xfc8b('0x40')]);var _0xb5a348={'where':_0x2f468c['where']};return db[_0xfc8b('0x41')]['count'](_0xb5a348)[_0xfc8b('0x25')](function(_0x4ffc3d){_0x75ff72[_0xfc8b('0x1f')]=_0x4ffc3d;if(_0x52b3ba[_0xfc8b('0x31')][_0xfc8b('0x42')]){_0x2f468c['include']=[{'all':!![]}];}return db['ZendeskField'][_0xfc8b('0x43')](_0x2f468c);})[_0xfc8b('0x25')](function(_0x1cbd4e){_0x75ff72[_0xfc8b('0x44')]=_0x1cbd4e;return _0x75ff72;})[_0xfc8b('0x25')](respondWithFilteredResult(_0x346578,_0x2f468c))[_0xfc8b('0x45')](handleError(_0x346578,null));};exports[_0xfc8b('0x46')]=function(_0x52f6a2,_0x475781){var _0x5c9d7d={'raw':!![],'where':{'id':_0x52f6a2[_0xfc8b('0x47')]['id']}},_0x287b2c={};_0x287b2c['model']=_[_0xfc8b('0x30')](db[_0xfc8b('0x41')]['rawAttributes']);_0x287b2c['query']=_[_0xfc8b('0x30')](_0x52f6a2[_0xfc8b('0x31')]);_0x287b2c['filters']=_['intersection'](_0x287b2c[_0xfc8b('0x2f')],_0x287b2c[_0xfc8b('0x31')]);_0x5c9d7d[_0xfc8b('0x35')]=_[_0xfc8b('0x33')](_0x287b2c[_0xfc8b('0x2f')],qs[_0xfc8b('0x34')](_0x52f6a2[_0xfc8b('0x31')][_0xfc8b('0x34')]));_0x5c9d7d['attributes']=_0x5c9d7d[_0xfc8b('0x35')]['length']?_0x5c9d7d[_0xfc8b('0x35')]:_0x287b2c[_0xfc8b('0x2f')];if(_0x52f6a2[_0xfc8b('0x31')][_0xfc8b('0x42')]){_0x5c9d7d[_0xfc8b('0x48')]=[{'all':!![]}];}_0x5c9d7d=_['merge']({},_0x5c9d7d,_0x52f6a2['options']);return db[_0xfc8b('0x41')][_0xfc8b('0x49')](_0x5c9d7d)[_0xfc8b('0x25')](handleEntityNotFound(_0x475781,null))[_0xfc8b('0x25')](respondWithResult(_0x475781,null))['catch'](handleError(_0x475781,null));};exports[_0xfc8b('0x4a')]=function(_0x4916d4,_0x3360cd){return db['ZendeskField'][_0xfc8b('0x4a')](_0x4916d4[_0xfc8b('0x4b')],{})[_0xfc8b('0x25')](respondWithResult(_0x3360cd,0xc9))[_0xfc8b('0x45')](handleError(_0x3360cd,null));};exports[_0xfc8b('0x4c')]=function(_0x19146a,_0x310bbd){if(_0x19146a[_0xfc8b('0x4b')]['id']){delete _0x19146a['body']['id'];}return db['ZendeskField'][_0xfc8b('0x49')]({'where':{'id':_0x19146a[_0xfc8b('0x47')]['id']}})[_0xfc8b('0x25')](handleEntityNotFound(_0x310bbd,null))[_0xfc8b('0x25')](saveUpdates(_0x19146a[_0xfc8b('0x4b')],null))[_0xfc8b('0x25')](respondWithResult(_0x310bbd,null))[_0xfc8b('0x45')](handleError(_0x310bbd,null));};exports[_0xfc8b('0x4d')]=function(_0x5cac2a,_0x20fc8b){return db['ZendeskField'][_0xfc8b('0x49')]({'where':{'id':_0x5cac2a[_0xfc8b('0x47')]['id']}})[_0xfc8b('0x25')](handleEntityNotFound(_0x20fc8b,null))['then'](removeEntity(_0x20fc8b,null))[_0xfc8b('0x45')](handleError(_0x20fc8b,null));};