Skip to content
Snippets Groups Projects
Commit fdb59daa authored by Sarthak Shrivastava's avatar Sarthak Shrivastava
Browse files

Added ability to accept and deny requests.

parent a187ca9e
No related branches found
No related tags found
No related merge requests found
......@@ -32,11 +32,11 @@ const OrganizationRequests = ({ token }) => {
const handleDecision = async (requestId, status) => {
try {
const response = await Axios.post('http://localhost:8080/request/user/request/decision', {
const response = await Axios.post('http://localhost:8080/request/user/request/update', {
jwt: token.jwt,
orgId: parseInt(orgId),
requestId,
status,
requestId: requestId,
status: status,
});
if (response.data.result === 'success') {
......@@ -84,9 +84,9 @@ const OrganizationRequests = ({ token }) => {
</button>
<button
className="deny-button"
onClick={() => handleDecision(requestId, 'ACCEPTED')}
onClick={() => handleDecision(requestId, 'DECLINED')}
>
Deny
Decline
</button>
</>
)}
......
......@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
@Repository
public class CustomRequestRepository {
......@@ -23,4 +24,18 @@ public class CustomRequestRepository {
return query.getResultList();
}
@Transactional
public Object updateRequest(Map<String, Object> json)
{
Integer requestId;
if (json.get("requestId") instanceof Integer)
requestId = (Integer) json.get("requestId");
else
requestId = Integer.parseInt((String) json.get("requestId"));
String nativeQuery = "UPDATE REQUEST r SET status = ?1 WHERE r.request_id = ?2";
Query query = entityManager.createNativeQuery(nativeQuery)
.setParameter(1, json.get("status"))
.setParameter(2, requestId);
return query.executeUpdate() > 0;
}
}
......@@ -76,6 +76,40 @@ public class RequestController {
return response;
}
@PostMapping(path = "/user/request/update")
public @ResponseBody Map<String, Object> updateOrgRequest(@RequestBody Map<String, Object> json)
{
Map<String, Object> response = new HashMap<>();
if (!json.containsKey("jwt") || !json.containsKey("orgId") || !json.containsKey("status") || !json.containsKey("requestId"))
{
response.put("result", "failure - bad request");
return response;
}
Map<String, Object> map = getUserOrg(json);
if (map.get("result").equals("success"))
{
Integer orgId;
if (json.get("orgId") instanceof Integer)
orgId = (Integer) json.get("orgId");
else
orgId = Integer.parseInt((String)(json.get("orgId")));
if (map.get("type") == OrganizationRoster.Type.MEMBER)
{
response.put("result", "failure - not authorized members cannot view requests");
response.put("type", map.get("type"));
return response;
}
response.put("data", customRequestRepository.updateRequest(json));
response.put("result", "success");
response.put("type", map.get("type"));
}
else
{
response.put("result", "failure - not authorized");
}
return response;
}
/*
Private helper function to validate that the user is supposed to see this data
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment