mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-04 00:48:52 +02:00
Remove option to reset dates
This is done automatically now for legacy polls that need it
This commit is contained in:
parent
c9aaddf4cc
commit
e44afd84cc
5 changed files with 15 additions and 160 deletions
|
@ -11,7 +11,6 @@ export default async function handler(
|
|||
res: NextApiResponse<GetPollApiResponse>,
|
||||
) {
|
||||
const urlId = getQueryParam(req, "urlId");
|
||||
const reset = req.query.reset;
|
||||
|
||||
const client = await getMongoClient();
|
||||
if (!client) {
|
||||
|
@ -45,69 +44,6 @@ export default async function handler(
|
|||
});
|
||||
}
|
||||
|
||||
if (reset) {
|
||||
const existingOptions = await prisma.option.findMany({
|
||||
where: { pollId: legacyPoll._id },
|
||||
orderBy: {
|
||||
value: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
if (!existingOptions) {
|
||||
return res.status(400).end();
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
for (let i = 0; i < existingOptions.length; i++) {
|
||||
promises.push(
|
||||
prisma.option.update({
|
||||
where: { id: existingOptions[i].id },
|
||||
data: {
|
||||
value: newOptions[i].value,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
await prisma.$transaction(promises);
|
||||
|
||||
const poll = await prisma.poll.findUnique({
|
||||
where: {
|
||||
urlId: legacyPoll._id,
|
||||
},
|
||||
include: {
|
||||
options: {
|
||||
include: {
|
||||
votes: true,
|
||||
},
|
||||
},
|
||||
participants: {
|
||||
include: {
|
||||
votes: true,
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
{ name: "desc" },
|
||||
],
|
||||
},
|
||||
user: true,
|
||||
links: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!poll) {
|
||||
return res.status(404);
|
||||
}
|
||||
|
||||
return res.json({
|
||||
...exclude(poll, "verificationCode"),
|
||||
role: "admin",
|
||||
urlId: poll.urlId,
|
||||
pollId: poll.urlId,
|
||||
});
|
||||
}
|
||||
|
||||
const newParticipants = legacyPoll.participants?.map((legacyParticipant) => ({
|
||||
name: legacyParticipant.name,
|
||||
id: legacyParticipant._id.toString(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue