Tranforming more components to typescript (#47)

This commit is contained in:
Vladyslav Matsiiako
2022-12-04 22:14:13 -05:00
parent 3b002abcb6
commit 6cdbc834ab
16 changed files with 95 additions and 85 deletions
@@ -31,8 +31,8 @@ const issueBackupPrivateKey = ({
if (res.status == 200) {
return res;
} else {
return res;
console.log("Failed to issue the backup key");
return res;
}
});
};
@@ -3,11 +3,8 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route logs the user out. Note: the user should authorized to do this.
* We first try to log out - if the authorization fails (response.status = 401), we refetch the new token, and then retry
* @param {*} req
* @param {*} res
* @returns
*/
const logout = async (req, res) => {
const logout = async () => {
return SecurityClient.fetchCall("/api/v1/auth/logout", {
method: "POST",
headers: {
@@ -15,7 +12,7 @@ const logout = async (req, res) => {
},
credentials: "include",
}).then((res) => {
if (res.status == 200) {
if (res?.status == 200) {
SecurityClient.setToken("");
// Delete the cookie by not setting a value; Alternatively clear the local storage
localStorage.setItem("publicKey", "");
@@ -2,18 +2,17 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get info about a certain org
* @param {*} req
* @param {*} res
* @param {string} orgId - the organization ID
* @returns
*/
const getOrganization = (req, res) => {
return SecurityClient.fetchCall("/api/v1/organization/" + req.orgId, {
const getOrganization = ({ orgId }: { orgId: string; }) => {
return SecurityClient.fetchCall("/api/v1/organization/" + orgId, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(async (res) => {
if (res.status == 200) {
if (res?.status == 200) {
return (await res.json()).organization;
} else {
console.log("Failed to get org info");
@@ -2,18 +2,16 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get the all the orgs of a certain user.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizations = (req, res) => {
const getOrganizations = () => {
return SecurityClient.fetchCall("/api/v1/organization", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(async (res) => {
if (res.status == 200) {
if (res?.status == 200) {
return (await res.json()).organizations;
} else {
console.log("Failed to get orgs of a user");
@@ -2,18 +2,15 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route gets the information about a specific user.
* @param {*} req
* @param {*} res
* @returns
*/
const getUser = (req, res) => {
const getUser = () => {
return SecurityClient.fetchCall("/api/v1/user", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(async (res) => {
if (res.status == 200) {
if (res?.status == 200) {
return (await res.json()).user;
} else {
console.log("Failed to get user info");
@@ -2,13 +2,12 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get the information of a certain project.
* @param {*} req
* @param {*} res
* @param {*} projectId - project ID (we renamed workspaces to projects in the app)
* @returns
*/
const getWorkspaceInfo = (req, res) => {
const getProjectInfo = ({ projectId }: { projectId: string; }) => {
return SecurityClient.fetchCall(
"/api/v1/workspace/" + req.workspaceId,
"/api/v1/workspace/" + projectId,
{
method: "GET",
headers: {
@@ -16,7 +15,7 @@ const getWorkspaceInfo = (req, res) => {
},
}
).then(async (res) => {
if (res.status == 200) {
if (res?.status == 200) {
return (await res.json()).workspace;
} else {
console.log("Failed to get project info");
@@ -24,4 +23,4 @@ const getWorkspaceInfo = (req, res) => {
});
};
export default getWorkspaceInfo;
export default getProjectInfo;