4070fbb473110290ec3af129230d07a6c9740bc9
[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 _0x553f=['create','body','update','find','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','path','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','count','set','apply','reject','save','then','destroy','error','stack','name','send','map','DeskField','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','include'];(function(_0x575d3b,_0x5a65ce){var _0x5905ea=function(_0x3f631c){while(--_0x3f631c){_0x575d3b['push'](_0x575d3b['shift']());}};_0x5905ea(++_0x5a65ce);}(_0x553f,0x1c0));var _0xf553=function(_0x455d91,_0x22b41a){_0x455d91=_0x455d91-0x0;var _0x41eedb=_0x553f[_0x455d91];return _0x41eedb;};'use strict';var emlformat=require(_0xf553('0x0'));var rimraf=require(_0xf553('0x1'));var zipdir=require(_0xf553('0x2'));var jsonpatch=require(_0xf553('0x3'));var rp=require(_0xf553('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf553('0x5'));var util=require('util');var path=require(_0xf553('0x6'));var sox=require(_0xf553('0x7'));var csv=require(_0xf553('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf553('0x9'));var _=require(_0xf553('0xa'));var squel=require(_0xf553('0xb'));var crypto=require('crypto');var jsforce=require(_0xf553('0xc'));var deskjs=require(_0xf553('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf553('0xe'));var authService=require(_0xf553('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xf553('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf553('0x11'))(_0xf553('0x12'));var utils=require('../../config/utils');var config=require(_0xf553('0x13'));var licenseUtil=require(_0xf553('0x14'));var db=require(_0xf553('0x15'))['db'];function respondWithStatusCode(_0x3a296c,_0x16be09){_0x16be09=_0x16be09||0xcc;return function(_0x15231e){if(_0x15231e){return _0x3a296c[_0xf553('0x16')](_0x16be09);}return _0x3a296c[_0xf553('0x17')](_0x16be09)[_0xf553('0x18')]();};}function respondWithResult(_0x154752,_0x49dc14){_0x49dc14=_0x49dc14||0xc8;return function(_0x275d32){if(_0x275d32){return _0x154752[_0xf553('0x17')](_0x49dc14)['json'](_0x275d32);}};}function respondWithFilteredResult(_0x32a01b,_0x12968c){return function(_0x2cef54){if(_0x2cef54){var _0x3197ea=typeof _0x12968c[_0xf553('0x19')]===_0xf553('0x1a')&&typeof _0x12968c['limit']===_0xf553('0x1a');var _0x264bc1=_0x2cef54[_0xf553('0x1b')];var _0x14ae9c=_0x3197ea?0x0:_0x12968c[_0xf553('0x19')];var _0x53aae0=_0x3197ea?_0x2cef54[_0xf553('0x1b')]:_0x12968c[_0xf553('0x19')]+_0x12968c['limit'];var _0x58bd9d;if(_0x53aae0>=_0x264bc1){_0x53aae0=_0x264bc1;_0x58bd9d=0xc8;}else{_0x58bd9d=0xce;}_0x32a01b[_0xf553('0x17')](_0x58bd9d);return _0x32a01b[_0xf553('0x1c')]('Content-Range',_0x14ae9c+'-'+_0x53aae0+'/'+_0x264bc1)['json'](_0x2cef54);}return null;};}function patchUpdates(_0x21c395){return function(_0x560033){try{jsonpatch[_0xf553('0x1d')](_0x560033,_0x21c395,!![]);}catch(_0x2b6f93){return BPromise[_0xf553('0x1e')](_0x2b6f93);}return _0x560033[_0xf553('0x1f')]();};}function saveUpdates(_0x2ad893,_0x242b60){return function(_0x487cdb){if(_0x487cdb){return _0x487cdb['update'](_0x2ad893)[_0xf553('0x20')](function(_0x12e0d1){return _0x12e0d1;});}return null;};}function removeEntity(_0x5d967c,_0x1921cf){return function(_0x585dfa){if(_0x585dfa){return _0x585dfa[_0xf553('0x21')]()[_0xf553('0x20')](function(){_0x5d967c[_0xf553('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1b9a57,_0x501be2){return function(_0x3a58b3){if(!_0x3a58b3){_0x1b9a57[_0xf553('0x16')](0x194);}return _0x3a58b3;};}function handleError(_0x5c4dd2,_0x466be4){_0x466be4=_0x466be4||0x1f4;return function(_0x532fa5){logger[_0xf553('0x22')](_0x532fa5[_0xf553('0x23')]);if(_0x532fa5['name']){delete _0x532fa5[_0xf553('0x24')];}_0x5c4dd2[_0xf553('0x17')](_0x466be4)[_0xf553('0x25')](_0x532fa5);};}exports['index']=function(_0x4749d0,_0x3e06e0){var _0x13b084={},_0x12075e={},_0x53145b={'count':0x0,'rows':[]};var _0x268e0e=_[_0xf553('0x26')](db[_0xf553('0x27')][_0xf553('0x28')],function(_0x31cafc){return{'name':_0x31cafc[_0xf553('0x29')],'type':_0x31cafc[_0xf553('0x2a')][_0xf553('0x2b')]};});_0x12075e['model']=_[_0xf553('0x26')](_0x268e0e,_0xf553('0x24'));_0x12075e['query']=_[_0xf553('0x2c')](_0x4749d0[_0xf553('0x2d')]);_0x12075e[_0xf553('0x2e')]=_[_0xf553('0x2f')](_0x12075e[_0xf553('0x30')],_0x12075e['query']);_0x13b084[_0xf553('0x31')]=_[_0xf553('0x2f')](_0x12075e[_0xf553('0x30')],qs[_0xf553('0x32')](_0x4749d0[_0xf553('0x2d')][_0xf553('0x32')]));_0x13b084[_0xf553('0x31')]=_0x13b084[_0xf553('0x31')][_0xf553('0x33')]?_0x13b084[_0xf553('0x31')]:_0x12075e[_0xf553('0x30')];if(!_0x4749d0['query'][_0xf553('0x34')](_0xf553('0x35'))){_0x13b084[_0xf553('0x36')]=qs[_0xf553('0x36')](_0x4749d0[_0xf553('0x2d')][_0xf553('0x36')]);_0x13b084[_0xf553('0x19')]=qs[_0xf553('0x19')](_0x4749d0[_0xf553('0x2d')]['offset']);}_0x13b084[_0xf553('0x37')]=qs[_0xf553('0x38')](_0x4749d0[_0xf553('0x2d')][_0xf553('0x38')]);_0x13b084['where']=qs[_0xf553('0x2e')](_[_0xf553('0x39')](_0x4749d0[_0xf553('0x2d')],_0x12075e[_0xf553('0x2e')]),_0x268e0e);if(_0x4749d0[_0xf553('0x2d')][_0xf553('0x3a')]){_0x13b084[_0xf553('0x3b')]=_[_0xf553('0x3c')](_0x13b084[_0xf553('0x3b')],{'$or':_[_0xf553('0x26')](_0x268e0e,function(_0x5a721c){if(_0x5a721c[_0xf553('0x2a')]!==_0xf553('0x3d')){var _0x266b9d={};_0x266b9d[_0x5a721c['name']]={'$like':'%'+_0x4749d0[_0xf553('0x2d')]['filter']+'%'};return _0x266b9d;}})});}_0x13b084=_[_0xf553('0x3c')]({},_0x13b084,_0x4749d0[_0xf553('0x3e')]);var _0x582931={'where':_0x13b084[_0xf553('0x3b')]};return db['DeskField'][_0xf553('0x1b')](_0x582931)[_0xf553('0x20')](function(_0x3ecc5d){_0x53145b[_0xf553('0x1b')]=_0x3ecc5d;if(_0x4749d0[_0xf553('0x2d')][_0xf553('0x3f')]){_0x13b084['include']=[{'all':!![]}];}return db[_0xf553('0x27')][_0xf553('0x40')](_0x13b084);})[_0xf553('0x20')](function(_0x294a60){_0x53145b[_0xf553('0x41')]=_0x294a60;return _0x53145b;})[_0xf553('0x20')](respondWithFilteredResult(_0x3e06e0,_0x13b084))[_0xf553('0x42')](handleError(_0x3e06e0,null));};exports[_0xf553('0x43')]=function(_0x5ab801,_0x222666){var _0x37480d={'raw':!![],'where':{'id':_0x5ab801[_0xf553('0x44')]['id']}},_0x28aaa4={};_0x28aaa4[_0xf553('0x30')]=_[_0xf553('0x2c')](db[_0xf553('0x27')]['rawAttributes']);_0x28aaa4[_0xf553('0x2d')]=_[_0xf553('0x2c')](_0x5ab801['query']);_0x28aaa4[_0xf553('0x2e')]=_['intersection'](_0x28aaa4[_0xf553('0x30')],_0x28aaa4[_0xf553('0x2d')]);_0x37480d[_0xf553('0x31')]=_[_0xf553('0x2f')](_0x28aaa4[_0xf553('0x30')],qs[_0xf553('0x32')](_0x5ab801[_0xf553('0x2d')][_0xf553('0x32')]));_0x37480d[_0xf553('0x31')]=_0x37480d[_0xf553('0x31')][_0xf553('0x33')]?_0x37480d[_0xf553('0x31')]:_0x28aaa4['model'];if(_0x5ab801[_0xf553('0x2d')][_0xf553('0x3f')]){_0x37480d[_0xf553('0x45')]=[{'all':!![]}];}_0x37480d=_[_0xf553('0x3c')]({},_0x37480d,_0x5ab801['options']);return db[_0xf553('0x27')]['find'](_0x37480d)[_0xf553('0x20')](handleEntityNotFound(_0x222666,null))[_0xf553('0x20')](respondWithResult(_0x222666,null))['catch'](handleError(_0x222666,null));};exports[_0xf553('0x46')]=function(_0x4d2e2e,_0x556d4e){return db[_0xf553('0x27')][_0xf553('0x46')](_0x4d2e2e[_0xf553('0x47')],{})[_0xf553('0x20')](respondWithResult(_0x556d4e,0xc9))['catch'](handleError(_0x556d4e,null));};exports[_0xf553('0x48')]=function(_0x2adae9,_0x41bbc5){if(_0x2adae9[_0xf553('0x47')]['id']){delete _0x2adae9['body']['id'];}return db[_0xf553('0x27')]['find']({'where':{'id':_0x2adae9[_0xf553('0x44')]['id']}})[_0xf553('0x20')](handleEntityNotFound(_0x41bbc5,null))['then'](saveUpdates(_0x2adae9['body'],null))['then'](respondWithResult(_0x41bbc5,null))[_0xf553('0x42')](handleError(_0x41bbc5,null));};exports[_0xf553('0x21')]=function(_0x1f04a5,_0x17a7e3){return db[_0xf553('0x27')][_0xf553('0x49')]({'where':{'id':_0x1f04a5['params']['id']}})[_0xf553('0x20')](handleEntityNotFound(_0x17a7e3,null))[_0xf553('0x20')](removeEntity(_0x17a7e3,null))['catch'](handleError(_0x17a7e3,null));};