Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

1.1 KB
Raw Blame
import { client } from "@kaneo/libs";
import { HttpError } from "@/lib/http-error";
import { getApiUrl } from "./get-api-url";

const endpoint = client["calendar-feed"].project[":projectId"];

export async function getCalendarFeeds(projectId: string) {
  const response = await endpoint.$get({ param: { projectId } });
  if (!response.ok) throw await HttpError.fromResponse(response);
  return response.json();
}

export async function createCalendarFeed(
  projectId: string,
  labelIds: string[],
  timeZone: string,
) {
  const response = await endpoint.$post({
    param: { projectId },
    json: { labelIds, timeZone },
  });
  if (!response.ok) throw await HttpError.fromResponse(response);
  return response.json();
}

export async function revokeCalendarFeed(projectId: string, id: string) {
  const response = await endpoint[":id"].$delete({ param: { projectId, id } });
  if (!response.ok) throw await HttpError.fromResponse(response);
  return response.json();
}

export function getCalendarFeedUrl(token: string) {
  return new URL(
    getApiUrl(`/calendar-feed/${encodeURIComponent(token)}/calendar.ics`),
    window.location.origin,
  ).href;
}