Skip to content
Draft
Show file tree
Hide file tree
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
26 changes: 11 additions & 15 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions frontend/src/app/api/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,40 @@ export async function fetchProjectProgramMaps(): Promise<ProjectProgramMapDTO[]>
: new Error("An unknown error occurred while fetching project-program maps");
}
}

export async function createTag(body: {
name: string;
color: string;
type: string;
}): Promise<VolunteerTag> {
try {
const headers = await getAuthHeaders();

const response = await fetch(`${API_BASE_URL}/api/tag`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify(body),
});

if (!response.ok) {
throw new Error(`Failed to create tag: ${response.status} ${response.statusText}`);
}

const data: unknown = await response.json();
if (!isTagDTO(data)) {
throw new TypeError("Unexpected response format: expected a tag object");
}

return {
_id: data._id,
name: data.name,
color: data.color,
type: data.type,
};
} catch (error) {
console.error("Error creating tag:", error);
throw error instanceof Error
? error
: new Error("An unknown error occurred while creating a tag");
}
}
66 changes: 61 additions & 5 deletions frontend/src/app/api/volunteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,64 @@ export async function fetchVolunteerAssignments(): Promise<VolunteerAssignment[]
return (await res.json()) as VolunteerAssignment[];
}

export async function createVolunteerAssignment(body: {
volunteerId: string;
assignmentTagId: string;
projectTagId: string;
shiftTagIds?: string[];
}): Promise<VolunteerAssignment> {
try {
const headers = await getAuthHeaders();

const response = await fetch(`${API_BASE_URL}/api/volunteerAssignment`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify(body),
});

if (!response.ok) {
throw new Error(
`Failed to create volunteer assignment: ${response.status} ${response.statusText}`,
);
}

const data: unknown = await response.json();
return data as VolunteerAssignment;
} catch (error) {
console.error("Error creating volunteer assignment:", error);
throw error instanceof Error ? error : new Error("Unknown error creating volunteer assignment");
}
}

export async function updateVolunteerAssignment(
id: string,
body: {
shiftTagIds?: string[];
},
): Promise<VolunteerAssignment> {
try {
const headers = await getAuthHeaders();

const response = await fetch(`${API_BASE_URL}/api/volunteerAssignment/${id}`, {
method: "PUT",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify(body),
});

if (!response.ok) {
throw new Error(
`Failed to update volunteer assignment: ${response.status} ${response.statusText}`,
);
}

const data: unknown = await response.json();
return data as VolunteerAssignment;
} catch (error) {
console.error("Error updating volunteer assignment:", error);
throw error instanceof Error ? error : new Error("Unknown error updating volunteer assignment");
}
}

export type VolunteerCsvParseResult = {
wouldCreateCount: number;
wouldUpdateCount: number;
Expand Down Expand Up @@ -206,9 +264,7 @@ export async function parseVolunteersCsv(csv: File): Promise<VolunteerCsvParseRe
totalCount: parsed.total,
volunteerInfo: volunteerInfo
.filter((item): item is VolunteerParseCsvDTO["volunteerInfo"][number] => {
if (!item || typeof item !== "object") {
return false;
}
if (!item || typeof item !== "object") return false;
const row = item as Partial<VolunteerParseCsvDTO["volunteerInfo"][number]>;
return (
typeof row.firstName === "string" &&
Expand All @@ -225,10 +281,10 @@ export async function parseVolunteersCsv(csv: File): Promise<VolunteerCsvParseRe
assignmentName: typeof item.assignmentName === "string" ? item.assignmentName : undefined,
projectName: typeof item.projectName === "string" ? item.projectName : undefined,
shiftNames: Array.isArray(item.shiftNames)
? item.shiftNames.filter((value): value is string => typeof value === "string")
? item.shiftNames.filter((v): v is string => typeof v === "string")
: undefined,
tags: Array.isArray(item.tags)
? item.tags.filter((tag): tag is string => typeof tag === "string")
? item.tags.filter((t): t is string => typeof t === "string")
: undefined,
})),
};
Expand Down
Loading
Loading