mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-05 20:21:50 +02:00
✨ New and Improved Screens (#1151)
This commit is contained in:
parent
5461c57228
commit
997a1eec78
75 changed files with 1517 additions and 743 deletions
|
@ -10,6 +10,7 @@
|
|||
"types": "src/index.ts",
|
||||
"dependencies": {
|
||||
"@rallly/database": "*",
|
||||
"@rallly/features": "*",
|
||||
"@rallly/emails": "*",
|
||||
"@rallly/utils": "*",
|
||||
"@trpc/server": "^10.13.0",
|
||||
|
|
17
packages/backend/trpc/routers/dashboard.ts
Normal file
17
packages/backend/trpc/routers/dashboard.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
|
||||
import { possiblyPublicProcedure, router } from "../trpc";
|
||||
|
||||
export const dashboard = router({
|
||||
info: possiblyPublicProcedure.query(async ({ ctx }) => {
|
||||
const activePollCount = await prisma.poll.count({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
status: "live",
|
||||
deleted: false, // TODO (Luke Vella) [2024-06-16]: We should add deleted/cancelled to the status enum
|
||||
},
|
||||
});
|
||||
|
||||
return { activePollCount };
|
||||
}),
|
||||
});
|
|
@ -1,13 +1,26 @@
|
|||
import dayjs from "dayjs";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import toArray from "dayjs/plugin/toArray";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
|
||||
import { mergeRouters, router } from "../trpc";
|
||||
import { auth } from "./auth";
|
||||
import { dashboard } from "./dashboard";
|
||||
import { polls } from "./polls";
|
||||
import { scheduledEvents } from "./scheduled-events";
|
||||
import { user } from "./user";
|
||||
|
||||
dayjs.extend(toArray); // used for creating ics
|
||||
dayjs.extend(timezone);
|
||||
dayjs.extend(utc);
|
||||
|
||||
export const appRouter = mergeRouters(
|
||||
router({
|
||||
scheduledEvents,
|
||||
auth,
|
||||
polls,
|
||||
user,
|
||||
dashboard,
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
import { PollStatus, prisma } from "@rallly/database";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { waitUntil } from "@vercel/functions";
|
||||
import dayjs from "dayjs";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import toArray from "dayjs/plugin/toArray";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import * as ics from "ics";
|
||||
import { z } from "zod";
|
||||
|
||||
|
@ -19,10 +16,6 @@ import {
|
|||
import { comments } from "./polls/comments";
|
||||
import { participants } from "./polls/participants";
|
||||
|
||||
dayjs.extend(toArray);
|
||||
dayjs.extend(timezone);
|
||||
dayjs.extend(utc);
|
||||
|
||||
const getPollIdFromAdminUrlId = async (urlId: string) => {
|
||||
const res = await prisma.poll.findUnique({
|
||||
select: {
|
||||
|
@ -43,6 +36,64 @@ const getPollIdFromAdminUrlId = async (urlId: string) => {
|
|||
export const polls = router({
|
||||
participants,
|
||||
comments,
|
||||
getCountByStatus: possiblyPublicProcedure.query(async ({ ctx }) => {
|
||||
const res = await prisma.poll.groupBy({
|
||||
by: ["status"],
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
deleted: false,
|
||||
},
|
||||
_count: {
|
||||
status: true,
|
||||
},
|
||||
});
|
||||
|
||||
return res.reduce(
|
||||
(acc, { status, _count }) => {
|
||||
acc[status] = _count.status;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<PollStatus, number>,
|
||||
);
|
||||
}),
|
||||
list: possiblyPublicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
status: z.enum(["all", "live", "paused", "finalized"]),
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
return await prisma.poll.findMany({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
status: input.status === "all" ? undefined : input.status,
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
{
|
||||
title: "asc",
|
||||
},
|
||||
],
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
location: true,
|
||||
timeZone: true,
|
||||
createdAt: true,
|
||||
status: true,
|
||||
userId: true,
|
||||
participants: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}),
|
||||
|
||||
// START LEGACY ROUTES
|
||||
create: possiblyPublicProcedure
|
||||
.input(
|
||||
|
|
33
packages/backend/trpc/routers/scheduled-events.ts
Normal file
33
packages/backend/trpc/routers/scheduled-events.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { listScheduledEvents } from "@rallly/features/scheduled-events/api";
|
||||
import dayjs from "dayjs";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import toArray from "dayjs/plugin/toArray";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import { z } from "zod";
|
||||
|
||||
import { possiblyPublicProcedure, router } from "../trpc";
|
||||
|
||||
dayjs.extend(toArray);
|
||||
dayjs.extend(timezone);
|
||||
dayjs.extend(utc);
|
||||
|
||||
export const scheduledEvents = router({
|
||||
list: possiblyPublicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
period: z.enum(["upcoming", "past"]).default("upcoming"),
|
||||
}),
|
||||
)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const events = await listScheduledEvents({
|
||||
userId: ctx.user.id,
|
||||
period: input.period,
|
||||
});
|
||||
|
||||
return events.map(({ poll, ...event }) => ({
|
||||
...event,
|
||||
timeZone: poll?.timeZone || null,
|
||||
participants: poll?.participants ?? [],
|
||||
}));
|
||||
}),
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue