Finished list render system
This commit is contained in:
@@ -1,35 +1,61 @@
|
||||
import { BatchPromotion } from '@shared/schemas/promotionSchema';
|
||||
import { Rank } from '@shared/types/rank'
|
||||
import { PagedData } from '@shared/types/pagination';
|
||||
import { PromotionSummary, Rank } from '@shared/types/rank'
|
||||
|
||||
// @ts-ignore
|
||||
const addr = import.meta.env.VITE_APIHOST;
|
||||
|
||||
export async function getAllRanks(): Promise<Rank[]> {
|
||||
const res = await fetch(`${addr}/ranks`, {
|
||||
credentials: 'include'
|
||||
})
|
||||
const res = await fetch(`${addr}/ranks`, {
|
||||
credentials: 'include'
|
||||
})
|
||||
|
||||
if (res.ok) {
|
||||
return res.json()
|
||||
} else {
|
||||
console.error("Something went wrong approving the application")
|
||||
}
|
||||
if (res.ok) {
|
||||
return res.json()
|
||||
} else {
|
||||
console.error("Something went wrong approving the application")
|
||||
}
|
||||
}
|
||||
|
||||
// Placeholder: submit a rank change
|
||||
export async function submitRankChange(promo: BatchPromotion) {
|
||||
const res = await fetch(`${addr}/memberRanks`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(promo),
|
||||
})
|
||||
const res = await fetch(`${addr}/memberRanks`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(promo),
|
||||
})
|
||||
|
||||
if (res.ok) {
|
||||
return
|
||||
} else {
|
||||
throw new Error("Failed to submit rank change: Server error");
|
||||
}
|
||||
if (res.ok) {
|
||||
return
|
||||
} else {
|
||||
throw new Error("Failed to submit rank change: Server error");
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPromoHistory(page?: number, pageSize?: number): Promise<PagedData<PromotionSummary>> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (page !== undefined) {
|
||||
params.set("page", page.toString());
|
||||
}
|
||||
|
||||
if (pageSize !== undefined) {
|
||||
params.set("pageSize", pageSize.toString());
|
||||
}
|
||||
|
||||
return fetch(`${addr}/memberRanks?${params}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: 'include',
|
||||
}).then((res) => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user