-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd99103
commit f5a45a2
Showing
50 changed files
with
5,983 additions
and
2,494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,3 +128,6 @@ dist | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
backend/service_credentials/ | ||
.firebase/ | ||
.firebase/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ public/ | |
next.config.js | ||
vite.config.ts | ||
postcss.config.js | ||
src/app/firebase-admin.tsx | ||
src/app/AuthContext.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { APIResult, handleAPIError } from "./requests"; | ||
|
||
export type Admin = { | ||
email: string; | ||
firstName: string; | ||
lastName: string; | ||
phoneNumber: string; | ||
title: string; | ||
superUser: boolean; | ||
}; | ||
|
||
// addadmin, delete admin by email, get all admins | ||
export async function checkAdmin(email: string): Promise<boolean> { | ||
try { | ||
if (!process.env.API_URL) { | ||
throw new Error("API URL is not defined"); | ||
} | ||
|
||
const url = `${process.env.API_URL}/admin/${email}`; | ||
|
||
const response = await fetch(url, { | ||
method: "GET", | ||
}); | ||
const json = (await response.json()) as boolean; | ||
return json; | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
} | ||
|
||
export async function addAdmin(admin: Admin): Promise<APIResult<Admin>> { | ||
try { | ||
if (!process.env.API_URL) { | ||
throw new Error("API URL is not defined"); | ||
} | ||
|
||
const url = `${process.env.API_URL}/admin`; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(admin), | ||
}); | ||
const json = (await response.json()) as Admin; | ||
return { success: true, data: json }; | ||
} catch (error) { | ||
return handleAPIError(error); | ||
} | ||
} | ||
|
||
export async function deleteAdminByEmail(email: string): Promise<APIResult<Admin>> { | ||
try { | ||
if (!process.env.API_URL) { | ||
throw new Error("API URL is not defined"); | ||
} | ||
|
||
const url = `${process.env.API_URL}/admin/${email}`; | ||
const response = await fetch(url, { | ||
method: "DELETE", | ||
}); | ||
if (!response.ok) { | ||
throw new Error("Admin cannot be deleted"); | ||
} | ||
const json = (await response.json()) as Admin; | ||
return { success: true, data: json }; | ||
} catch (error) { | ||
console.log(error); | ||
return handleAPIError(error); | ||
} | ||
} | ||
|
||
export async function getAllAdmins(): Promise<Admin[]> { | ||
try { | ||
if (!process.env.API_URL) { | ||
throw new Error("API URL is not defined"); | ||
} | ||
|
||
const url = `${process.env.API_URL}/allAdmins`; | ||
const response = await fetch(url, { | ||
method: "GET", | ||
}); | ||
const json = (await response.json()) as Admin[]; | ||
|
||
return json; | ||
} catch (error) { | ||
console.log(error); | ||
return []; | ||
} | ||
} | ||
|
||
export async function checkSuperAdmin(email: string): Promise<boolean> { | ||
try { | ||
if (!process.env.API_URL) { | ||
throw new Error("API URL is not defined"); | ||
} | ||
|
||
const url = `${process.env.API_URL}/isSuperAdmin/${email}`; | ||
|
||
const response = await fetch(url, { | ||
method: "GET", | ||
}); | ||
const json = (await response.json()) as boolean; | ||
return json; | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.