Skip to content

Commit

Permalink
leave group gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed Mar 13, 2024
1 parent 1a85903 commit f4e6aa6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions game/groupservice/GroupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let GroupController = {
res.json(response);

}catch(error){
console.log(error)
res.status(400).json({error: error.message})
}

Expand All @@ -45,8 +46,8 @@ let GroupController = {
requiredFields = ['expelledUUID','groupName', 'adminUUID']
validateRequiredFields(req, requiredFields);
const group = await getGroupByName(req.body.groupName);

if(req.body.adminUUID != group.admin && req.body.adminUUID == req.body.expelledUUID){
console.log(req.body.adminUUID +" - "+ req.body.expelledUUID)
if(req.body.adminUUID != group.admin && req.body.adminUUID != req.body.expelledUUID){
console.log("entra en la condicion")
res.json({ message: 'User is unable to perform this operation' });
return;
Expand Down
28 changes: 26 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,44 @@ app.post('/createGroup', async (req, res) => {
try {
const { creatorUUID } = req.body
const groupResponse = await axios.post(groupServiceUrl+'/createGroup', req.body);
const groupName = groupResponse.data.groupName;
console.log("----Group created succesfully----")
console.log(groupResponse.data)
const userResponse = await axios.put(userServiceUrl+'/addGroup/'+creatorUUID, {groupUUID: groupResponse.data.uuid});
console.log(userResponse.data);
console.log("----User updated succesfully----");
console.log(userResponse.data)
if(userResponse.data.previousGroup){
console.log("----User has a previous group----")
console.log(userResponse.data.previousGroup)
const getGroupResponse = await axios.get(groupServiceUrl+'/getGroup/'+userResponse.data.previousGroup);
console.log("----Group retrieved succesfully----")
console.log(getGroupResponse.data)
const exitGroupResponse = await axios.post(groupServiceUrl+'/leaveGroup', {expelledUUID: creatorUUID, adminUUID: creatorUUID, groupName: getGroupResponse.data.groupName});
console.log("----Group exited succesfully----")
console.log(exitGroupResponse.data)
}
res.json(groupResponse.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
})
// join group
app.post('/joinGroup', async (req, res) => {
try{
const { uuid } = req.body
const groupResponse = await axios.post(groupServiceUrl+'/joinGroup', req.body);
const userResponse = await axios.put(userServiceUrl+'/addGroup/'+req.body.uuid, {groupUUID: groupResponse.data.uuid});
if(userResponse.data.previousGroup){
const getGroupResponse = await axios.get(groupServiceUrl+'/getGroup/'+userResponse.data.previousGroup);
console.log(getGroupResponse.data)
const exitGroupResponse = await axios.post(groupServiceUrl+'/leaveGroup', {expelledUUID: uuid, adminUUID: uuid, groupName: getGroupResponse.data.groupName});
console.log(exitGroupResponse.data)
}
console.log(groupResponse.data)
res.json(groupResponse.data);
} catch(error){
res.status(500).json({ error: error.message });
}
})
// leave group
// get group by id

Expand Down

0 comments on commit f4e6aa6

Please sign in to comment.