Built motion from commit 25580385.|2.6.2
[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 _0x35f5=['index','rawAttributes','fieldName','type','map','query','keys','filters','model','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','DeskField','includeAll','findAll','rows','show','include','find','catch','create','body','params','eml-format','zip-dir','fast-json-patch','request-promise','moment','path','sox','ejs','lodash','squel','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','json','undefined','count','offset','limit','status','set','Content-Range','apply','update','then','destroy','stack','name','send'];(function(_0x45a9ec,_0x125a96){var _0x546581=function(_0x2dece0){while(--_0x2dece0){_0x45a9ec['push'](_0x45a9ec['shift']());}};_0x546581(++_0x125a96);}(_0x35f5,0x100));var _0x535f=function(_0x2390bd,_0x212fbd){_0x2390bd=_0x2390bd-0x0;var _0x3a969d=_0x35f5[_0x2390bd];return _0x3a969d;};'use strict';var emlformat=require(_0x535f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x535f('0x1'));var jsonpatch=require(_0x535f('0x2'));var rp=require(_0x535f('0x3'));var moment=require(_0x535f('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x535f('0x5'));var sox=require(_0x535f('0x6'));var csv=require('to-csv');var ejs=require(_0x535f('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x535f('0x8'));var squel=require(_0x535f('0x9'));var crypto=require('crypto');var jsforce=require(_0x535f('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x535f('0xb'));var querystring=require(_0x535f('0xc'));var Papa=require(_0x535f('0xd'));var Redis=require(_0x535f('0xe'));var authService=require(_0x535f('0xf'));var qs=require(_0x535f('0x10'));var as=require(_0x535f('0x11'));var hardwareService=require(_0x535f('0x12'));var logger=require('../../config/logger')(_0x535f('0x13'));var utils=require(_0x535f('0x14'));var config=require(_0x535f('0x15'));var licenseUtil=require(_0x535f('0x16'));var db=require(_0x535f('0x17'))['db'];function respondWithStatusCode(_0x2d24cf,_0x54a095){_0x54a095=_0x54a095||0xcc;return function(_0x1cd819){if(_0x1cd819){return _0x2d24cf['sendStatus'](_0x54a095);}return _0x2d24cf['status'](_0x54a095)[_0x535f('0x18')]();};}function respondWithResult(_0x465521,_0x423f95){_0x423f95=_0x423f95||0xc8;return function(_0x47e080){if(_0x47e080){return _0x465521['status'](_0x423f95)[_0x535f('0x19')](_0x47e080);}};}function respondWithFilteredResult(_0x4a97fc,_0x3119e1){return function(_0x3ea018){if(_0x3ea018){var _0x592a67=typeof _0x3119e1['offset']===_0x535f('0x1a')&&typeof _0x3119e1['limit']===_0x535f('0x1a');var _0xa6c20b=_0x3ea018[_0x535f('0x1b')];var _0x16f614=_0x592a67?0x0:_0x3119e1[_0x535f('0x1c')];var _0x3b4f3f=_0x592a67?_0x3ea018[_0x535f('0x1b')]:_0x3119e1[_0x535f('0x1c')]+_0x3119e1[_0x535f('0x1d')];var _0x20655c;if(_0x3b4f3f>=_0xa6c20b){_0x3b4f3f=_0xa6c20b;_0x20655c=0xc8;}else{_0x20655c=0xce;}_0x4a97fc[_0x535f('0x1e')](_0x20655c);return _0x4a97fc[_0x535f('0x1f')](_0x535f('0x20'),_0x16f614+'-'+_0x3b4f3f+'/'+_0xa6c20b)[_0x535f('0x19')](_0x3ea018);}return null;};}function patchUpdates(_0xa59e26){return function(_0xe13d3e){try{jsonpatch[_0x535f('0x21')](_0xe13d3e,_0xa59e26,!![]);}catch(_0x1a8623){return BPromise['reject'](_0x1a8623);}return _0xe13d3e['save']();};}function saveUpdates(_0x2b3297,_0x5f2b70){return function(_0x1f3938){if(_0x1f3938){return _0x1f3938[_0x535f('0x22')](_0x2b3297)[_0x535f('0x23')](function(_0x2f02b1){return _0x2f02b1;});}return null;};}function removeEntity(_0x362a78,_0x556512){return function(_0x45eb4b){if(_0x45eb4b){return _0x45eb4b[_0x535f('0x24')]()['then'](function(){_0x362a78[_0x535f('0x1e')](0xcc)[_0x535f('0x18')]();});}};}function handleEntityNotFound(_0xa6cf8,_0x293e05){return function(_0x49de3a){if(!_0x49de3a){_0xa6cf8['sendStatus'](0x194);}return _0x49de3a;};}function handleError(_0x43a3e1,_0x573ef0){_0x573ef0=_0x573ef0||0x1f4;return function(_0x1896e8){logger['error'](_0x1896e8[_0x535f('0x25')]);if(_0x1896e8[_0x535f('0x26')]){delete _0x1896e8[_0x535f('0x26')];}_0x43a3e1['status'](_0x573ef0)[_0x535f('0x27')](_0x1896e8);};}exports[_0x535f('0x28')]=function(_0xc8b843,_0x5105ee){var _0x122b7d={},_0x38b464={},_0x285b9d={'count':0x0,'rows':[]};var _0x23c5e4=_['map'](db['DeskField'][_0x535f('0x29')],function(_0x2af771){return{'name':_0x2af771[_0x535f('0x2a')],'type':_0x2af771[_0x535f('0x2b')]['key']};});_0x38b464['model']=_[_0x535f('0x2c')](_0x23c5e4,'name');_0x38b464[_0x535f('0x2d')]=_[_0x535f('0x2e')](_0xc8b843[_0x535f('0x2d')]);_0x38b464[_0x535f('0x2f')]=_['intersection'](_0x38b464[_0x535f('0x30')],_0x38b464[_0x535f('0x2d')]);_0x122b7d[_0x535f('0x31')]=_[_0x535f('0x32')](_0x38b464[_0x535f('0x30')],qs[_0x535f('0x33')](_0xc8b843[_0x535f('0x2d')][_0x535f('0x33')]));_0x122b7d[_0x535f('0x31')]=_0x122b7d[_0x535f('0x31')][_0x535f('0x34')]?_0x122b7d[_0x535f('0x31')]:_0x38b464[_0x535f('0x30')];if(!_0xc8b843[_0x535f('0x2d')][_0x535f('0x35')](_0x535f('0x36'))){_0x122b7d[_0x535f('0x1d')]=qs[_0x535f('0x1d')](_0xc8b843[_0x535f('0x2d')][_0x535f('0x1d')]);_0x122b7d['offset']=qs[_0x535f('0x1c')](_0xc8b843[_0x535f('0x2d')][_0x535f('0x1c')]);}_0x122b7d[_0x535f('0x37')]=qs['sort'](_0xc8b843[_0x535f('0x2d')][_0x535f('0x38')]);_0x122b7d[_0x535f('0x39')]=qs[_0x535f('0x2f')](_[_0x535f('0x3a')](_0xc8b843[_0x535f('0x2d')],_0x38b464[_0x535f('0x2f')]),_0x23c5e4);if(_0xc8b843[_0x535f('0x2d')][_0x535f('0x3b')]){_0x122b7d[_0x535f('0x39')]=_[_0x535f('0x3c')](_0x122b7d[_0x535f('0x39')],{'$or':_[_0x535f('0x2c')](_0x23c5e4,function(_0xd7f9e){if(_0xd7f9e['type']!==_0x535f('0x3d')){var _0x46a825={};_0x46a825[_0xd7f9e[_0x535f('0x26')]]={'$like':'%'+_0xc8b843[_0x535f('0x2d')][_0x535f('0x3b')]+'%'};return _0x46a825;}})});}_0x122b7d=_[_0x535f('0x3c')]({},_0x122b7d,_0xc8b843[_0x535f('0x3e')]);var _0x3e3d4d={'where':_0x122b7d[_0x535f('0x39')]};return db[_0x535f('0x3f')][_0x535f('0x1b')](_0x3e3d4d)[_0x535f('0x23')](function(_0x1b7d05){_0x285b9d[_0x535f('0x1b')]=_0x1b7d05;if(_0xc8b843['query'][_0x535f('0x40')]){_0x122b7d['include']=[{'all':!![]}];}return db['DeskField'][_0x535f('0x41')](_0x122b7d);})[_0x535f('0x23')](function(_0x534370){_0x285b9d[_0x535f('0x42')]=_0x534370;return _0x285b9d;})[_0x535f('0x23')](respondWithFilteredResult(_0x5105ee,_0x122b7d))['catch'](handleError(_0x5105ee,null));};exports[_0x535f('0x43')]=function(_0x59dec0,_0x4bf123){var _0x53fc90={'raw':!![],'where':{'id':_0x59dec0['params']['id']}},_0x9868e5={};_0x9868e5['model']=_['keys'](db[_0x535f('0x3f')][_0x535f('0x29')]);_0x9868e5[_0x535f('0x2d')]=_[_0x535f('0x2e')](_0x59dec0[_0x535f('0x2d')]);_0x9868e5[_0x535f('0x2f')]=_['intersection'](_0x9868e5['model'],_0x9868e5['query']);_0x53fc90[_0x535f('0x31')]=_[_0x535f('0x32')](_0x9868e5['model'],qs[_0x535f('0x33')](_0x59dec0[_0x535f('0x2d')][_0x535f('0x33')]));_0x53fc90[_0x535f('0x31')]=_0x53fc90[_0x535f('0x31')][_0x535f('0x34')]?_0x53fc90[_0x535f('0x31')]:_0x9868e5[_0x535f('0x30')];if(_0x59dec0[_0x535f('0x2d')]['includeAll']){_0x53fc90[_0x535f('0x44')]=[{'all':!![]}];}_0x53fc90=_['merge']({},_0x53fc90,_0x59dec0[_0x535f('0x3e')]);return db['DeskField'][_0x535f('0x45')](_0x53fc90)[_0x535f('0x23')](handleEntityNotFound(_0x4bf123,null))['then'](respondWithResult(_0x4bf123,null))[_0x535f('0x46')](handleError(_0x4bf123,null));};exports['create']=function(_0x438b9a,_0x3f491d){return db[_0x535f('0x3f')][_0x535f('0x47')](_0x438b9a[_0x535f('0x48')],{})[_0x535f('0x23')](respondWithResult(_0x3f491d,0xc9))['catch'](handleError(_0x3f491d,null));};exports[_0x535f('0x22')]=function(_0x51f4d4,_0x517623){if(_0x51f4d4['body']['id']){delete _0x51f4d4['body']['id'];}return db['DeskField']['find']({'where':{'id':_0x51f4d4[_0x535f('0x49')]['id']}})['then'](handleEntityNotFound(_0x517623,null))['then'](saveUpdates(_0x51f4d4['body'],null))[_0x535f('0x23')](respondWithResult(_0x517623,null))[_0x535f('0x46')](handleError(_0x517623,null));};exports[_0x535f('0x24')]=function(_0x21d73f,_0x33e338){return db[_0x535f('0x3f')]['find']({'where':{'id':_0x21d73f['params']['id']}})[_0x535f('0x23')](handleEntityNotFound(_0x33e338,null))[_0x535f('0x23')](removeEntity(_0x33e338,null))['catch'](handleError(_0x33e338,null));};