mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-29 08:46:22 +02:00
First public commit
This commit is contained in:
commit
e05cd62e53
228 changed files with 17717 additions and 0 deletions
23
api-client/add-participant.ts
Normal file
23
api-client/add-participant.ts
Normal 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;
|
||||
};
|
18
api-client/create-comment.ts
Normal file
18
api-client/create-comment.ts
Normal 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;
|
||||
};
|
7
api-client/create-demo.ts
Normal file
7
api-client/create-demo.ts
Normal 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
21
api-client/create-poll.ts
Normal 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;
|
||||
};
|
17
api-client/delete-participant.ts
Normal file
17
api-client/delete-participant.ts
Normal 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
14
api-client/get-poll.ts
Normal 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;
|
||||
}
|
15
api-client/update-participant.ts
Normal file
15
api-client/update-participant.ts
Normal 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
25
api-client/update-poll.ts
Normal 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;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue