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) #346

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 |
SalihuDickson marked this conversation as resolved.
Show resolved Hide resolved
| `id` | string | ID of the object to be deleted |


![Logo]('./../../../../images/logo-elixir.svg)
![Logo]('./../../../../images/logo-elixir-cloud-aai.svg)
SalihuDickson marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Update JSDoc to match actual return type of postObject

The JSDoc indicates that postObject returns a string, but the implementation suggests it returns an object. Please update the documentation to accurately reflect the function's behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psankhe28, please take a look at this

*/
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) => {
SalihuDickson marked this conversation as resolved.
Show resolved Hide resolved
const url = `${baseURL}/objects/${id}`;
SalihuDickson marked this conversation as resolved.
Show resolved Hide resolved
try {
const response = await fetch(url, {
method: "DELETE",
});

if (!response) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider some more robust error handling like checking the status text, as checking for just the response object won't catch many errors that may occur.

Also consider this for the other postObject function.

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

return await response.json();
SalihuDickson marked this conversation as resolved.
Show resolved Hide resolved
} 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
@@ -0 +0,0 @@
import "./Object/drsAPI.js";
Expand Up @@ -2,0 +1 @@
import "./Object/drsAPI.js";

Check failure on line 1 in packages/ecc-client-elixir-drs-filer/src/API/index.ts

View workflow job for this annotation

GitHub Actions / Linting checks

Insert `⏎`
Loading