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

refactor: update api endpoints #565

Merged
merged 1 commit into from
Nov 4, 2023
Merged
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
52 changes: 26 additions & 26 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function sign_up({
}

export async function getLeaderboard(date) {
const response = await API.get(`/api/v1/leaderboard/${date}`);
const response = await API.get(`/api/leaderboard/${date}`);

return response.data;
}
Expand All @@ -50,13 +50,13 @@ export async function sign_in({ email, password }) {
}

export async function getReedemable(uuid) {
const response = await API.get(`/api/v1/store/redeem/${uuid}`);
const response = await API.get(`/api/store/redeem/${uuid}`);

return response.data;
}

export async function redeem(attendee, prize, amount) {
const response = await API.post("/api/v1/store/redeem", {
const response = await API.post("/api/store/redeem", {
redeem: {
attendee_id: attendee,
redeemable: prize,
Expand All @@ -68,7 +68,7 @@ export async function redeem(attendee, prize, amount) {
}

export async function redeemWheel(attendee, prize, amount) {
const response = await API.post("/api/v1/roulette/redeem", {
const response = await API.post("/api/roulette/redeem", {
redeem: {
attendee_id: attendee,
prize: prize,
Expand All @@ -80,7 +80,7 @@ export async function redeemWheel(attendee, prize, amount) {
}

export async function redeemBadge(uuid, selectedBadge) {
const response = await API.post("/api/v1/redeems", {
const response = await API.post("/api/redeems", {
redeem: {
attendee_id: uuid,
badge_id: selectedBadge,
Expand Down Expand Up @@ -125,72 +125,72 @@ export async function sendResetEmail({ email }) {
}

export async function getAttendee(id) {
const response = await API.get(`/api/v1/attendees/${id}`);
const response = await API.get(`/api/attendees/${id}`);

return response.data;
}

export async function getWheelPrizes() {
const response = await API.get("/api/v1/roulette/prizes");
const response = await API.get("/api/roulette/prizes");

return response.data;
}

export async function getWheelRedeemables(uuid) {
const response = await API.get(`/api/v1/roulette/redeem/${uuid}`);
const response = await API.get(`/api/roulette/redeem/${uuid}`);

return response.data;
}

export async function getAllBadges() {
const response = await API.get("/api/v1/badges");
const response = await API.get("/api/badges");

return response.data;
}

export async function getWheelLatestWins() {
const response = await API.get("/api/v1/roulette/latestwins");
const response = await API.get("/api/roulette/latestwins");

return response.data;
}

export async function spinWheel() {
const response = await API.post("/api/v1/roulette");
const response = await API.post("/api/roulette");

return response.data;
}

export async function referral(id) {
const response = await API.post("/api/v1/referrals", {
const response = await API.post("/api/referrals", {
id: id,
});

return response.data;
}

export async function isAttendeeRegistered(id) {
const response = await API.get(`/api/v1/is_registered/${id}`);
const response = await API.get(`/api/is_registered/${id}`);

return response;
}

export async function getCurrentUser() {
const response = await API.get("/api/v1/user");
const response = await API.get("/api/user");
const { type } = response.data;

if (type) {
switch (type) {
case USER.ROLES.ATTENDEE:
const { data: attendee } = await API.get("/api/v1/attendee");
const { data: attendee } = await API.get("/api/attendee");
const {
data: { data: extras },
} = await API.get(`/api/v1/attendees/${attendee.id}`);
} = await API.get(`/api/attendees/${attendee.id}`);

return { ...attendee, ...extras, type };
case USER.ROLES.MANAGER:
return response.data;
case USER.ROLES.SPONSOR:
const { data: company } = await API.get("/api/v1/company");
const { data: company } = await API.get("/api/company");

return { ...company, user_id: response.data.id, type };
default:
Expand All @@ -202,25 +202,25 @@ export async function getCurrentUser() {
}

export async function getBadge(id) {
const response = await API.get(`/api/v1/badges/${id}`);
const response = await API.get(`/api/badges/${id}`);

return response;
}

export async function testEdit(id, formData) {
const response = await API.patch(`/api/v1/attendees/${id}`, formData);
const response = await API.patch(`/api/attendees/${id}`, formData);

return response.data;
}

export async function editUser(id, formData) {
const response = await API.patch(`/api/v1/attendees/${id}`, formData);
const response = await API.patch(`/api/attendees/${id}`, formData);

return response.data;
}

export async function giveBadge(attendee_id, badge_id) {
const response = await API.post("/api/v1/redeems", {
const response = await API.post("/api/redeems", {
redeem: {
attendee_id,
badge_id,
Expand All @@ -231,32 +231,32 @@ export async function giveBadge(attendee_id, badge_id) {
}

export async function getProducts() {
const response = await API.get("/api/v1/store");
const response = await API.get("/api/store");

return response.data;
}

export async function getProduct(id) {
const response = await API.get(`/api/v1/store/${id}`);
const response = await API.get(`/api/store/${id}`);

return response;
}

export async function buyProduct(id) {
const response = await API.post(`/api/v1/store/buy/`, {
const response = await API.post(`/api/store/buy/`, {
redeemable: { redeemable_id: id },
});
return response.data;
}

export async function getCompanyVisitors(id) {
const response = await API.get(`/api/v1/company/attendees/${id}`);
const response = await API.get(`/api/company/attendees/${id}`);

return response.data;
}

export async function downloadCVInBulk(id) {
const response = await API.get(`/api/v1/company/attendees/cvs/${id}`, {
const response = await API.get(`/api/company/attendees/cvs/${id}`, {
responseType: "blob",
});

Expand Down
Loading