Convert all SecurityClient API calls to hooks except auth

This commit is contained in:
Tuan Dang
2023-08-10 17:19:23 +07:00
parent 78802409bd
commit 2dba7847b6
45 changed files with 179 additions and 1377 deletions
@@ -1,23 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get all the projects of a certain user in an org.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizationUserProjects = (req: { orgId: string }) =>
SecurityClient.fetchCall(`/api/v1/organization/${req.orgId}/my-workspaces`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).workspaces;
}
console.log("Failed to get projects of a user in an org");
return undefined;
});
export default getOrganizationUserProjects;
@@ -1,38 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
export interface IMembershipOrg {
_id: string;
user: {
email: string;
firstName: string;
lastName: string;
_id: string;
publicKey: string;
};
inviteEmail: string;
organization: string;
role: "owner" | "admin" | "member";
status: "invited" | "accepted";
deniedPermissions: any[];
}
/**
* This route lets us get all the users in an org.
* @param {object} obj
* @param {string} obj.orgId - organization Id
* @returns
*/
const getOrganizationUsers = ({ orgId }: { orgId: string }): Promise<IMembershipOrg[]> =>
SecurityClient.fetchCall(`/api/v1/organization/${orgId}/users`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res?.status === 200) {
return (await res.json()).users;
}
console.log("Failed to get org users");
return undefined;
});
export default getOrganizationUsers;
@@ -1,27 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This function sends an email invite to a user to join an org
* @param {*} email
* @param {*} orgId
* @returns
*/
const addUserToOrg = (email: string, orgId: string) =>
SecurityClient.fetchCall("/api/v1/invite-org/signup", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
inviteeEmail: email,
organizationId: orgId
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to add a user to an org");
return undefined;
});
export default addUserToOrg;
@@ -1,23 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get the all the orgs of a certain user.
* @returns
*/
const getOrganizations = () => {
return SecurityClient.fetchCall("/api/v1/organization", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res?.status === 200) {
const {organizations} = await res.json();
return organizations;
}
console.log("Failed to get orgs of a user");
return undefined;
});
}
export default getOrganizations;
@@ -1,13 +0,0 @@
import { apiRequest } from "@app/config/request";
/**
* Get the latest key pairs from a certain workspace
* @param {string} workspaceId
* @returns
*/
const getLatestFileKey = async ({ workspaceId }: { workspaceId: string }) => {
const { data } = await apiRequest.get(`/api/v1/key/${workspaceId}/latest`);
return data;
}
export default getLatestFileKey;
@@ -1,32 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route uplods the keys in an encrypted format.
* @param {*} workspaceId
* @param {*} userId
* @param {*} encryptedKey
* @param {*} nonce
* @returns
*/
const uploadKeys = (workspaceId: string, userId: string, encryptedKey: string, nonce: string) =>
SecurityClient.fetchCall(`/api/v1/key/${workspaceId}`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
key: {
userId,
encryptedKey,
nonce
}
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to upload keys for a new user");
return undefined;
});
export default uploadKeys;