61c920551bda55062f5e7fb9cdeabebdda3656e0
[motion2.git] / server / api / intDeskField / intDeskField.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 _0xa337=['filters','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','pick','filter','merge','VIRTUAL','options','where','count','includeAll','findAll','rows','catch','show','params','keys','include','create','body','find','eml-format','rimraf','fast-json-patch','request-promise','moment','util','path','sox','to-csv','ejs','fs-extra','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','set','Content-Range','apply','reject','save','update','then','destroy','stack','DeskField','rawAttributes','fieldName','type','key','model','map','name','query'];(function(_0xd983d3,_0x1c5b1b){var _0x488e12=function(_0x48084d){while(--_0x48084d){_0xd983d3['push'](_0xd983d3['shift']());}};_0x488e12(++_0x1c5b1b);}(_0xa337,0x13f));var _0x7a33=function(_0x39cd14,_0x420897){_0x39cd14=_0x39cd14-0x0;var _0x49b692=_0xa337[_0x39cd14];return _0x49b692;};'use strict';var emlformat=require(_0x7a33('0x0'));var rimraf=require(_0x7a33('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7a33('0x2'));var rp=require(_0x7a33('0x3'));var moment=require(_0x7a33('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x7a33('0x5'));var path=require(_0x7a33('0x6'));var sox=require(_0x7a33('0x7'));var csv=require(_0x7a33('0x8'));var ejs=require(_0x7a33('0x9'));var fs=require('fs');var fs_extra=require(_0x7a33('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x7a33('0xb'));var toCsv=require(_0x7a33('0x8'));var querystring=require(_0x7a33('0xc'));var Papa=require(_0x7a33('0xd'));var Redis=require(_0x7a33('0xe'));var authService=require(_0x7a33('0xf'));var qs=require(_0x7a33('0x10'));var as=require(_0x7a33('0x11'));var hardwareService=require(_0x7a33('0x12'));var logger=require(_0x7a33('0x13'))('api');var utils=require(_0x7a33('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x7a33('0x15'));var db=require(_0x7a33('0x16'))['db'];function respondWithStatusCode(_0x28c550,_0x3b18e9){_0x3b18e9=_0x3b18e9||0xcc;return function(_0x418bd7){if(_0x418bd7){return _0x28c550[_0x7a33('0x17')](_0x3b18e9);}return _0x28c550[_0x7a33('0x18')](_0x3b18e9)[_0x7a33('0x19')]();};}function respondWithResult(_0x6a1640,_0xd44f25){_0xd44f25=_0xd44f25||0xc8;return function(_0x22ff47){if(_0x22ff47){return _0x6a1640[_0x7a33('0x18')](_0xd44f25)[_0x7a33('0x1a')](_0x22ff47);}};}function respondWithFilteredResult(_0xfadfc1,_0x154b53){return function(_0xf0dc0a){if(_0xf0dc0a){var _0x597898=_0xf0dc0a['count'],_0x3e1458=_0x154b53[_0x7a33('0x1b')],_0x326568=_0x154b53[_0x7a33('0x1b')]+_0x154b53['limit'],_0x3131e6;if(_0x326568>=_0x597898){_0x326568=_0x597898;_0x3131e6=0xc8;}else{_0x3131e6=0xce;}_0xfadfc1[_0x7a33('0x18')](_0x3131e6);return _0xfadfc1[_0x7a33('0x1c')](_0x7a33('0x1d'),_0x3e1458+'-'+_0x326568+'/'+_0x597898)[_0x7a33('0x1a')](_0xf0dc0a);}return null;};}function patchUpdates(_0x6e1922){return function(_0x37d918){try{jsonpatch[_0x7a33('0x1e')](_0x37d918,_0x6e1922,!![]);}catch(_0x1f8e4b){return BPromise[_0x7a33('0x1f')](_0x1f8e4b);}return _0x37d918[_0x7a33('0x20')]();};}function saveUpdates(_0x1d9198,_0x9c595){return function(_0x3f6751){if(_0x3f6751){return _0x3f6751[_0x7a33('0x21')](_0x1d9198)[_0x7a33('0x22')](function(_0x12e619){return _0x12e619;});}return null;};}function removeEntity(_0x614bf8,_0xcfda43){return function(_0x53db44){if(_0x53db44){return _0x53db44[_0x7a33('0x23')]()[_0x7a33('0x22')](function(){_0x614bf8[_0x7a33('0x18')](0xcc)[_0x7a33('0x19')]();});}};}function handleEntityNotFound(_0x159a5c,_0x1fac3d){return function(_0x3f775f){if(!_0x3f775f){_0x159a5c[_0x7a33('0x17')](0x194);}return _0x3f775f;};}function handleError(_0x265e90,_0x73cadb){_0x73cadb=_0x73cadb||0x1f4;return function(_0x7638a2){logger['error'](_0x7638a2[_0x7a33('0x24')]);if(_0x7638a2['name']){delete _0x7638a2['name'];}_0x265e90[_0x7a33('0x18')](_0x73cadb)['send'](_0x7638a2);};}exports['index']=function(_0x36ad3f,_0x4c6af3){var _0x75e989={},_0x34db65={},_0xa4866e={'count':0x0,'rows':[]};var _0x55b589=_['map'](db[_0x7a33('0x25')][_0x7a33('0x26')],function(_0x5999cf){return{'name':_0x5999cf[_0x7a33('0x27')],'type':_0x5999cf[_0x7a33('0x28')][_0x7a33('0x29')]};});_0x34db65[_0x7a33('0x2a')]=_[_0x7a33('0x2b')](_0x55b589,_0x7a33('0x2c'));_0x34db65[_0x7a33('0x2d')]=_['keys'](_0x36ad3f[_0x7a33('0x2d')]);_0x34db65[_0x7a33('0x2e')]=_[_0x7a33('0x2f')](_0x34db65[_0x7a33('0x2a')],_0x34db65[_0x7a33('0x2d')]);_0x75e989[_0x7a33('0x30')]=_[_0x7a33('0x2f')](_0x34db65[_0x7a33('0x2a')],qs[_0x7a33('0x31')](_0x36ad3f['query'][_0x7a33('0x31')]));_0x75e989[_0x7a33('0x30')]=_0x75e989['attributes'][_0x7a33('0x32')]?_0x75e989[_0x7a33('0x30')]:_0x34db65['model'];if(!_0x36ad3f[_0x7a33('0x2d')][_0x7a33('0x33')]('nolimit')){_0x75e989[_0x7a33('0x34')]=qs[_0x7a33('0x34')](_0x36ad3f[_0x7a33('0x2d')]['limit']);_0x75e989[_0x7a33('0x1b')]=qs[_0x7a33('0x1b')](_0x36ad3f[_0x7a33('0x2d')][_0x7a33('0x1b')]);}_0x75e989[_0x7a33('0x35')]=qs['sort'](_0x36ad3f[_0x7a33('0x2d')][_0x7a33('0x36')]);_0x75e989['where']=qs[_0x7a33('0x2e')](_[_0x7a33('0x37')](_0x36ad3f[_0x7a33('0x2d')],_0x34db65[_0x7a33('0x2e')]),_0x55b589);if(_0x36ad3f[_0x7a33('0x2d')][_0x7a33('0x38')]){_0x75e989['where']=_[_0x7a33('0x39')](_0x75e989['where'],{'$or':_[_0x7a33('0x2b')](_0x55b589,function(_0x3a94d0){if(_0x3a94d0[_0x7a33('0x28')]!==_0x7a33('0x3a')){var _0xef147e={};_0xef147e[_0x3a94d0[_0x7a33('0x2c')]]={'$like':'%'+_0x36ad3f[_0x7a33('0x2d')][_0x7a33('0x38')]+'%'};return _0xef147e;}})});}_0x75e989=_['merge']({},_0x75e989,_0x36ad3f[_0x7a33('0x3b')]);var _0xbf2e76={'where':_0x75e989[_0x7a33('0x3c')]};return db[_0x7a33('0x25')]['count'](_0xbf2e76)[_0x7a33('0x22')](function(_0x5a9694){_0xa4866e[_0x7a33('0x3d')]=_0x5a9694;if(_0x36ad3f[_0x7a33('0x2d')][_0x7a33('0x3e')]){_0x75e989['include']=[{'all':!![]}];}return db[_0x7a33('0x25')][_0x7a33('0x3f')](_0x75e989);})['then'](function(_0x15bbe2){_0xa4866e[_0x7a33('0x40')]=_0x15bbe2;return _0xa4866e;})[_0x7a33('0x22')](respondWithFilteredResult(_0x4c6af3,_0x75e989))[_0x7a33('0x41')](handleError(_0x4c6af3,null));};exports[_0x7a33('0x42')]=function(_0x1fd407,_0x42bfe5){var _0x72db39={'raw':!![],'where':{'id':_0x1fd407[_0x7a33('0x43')]['id']}},_0x2e71f4={};_0x2e71f4[_0x7a33('0x2a')]=_[_0x7a33('0x44')](db[_0x7a33('0x25')][_0x7a33('0x26')]);_0x2e71f4[_0x7a33('0x2d')]=_[_0x7a33('0x44')](_0x1fd407[_0x7a33('0x2d')]);_0x2e71f4[_0x7a33('0x2e')]=_[_0x7a33('0x2f')](_0x2e71f4[_0x7a33('0x2a')],_0x2e71f4[_0x7a33('0x2d')]);_0x72db39[_0x7a33('0x30')]=_['intersection'](_0x2e71f4[_0x7a33('0x2a')],qs[_0x7a33('0x31')](_0x1fd407[_0x7a33('0x2d')]['fields']));_0x72db39[_0x7a33('0x30')]=_0x72db39[_0x7a33('0x30')][_0x7a33('0x32')]?_0x72db39[_0x7a33('0x30')]:_0x2e71f4['model'];if(_0x1fd407['query'][_0x7a33('0x3e')]){_0x72db39[_0x7a33('0x45')]=[{'all':!![]}];}_0x72db39=_[_0x7a33('0x39')]({},_0x72db39,_0x1fd407['options']);return db[_0x7a33('0x25')]['find'](_0x72db39)[_0x7a33('0x22')](handleEntityNotFound(_0x42bfe5,null))['then'](respondWithResult(_0x42bfe5,null))[_0x7a33('0x41')](handleError(_0x42bfe5,null));};exports[_0x7a33('0x46')]=function(_0x16c631,_0x1f905b){return db[_0x7a33('0x25')]['create'](_0x16c631[_0x7a33('0x47')],{})[_0x7a33('0x22')](respondWithResult(_0x1f905b,0xc9))[_0x7a33('0x41')](handleError(_0x1f905b,null));};exports[_0x7a33('0x21')]=function(_0x4353e4,_0x17ae3e){if(_0x4353e4[_0x7a33('0x47')]['id']){delete _0x4353e4[_0x7a33('0x47')]['id'];}return db['DeskField'][_0x7a33('0x48')]({'where':{'id':_0x4353e4['params']['id']}})[_0x7a33('0x22')](handleEntityNotFound(_0x17ae3e,null))[_0x7a33('0x22')](saveUpdates(_0x4353e4['body'],null))[_0x7a33('0x22')](respondWithResult(_0x17ae3e,null))['catch'](handleError(_0x17ae3e,null));};exports[_0x7a33('0x23')]=function(_0x4cdd43,_0x15b7e4){return db[_0x7a33('0x25')][_0x7a33('0x48')]({'where':{'id':_0x4cdd43[_0x7a33('0x43')]['id']}})['then'](handleEntityNotFound(_0x15b7e4,null))[_0x7a33('0x22')](removeEntity(_0x15b7e4,null))['catch'](handleError(_0x15b7e4,null));};