Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add delete endpoint #345

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/ecc-client-elixir-drs-filer/src/API/Object/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ Posts/Create a new object.
| | | This should be an object containing the necessary fields for the object. |
| | | Modify the structure according to your object requirements. |

## deleteObject

Deletes a specific DRS object.

**API Request Body**

| Parameter | Type | Description |
| --------- | ------ | ------------------------------ |
| `baseURL` | string | Base URL for deleting object |
| `id` | string | ID of the object to be deleted |


![Logo]('./../../../../images/logo-elixir.svg)
![Logo]('./../../../../images/logo-elixir-cloud-aai.svg)
Expand Down
39 changes: 38 additions & 1 deletion packages/ecc-client-elixir-drs-filer/src/API/Object/drsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* Posts a new drs object.
* @param {string} baseURL - The base URL for posting the drs object.
* @param {object} objectData - The data of the drs object to be posted.
* This should be an object containing the necessary fields for the drs object.
* Modify the structure according to your object requirements.
* @returns {string} - A string that denotes the object id
*/
const postObject = async (baseURL: string, objectData: object) => {
const url = `${baseURL}/objects`;

Expand Down Expand Up @@ -28,4 +36,33 @@ const postObject = async (baseURL: string, objectData: object) => {
}
};

export { postObject };
/**
*This method deletes a specific object
* @param id ID of the drs obeject to be deleted
*/
const deleteObject = async (baseURL: string, id: string) => {
psankhe28 marked this conversation as resolved.
Show resolved Hide resolved
const url = `${baseURL}/objects/${id}`;
try {
const response = await fetch(url, {
method: "DELETE",
});

if (!response) {
return {
isError: true,
breakpoint: "deleteObject",
error: "No response from server",
};
}

return await response.json();
} catch (error) {
return {
isError: true,
breakpoint: "deleteObject",
error,
};
}
};

export { postObject, deleteObject };
2 changes: 1 addition & 1 deletion packages/ecc-client-elixir-drs-filer/src/API/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "./Object/drsAPI.js";
import "./Object/drsAPI.js";