1bace445c90e958f029b5560835112933318dd03
[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 _0xa142=['include','rows','show','catch','create','body','find','params','html-pdf','eml-format','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','count','offset','limit','set','Content-Range','save','then','destroy','error','stack','name','index','map','DeskField','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','where','pick','filter','merge','options','includeAll'];(function(_0x7b301,_0x2276d9){var _0x143f22=function(_0x14f9c4){while(--_0x14f9c4){_0x7b301['push'](_0x7b301['shift']());}};_0x143f22(++_0x2276d9);}(_0xa142,0x11c));var _0x2a14=function(_0x1d1918,_0x9b060b){_0x1d1918=_0x1d1918-0x0;var _0x40242b=_0xa142[_0x1d1918];return _0x40242b;};'use strict';var pdf=require(_0x2a14('0x0'));var emlformat=require(_0x2a14('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x2a14('0x2'));var BPromise=require(_0x2a14('0x3'));var Mustache=require(_0x2a14('0x4'));var util=require(_0x2a14('0x5'));var path=require(_0x2a14('0x6'));var sox=require(_0x2a14('0x7'));var csv=require(_0x2a14('0x8'));var ejs=require(_0x2a14('0x9'));var fs=require('fs');var _=require(_0x2a14('0xa'));var squel=require(_0x2a14('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x2a14('0xc'));var toCsv=require('to-csv');var querystring=require(_0x2a14('0xd'));var Papa=require(_0x2a14('0xe'));var Redis=require(_0x2a14('0xf'));var authService=require(_0x2a14('0x10'));var qs=require(_0x2a14('0x11'));var as=require(_0x2a14('0x12'));var hardwareService=require(_0x2a14('0x13'));var logger=require('../../config/logger')(_0x2a14('0x14'));var utils=require(_0x2a14('0x15'));var config=require(_0x2a14('0x16'));var licenseUtil=require(_0x2a14('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xca5c26,_0x4716b3){_0x4716b3=_0x4716b3||0xcc;return function(_0x5d1a29){if(_0x5d1a29){return _0xca5c26[_0x2a14('0x18')](_0x4716b3);}return _0xca5c26['status'](_0x4716b3)[_0x2a14('0x19')]();};}function respondWithResult(_0x416850,_0x36080f){_0x36080f=_0x36080f||0xc8;return function(_0x4e985d){if(_0x4e985d){return _0x416850[_0x2a14('0x1a')](_0x36080f)[_0x2a14('0x1b')](_0x4e985d);}};}function respondWithFilteredResult(_0x170bb5,_0x36e10b){return function(_0x262e3a){if(_0x262e3a){var _0x200409=_0x262e3a[_0x2a14('0x1c')],_0x34eca6=_0x36e10b[_0x2a14('0x1d')],_0x2be69e=_0x36e10b[_0x2a14('0x1d')]+_0x36e10b[_0x2a14('0x1e')],_0x13f101;if(_0x2be69e>=_0x200409){_0x2be69e=_0x200409;_0x13f101=0xc8;}else{_0x13f101=0xce;}_0x170bb5['status'](_0x13f101);return _0x170bb5[_0x2a14('0x1f')](_0x2a14('0x20'),_0x34eca6+'-'+_0x2be69e+'/'+_0x200409)[_0x2a14('0x1b')](_0x262e3a);}return null;};}function patchUpdates(_0x48ae87){return function(_0x364614){try{jsonpatch['apply'](_0x364614,_0x48ae87,!![]);}catch(_0x1cf4ea){return BPromise['reject'](_0x1cf4ea);}return _0x364614[_0x2a14('0x21')]();};}function saveUpdates(_0x547f65,_0x1ef7e7){return function(_0x268a27){if(_0x268a27){return _0x268a27['update'](_0x547f65)[_0x2a14('0x22')](function(_0x49bca1){return _0x49bca1;});}return null;};}function removeEntity(_0x135563,_0x1b54e3){return function(_0x166cf8){if(_0x166cf8){return _0x166cf8[_0x2a14('0x23')]()[_0x2a14('0x22')](function(){_0x135563[_0x2a14('0x1a')](0xcc)[_0x2a14('0x19')]();});}};}function handleEntityNotFound(_0xbc289e,_0x128e15){return function(_0x51efb5){if(!_0x51efb5){_0xbc289e['sendStatus'](0x194);}return _0x51efb5;};}function handleError(_0x13da6b,_0x1a332b){_0x1a332b=_0x1a332b||0x1f4;return function(_0x1fc334){logger[_0x2a14('0x24')](_0x1fc334[_0x2a14('0x25')]);if(_0x1fc334['name']){delete _0x1fc334[_0x2a14('0x26')];}_0x13da6b[_0x2a14('0x1a')](_0x1a332b)['send'](_0x1fc334);};}exports[_0x2a14('0x27')]=function(_0x542f8c,_0x29623d){var _0x1b47d6={},_0x4ccc95={},_0x596af5={'count':0x0,'rows':[]};var _0x4a2018=_[_0x2a14('0x28')](db[_0x2a14('0x29')]['rawAttributes'],function(_0x3f7623){return{'name':_0x3f7623[_0x2a14('0x2a')],'type':_0x3f7623[_0x2a14('0x2b')]['key']};});_0x4ccc95[_0x2a14('0x2c')]=_[_0x2a14('0x28')](_0x4a2018,_0x2a14('0x26'));_0x4ccc95[_0x2a14('0x2d')]=_[_0x2a14('0x2e')](_0x542f8c[_0x2a14('0x2d')]);_0x4ccc95[_0x2a14('0x2f')]=_[_0x2a14('0x30')](_0x4ccc95[_0x2a14('0x2c')],_0x4ccc95[_0x2a14('0x2d')]);_0x1b47d6[_0x2a14('0x31')]=_[_0x2a14('0x30')](_0x4ccc95[_0x2a14('0x2c')],qs[_0x2a14('0x32')](_0x542f8c[_0x2a14('0x2d')][_0x2a14('0x32')]));_0x1b47d6[_0x2a14('0x31')]=_0x1b47d6[_0x2a14('0x31')][_0x2a14('0x33')]?_0x1b47d6[_0x2a14('0x31')]:_0x4ccc95[_0x2a14('0x2c')];if(!_0x542f8c['query'][_0x2a14('0x34')](_0x2a14('0x35'))){_0x1b47d6[_0x2a14('0x1e')]=qs[_0x2a14('0x1e')](_0x542f8c[_0x2a14('0x2d')][_0x2a14('0x1e')]);_0x1b47d6['offset']=qs[_0x2a14('0x1d')](_0x542f8c['query']['offset']);}_0x1b47d6[_0x2a14('0x36')]=qs['sort'](_0x542f8c[_0x2a14('0x2d')]['sort']);_0x1b47d6[_0x2a14('0x37')]=qs[_0x2a14('0x2f')](_[_0x2a14('0x38')](_0x542f8c[_0x2a14('0x2d')],_0x4ccc95[_0x2a14('0x2f')]),_0x4a2018);if(_0x542f8c[_0x2a14('0x2d')][_0x2a14('0x39')]){_0x1b47d6[_0x2a14('0x37')]=_[_0x2a14('0x3a')](_0x1b47d6[_0x2a14('0x37')],{'$or':_[_0x2a14('0x28')](_0x4a2018,function(_0x5393c7){if(_0x5393c7[_0x2a14('0x2b')]!=='VIRTUAL'){var _0x1ce261={};_0x1ce261[_0x5393c7['name']]={'$like':'%'+_0x542f8c['query'][_0x2a14('0x39')]+'%'};return _0x1ce261;}})});}_0x1b47d6=_[_0x2a14('0x3a')]({},_0x1b47d6,_0x542f8c[_0x2a14('0x3b')]);var _0x5480a6={'where':_0x1b47d6[_0x2a14('0x37')]};return db[_0x2a14('0x29')][_0x2a14('0x1c')](_0x5480a6)[_0x2a14('0x22')](function(_0x505fed){_0x596af5[_0x2a14('0x1c')]=_0x505fed;if(_0x542f8c[_0x2a14('0x2d')][_0x2a14('0x3c')]){_0x1b47d6[_0x2a14('0x3d')]=[{'all':!![]}];}return db['DeskField']['findAll'](_0x1b47d6);})['then'](function(_0x2f2aa8){_0x596af5[_0x2a14('0x3e')]=_0x2f2aa8;return _0x596af5;})[_0x2a14('0x22')](respondWithFilteredResult(_0x29623d,_0x1b47d6))['catch'](handleError(_0x29623d,null));};exports[_0x2a14('0x3f')]=function(_0x137331,_0x3211a8){var _0x1fdfab={'raw':!![],'where':{'id':_0x137331['params']['id']}},_0x271560={};_0x271560[_0x2a14('0x2c')]=_[_0x2a14('0x2e')](db['DeskField']['rawAttributes']);_0x271560['query']=_[_0x2a14('0x2e')](_0x137331['query']);_0x271560[_0x2a14('0x2f')]=_['intersection'](_0x271560[_0x2a14('0x2c')],_0x271560[_0x2a14('0x2d')]);_0x1fdfab[_0x2a14('0x31')]=_['intersection'](_0x271560['model'],qs['fields'](_0x137331['query'][_0x2a14('0x32')]));_0x1fdfab[_0x2a14('0x31')]=_0x1fdfab[_0x2a14('0x31')][_0x2a14('0x33')]?_0x1fdfab[_0x2a14('0x31')]:_0x271560[_0x2a14('0x2c')];if(_0x137331['query'][_0x2a14('0x3c')]){_0x1fdfab[_0x2a14('0x3d')]=[{'all':!![]}];}_0x1fdfab=_[_0x2a14('0x3a')]({},_0x1fdfab,_0x137331[_0x2a14('0x3b')]);return db[_0x2a14('0x29')]['find'](_0x1fdfab)[_0x2a14('0x22')](handleEntityNotFound(_0x3211a8,null))['then'](respondWithResult(_0x3211a8,null))[_0x2a14('0x40')](handleError(_0x3211a8,null));};exports[_0x2a14('0x41')]=function(_0x22fc39,_0x3088aa){return db['DeskField'][_0x2a14('0x41')](_0x22fc39[_0x2a14('0x42')],{})[_0x2a14('0x22')](respondWithResult(_0x3088aa,0xc9))['catch'](handleError(_0x3088aa,null));};exports['update']=function(_0xd4c33,_0x7d1c65){if(_0xd4c33[_0x2a14('0x42')]['id']){delete _0xd4c33[_0x2a14('0x42')]['id'];}return db[_0x2a14('0x29')][_0x2a14('0x43')]({'where':{'id':_0xd4c33['params']['id']}})['then'](handleEntityNotFound(_0x7d1c65,null))[_0x2a14('0x22')](saveUpdates(_0xd4c33['body'],null))[_0x2a14('0x22')](respondWithResult(_0x7d1c65,null))['catch'](handleError(_0x7d1c65,null));};exports['destroy']=function(_0x1cea1c,_0xc2b34b){return db[_0x2a14('0x29')][_0x2a14('0x43')]({'where':{'id':_0x1cea1c[_0x2a14('0x44')]['id']}})['then'](handleEntityNotFound(_0xc2b34b,null))[_0x2a14('0x22')](removeEntity(_0xc2b34b,null))[_0x2a14('0x40')](handleError(_0xc2b34b,null));};