First public commit

This commit is contained in:
Luke Vella 2022-04-12 07:14:28 +01:00
commit e05cd62e53
228 changed files with 17717 additions and 0 deletions

View file

@ -0,0 +1,23 @@
import { Participant, Vote } from "@prisma/client";
import axios from "axios";
export interface AddParticipantPayload {
pollId: string;
name: string;
votes: string[];
}
export type AddParticipantResponse = Participant & {
votes: Vote[];
};
export const addParticipant = async (
payload: AddParticipantPayload,
): Promise<AddParticipantResponse> => {
const res = await axios.post<AddParticipantResponse>(
`/api/poll/${payload.pollId}/participant`,
payload,
);
return res.data;
};

View file

@ -0,0 +1,18 @@
import { Comment } from "@prisma/client";
import axios from "axios";
export interface CreateCommentPayload {
pollId: string;
content: string;
authorName: string;
}
export const createComment = async (
payload: CreateCommentPayload,
): Promise<Comment> => {
const { data } = await axios.post<Comment>(
`/api/poll/${payload.pollId}/comments`,
payload,
);
return data;
};

View file

@ -0,0 +1,7 @@
import { Poll } from "@prisma/client";
import axios from "axios";
export const createDemo = async (): Promise<Poll> => {
const { data } = await axios.post<Poll>("/api/poll/create-demo");
return data;
};

21
api-client/create-poll.ts Normal file
View file

@ -0,0 +1,21 @@
import { Poll } from "@prisma/client";
import axios from "axios";
export interface CreatePollPayload {
title: string;
type: "date";
timeZone?: string;
location?: string;
description?: string;
user: {
name: string;
email: string;
};
options: string[];
demo?: boolean;
}
export const createPoll = async (payload: CreatePollPayload): Promise<Poll> => {
const { data } = await axios.post<Poll>("/api/poll", payload);
return data;
};

View file

@ -0,0 +1,17 @@
import axios from "axios";
export interface DeleteParticipantPayload {
pollId: string;
participantId: string;
}
export const deleteParticipant = async (
payload: DeleteParticipantPayload,
): Promise<void> => {
try {
const { pollId, participantId } = payload;
await axios.delete(`/api/poll/${pollId}/participant/${participantId}`);
} catch (err) {
throw err;
}
};

14
api-client/get-poll.ts Normal file
View file

@ -0,0 +1,14 @@
import { Link, Option, Participant, Poll, User, Vote } from "@prisma/client";
export interface GetPollApiResponse extends Omit<Poll, "verificationCode"> {
options: Array<Option & { votes: Vote[] }>;
participants: Array<Participant & { votes: Vote[] }>;
user: User;
role: "admin" | "participant";
links: Array<Link>;
pollId: string;
}
export interface GetPollResponse extends Omit<GetPollApiResponse, "createdAt"> {
createdAt: string;
}

View file

@ -0,0 +1,15 @@
import axios from "axios";
export interface UpdateParticipantPayload {
pollId: string;
participantId: string;
name: string;
votes: string[];
}
export const updateParticipant = async (
payload: UpdateParticipantPayload,
): Promise<void> => {
const { pollId, participantId, ...body } = payload;
await axios.patch(`/api/poll/${pollId}/participant/${participantId}`, body);
};

25
api-client/update-poll.ts Normal file
View file

@ -0,0 +1,25 @@
import { Poll } from "@prisma/client";
import axios from "axios";
export interface UpdatePollPayload {
title?: string;
timeZone?: string;
location?: string;
description?: string;
optionsToDelete?: string[];
optionsToAdd?: string[];
notifications?: boolean;
closed?: boolean;
}
export const updatePoll = async (
urlId: string,
payload: UpdatePollPayload,
): Promise<Poll> => {
try {
const { data } = await axios.patch<Poll>(`/api/poll/${urlId}`, payload);
return data;
} catch (err) {
throw err;
}
};