890b16750444a8665de3fee2cb4d503df1f915f2
[motion2.git] / server / api / squareProject / squareProject.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 _0x7f20=['autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','stringify','production','lodash','ioredis','../../components/parsers/qs','../../config/logger','../../mysqldb','redis','socket.io-emitter','./squareProject.socket','register','status','json','offset','undefined','count','limit','set','Content-Range','update','then','destroy','get','SquareProjects','publish','agi','end','sendStatus','error','stack','name','send','index','map','SquareProject','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','filter','includeAll','include','show','params','options','find','catch','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId'];(function(_0x27b588,_0x176012){var _0x1ed0c0=function(_0x5b8f06){while(--_0x5b8f06){_0x27b588['push'](_0x27b588['shift']());}};_0x1ed0c0(++_0x176012);}(_0x7f20,0x163));var _0x07f2=function(_0x263402,_0x9e792e){_0x263402=_0x263402-0x0;var _0x4b886b=_0x7f20[_0x263402];return _0x4b886b;};'use strict';var _=require(_0x07f2('0x0'));var Redis=require(_0x07f2('0x1'));var qs=require(_0x07f2('0x2'));var logger=require(_0x07f2('0x3'))('api');var config=require('../../config/environment');var db=require(_0x07f2('0x4'))['db'];config[_0x07f2('0x5')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x07f2('0x6'))(new Redis(config[_0x07f2('0x5')]));require(_0x07f2('0x7'))[_0x07f2('0x8')](socket);function respondWithResult(_0x3cbb03,_0x124ec5){_0x124ec5=_0x124ec5||0xc8;return function(_0x10b8df){if(_0x10b8df){return _0x3cbb03[_0x07f2('0x9')](_0x124ec5)[_0x07f2('0xa')](_0x10b8df);}};}function respondWithFilteredResult(_0x97ee16,_0xee98d0){return function(_0x3cc594){if(_0x3cc594){var _0x5473c9=typeof _0xee98d0[_0x07f2('0xb')]===_0x07f2('0xc')&&typeof _0xee98d0['limit']===_0x07f2('0xc');var _0x30fac2=_0x3cc594['count'];var _0x33b3b9=_0x5473c9?0x0:_0xee98d0[_0x07f2('0xb')];var _0x58423c=_0x5473c9?_0x3cc594[_0x07f2('0xd')]:_0xee98d0[_0x07f2('0xb')]+_0xee98d0[_0x07f2('0xe')];var _0x2a8995;if(_0x58423c>=_0x30fac2){_0x58423c=_0x30fac2;_0x2a8995=0xc8;}else{_0x2a8995=0xce;}_0x97ee16[_0x07f2('0x9')](_0x2a8995);return _0x97ee16[_0x07f2('0xf')](_0x07f2('0x10'),_0x33b3b9+'-'+_0x58423c+'/'+_0x30fac2)[_0x07f2('0xa')](_0x3cc594);}return null;};}function saveUpdates(_0xcc365f){return function(_0x1fda3b){if(_0x1fda3b){return _0x1fda3b[_0x07f2('0x11')](_0xcc365f)[_0x07f2('0x12')](function(_0x3f8df8){return _0x3f8df8;});}return null;};}function removeEntity(_0x51cb6a){return function(_0xda2131){if(_0xda2131){return _0xda2131[_0x07f2('0x13')]()[_0x07f2('0x12')](function(){var _0x10125f=_0xda2131[_0x07f2('0x14')]({'plain':!![]});var _0x4bca24=_0x07f2('0x15');return db['UserProfileResource'][_0x07f2('0x13')]({'where':{'type':_0x4bca24,'resourceId':_0x10125f['id']}})[_0x07f2('0x12')](function(){return _0xda2131;});})[_0x07f2('0x12')](function(){var _0x1b2d36=new Redis(config[_0x07f2('0x5')]);_0x1b2d36[_0x07f2('0x16')](_0x07f2('0x17'),JSON['stringify']({'id':_0xda2131['id'],'deleted':!![]}));})[_0x07f2('0x12')](function(){_0x51cb6a[_0x07f2('0x9')](0xcc)[_0x07f2('0x18')]();});}};}function handleEntityNotFound(_0x17e1ad){return function(_0x190bba){if(!_0x190bba){_0x17e1ad[_0x07f2('0x19')](0x194);}return _0x190bba;};}function handleError(_0x5bb4d8,_0x1195f6){_0x1195f6=_0x1195f6||0x1f4;return function(_0x91058f){logger[_0x07f2('0x1a')](_0x91058f[_0x07f2('0x1b')]);if(_0x91058f[_0x07f2('0x1c')]){delete _0x91058f[_0x07f2('0x1c')];}_0x5bb4d8['status'](_0x1195f6)[_0x07f2('0x1d')](_0x91058f);};}exports[_0x07f2('0x1e')]=function(_0xaa52,_0x5668ec){var _0xa264d6={},_0xcae913={},_0x5c12c9={'count':0x0,'rows':[]};var _0x333db5=_[_0x07f2('0x1f')](db[_0x07f2('0x20')][_0x07f2('0x21')],function(_0x286d1c){return{'name':_0x286d1c[_0x07f2('0x22')],'type':_0x286d1c['type'][_0x07f2('0x23')]};});_0xcae913[_0x07f2('0x24')]=_[_0x07f2('0x1f')](_0x333db5,_0x07f2('0x1c'));_0xcae913['query']=_[_0x07f2('0x25')](_0xaa52[_0x07f2('0x26')]);_0xcae913[_0x07f2('0x27')]=_[_0x07f2('0x28')](_0xcae913[_0x07f2('0x24')],_0xcae913['query']);_0xa264d6[_0x07f2('0x29')]=_[_0x07f2('0x28')](_0xcae913[_0x07f2('0x24')],qs['fields'](_0xaa52['query'][_0x07f2('0x2a')]));_0xa264d6[_0x07f2('0x29')]=_0xa264d6[_0x07f2('0x29')][_0x07f2('0x2b')]?_0xa264d6[_0x07f2('0x29')]:_0xcae913['model'];if(!_0xaa52['query'][_0x07f2('0x2c')]('nolimit')){_0xa264d6[_0x07f2('0xe')]=qs[_0x07f2('0xe')](_0xaa52[_0x07f2('0x26')][_0x07f2('0xe')]);_0xa264d6[_0x07f2('0xb')]=qs[_0x07f2('0xb')](_0xaa52['query'][_0x07f2('0xb')]);}_0xa264d6[_0x07f2('0x2d')]=qs[_0x07f2('0x2e')](_0xaa52[_0x07f2('0x26')][_0x07f2('0x2e')]);_0xa264d6[_0x07f2('0x2f')]=qs[_0x07f2('0x27')](_[_0x07f2('0x30')](_0xaa52['query'],_0xcae913['filters']),_0x333db5);if(_0xaa52[_0x07f2('0x26')]['filter']){_0xa264d6['where']=_[_0x07f2('0x31')](_0xa264d6[_0x07f2('0x2f')],{'$or':_[_0x07f2('0x1f')](_0x333db5,function(_0x2d4700){if(_0x2d4700['type']!==_0x07f2('0x32')){var _0x25cc8b={};_0x25cc8b[_0x2d4700[_0x07f2('0x1c')]]={'$like':'%'+_0xaa52[_0x07f2('0x26')][_0x07f2('0x33')]+'%'};return _0x25cc8b;}})});}_0xa264d6=_['merge']({},_0xa264d6,_0xaa52['options']);var _0x73539f={'where':_0xa264d6['where']};return db['SquareProject']['count'](_0x73539f)[_0x07f2('0x12')](function(_0x5527e2){_0x5c12c9[_0x07f2('0xd')]=_0x5527e2;if(_0xaa52[_0x07f2('0x26')][_0x07f2('0x34')]){_0xa264d6[_0x07f2('0x35')]=[{'all':!![]}];}return db[_0x07f2('0x20')]['findAll'](_0xa264d6);})[_0x07f2('0x12')](function(_0x52d974){_0x5c12c9['rows']=_0x52d974;return _0x5c12c9;})[_0x07f2('0x12')](respondWithFilteredResult(_0x5668ec,_0xa264d6))['catch'](handleError(_0x5668ec,null));};exports[_0x07f2('0x36')]=function(_0x11670d,_0x24ae49){var _0x40cdee={'raw':![],'where':{'id':_0x11670d[_0x07f2('0x37')]['id']}},_0x549ab4={};_0x549ab4[_0x07f2('0x24')]=_[_0x07f2('0x25')](db[_0x07f2('0x20')][_0x07f2('0x21')]);_0x549ab4[_0x07f2('0x26')]=_['keys'](_0x11670d[_0x07f2('0x26')]);_0x549ab4[_0x07f2('0x27')]=_[_0x07f2('0x28')](_0x549ab4[_0x07f2('0x24')],_0x549ab4[_0x07f2('0x26')]);_0x40cdee[_0x07f2('0x29')]=_['intersection'](_0x549ab4['model'],qs[_0x07f2('0x2a')](_0x11670d['query']['fields']));_0x40cdee['attributes']=_0x40cdee[_0x07f2('0x29')][_0x07f2('0x2b')]?_0x40cdee[_0x07f2('0x29')]:_0x549ab4[_0x07f2('0x24')];if(_0x11670d[_0x07f2('0x26')][_0x07f2('0x34')]){_0x40cdee[_0x07f2('0x35')]=[{'all':!![]}];}_0x40cdee=_[_0x07f2('0x31')]({},_0x40cdee,_0x11670d[_0x07f2('0x38')]);return db[_0x07f2('0x20')][_0x07f2('0x39')](_0x40cdee)[_0x07f2('0x12')](handleEntityNotFound(_0x24ae49,null))[_0x07f2('0x12')](respondWithResult(_0x24ae49,null))[_0x07f2('0x3a')](handleError(_0x24ae49,null));};exports['create']=function(_0x23f524,_0x4b435c){return db[_0x07f2('0x20')]['create'](_0x23f524[_0x07f2('0x3b')],{})['then'](function(_0x3adf66){var _0x3eff96=_0x23f524['user'][_0x07f2('0x14')]({'plain':!![]});if(!_0x3eff96)throw new Error(_0x07f2('0x3c'));if(_0x3eff96[_0x07f2('0x3d')]===_0x07f2('0x3e')){var _0x3a96ef=_0x3adf66[_0x07f2('0x14')]({'plain':!![]});var _0x53d3c9=_0x07f2('0x15');return db[_0x07f2('0x3f')][_0x07f2('0x39')]({'where':{'name':_0x53d3c9,'userProfileId':_0x3eff96[_0x07f2('0x40')]},'raw':!![]})[_0x07f2('0x12')](function(_0x109a77){if(_0x109a77&&_0x109a77[_0x07f2('0x41')]===0x0){return db['UserProfileResource'][_0x07f2('0x42')]({'name':_0x3a96ef['name'],'resourceId':_0x3a96ef['id'],'type':_0x109a77[_0x07f2('0x1c')],'sectionId':_0x109a77['id']},{})[_0x07f2('0x12')](function(){return _0x3adf66;});}else{return _0x3adf66;}})['catch'](function(_0x395c81){logger[_0x07f2('0x1a')](_0x07f2('0x43'),_0x395c81);throw _0x395c81;});}return _0x3adf66;})[_0x07f2('0x12')](respondWithResult(_0x4b435c,0xc9))[_0x07f2('0x3a')](handleError(_0x4b435c,null));};exports['update']=function(_0x387120,_0x2ca7d1){if(_0x387120[_0x07f2('0x3b')]['id']){delete _0x387120['body']['id'];}return db[_0x07f2('0x20')][_0x07f2('0x39')]({'where':{'id':_0x387120[_0x07f2('0x37')]['id']}})[_0x07f2('0x12')](handleEntityNotFound(_0x2ca7d1,null))['then'](saveUpdates(_0x387120[_0x07f2('0x3b')],null))['then'](function(_0x2f3ea6){if(!_0x2f3ea6)return;var _0x3ce06a=_0x2f3ea6[_0x07f2('0x14')]({'plain':!![]});return _0x3ce06a;})['then'](function(_0x195755){var _0x2f9176=new Redis(config[_0x07f2('0x5')]);_0x2f9176['publish'](_0x07f2('0x17'),JSON[_0x07f2('0x44')](_[_0x07f2('0x30')](_0x195755,['id','name',_0x07f2('0x45')])));return _0x195755;})[_0x07f2('0x12')](respondWithResult(_0x2ca7d1,null))['catch'](handleError(_0x2ca7d1,null));};exports[_0x07f2('0x13')]=function(_0x4e066b,_0x5cbcd4){return db[_0x07f2('0x20')]['find']({'where':{'id':_0x4e066b[_0x07f2('0x37')]['id']}})[_0x07f2('0x12')](handleEntityNotFound(_0x5cbcd4,null))[_0x07f2('0x12')](removeEntity(_0x5cbcd4,null))[_0x07f2('0x3a')](handleError(_0x5cbcd4,null));};