This commit is contained in:
Luke Vella 2024-09-28 20:14:55 +01:00
parent 8ca4b2acf8
commit 211e261c71
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
28 changed files with 519 additions and 324 deletions

View file

@ -1,4 +1,7 @@
import { prisma } from "@rallly/database";
import dayjs from "dayjs";
import { shortUrl } from "@/utils/absolute-url";
import { possiblyPublicProcedure, router } from "../trpc";
@ -14,4 +17,48 @@ export const dashboard = router({
return { activePollCount };
}),
getPending: possiblyPublicProcedure.query(async ({ ctx }) => {
const polls = await prisma.poll.findMany({
where: {
userId: ctx.user.id,
status: "live",
deleted: false,
},
select: {
id: true,
title: true,
createdAt: true,
status: true,
options: {
select: {
startTime: true,
duration: true,
},
},
_count: {
select: {
participants: true,
},
},
},
take: 3,
});
return polls.map((poll) => {
return {
id: poll.id,
title: poll.title,
createdAt: poll.createdAt,
range: {
start: poll.options[0].startTime,
end: dayjs(poll.options[poll.options.length - 1].startTime)
.add(poll.options[poll.options.length - 1].duration, "minute")
.toDate(),
},
status: poll.status,
responseCount: poll._count.participants,
inviteLink: shortUrl(`/invite/${poll.id}`),
};
});
}),
});