revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s
Local Build and Deploy / deploy (push) Successful in 1m11s
revert style: clean up code with prettier and eslint
This commit is contained in:
1 parent
27de078f54
commit
e85e4d74ea
378 files changed
+20710
-22428
No files matched your search
+45
-45
@@ -1,107 +1,107 @@
|
||||
"use server";
|
||||
'use server'
|
||||
|
||||
import { z } from "zod";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { adminAction } from "@/lib/safe-action";
|
||||
import { ActionError, actionOk } from "@/lib/safe-action-shared";
|
||||
import { logAudit } from "@/lib/services/audit";
|
||||
import { createPollSchema, pollQuestionSchema, updatePollSchema } from "@/lib/validators/poll";
|
||||
import { z } from 'zod'
|
||||
import { PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { adminAction } from '@/lib/safe-action'
|
||||
import { ActionError, actionOk } from '@/lib/safe-action-shared'
|
||||
import { logAudit } from '@/lib/services/audit'
|
||||
import { createPollSchema, pollQuestionSchema, updatePollSchema } from '@/lib/validators/poll'
|
||||
|
||||
// ── Polls ───────────────────────────────────────────────────────────
|
||||
|
||||
export const createPoll = adminAction(
|
||||
{ permission: PERMS.POLLS_EDIT, schema: createPollSchema },
|
||||
async (ctx) => {
|
||||
const poll = await prisma.websitePoll.create({ data: ctx.data });
|
||||
const poll = await prisma.websitePoll.create({ data: ctx.data })
|
||||
logAudit({
|
||||
userId: ctx.session.user.id,
|
||||
action: "poll_create",
|
||||
target: "WebsitePoll",
|
||||
action: 'poll_create',
|
||||
target: 'WebsitePoll',
|
||||
targetId: poll.id,
|
||||
after: { title: poll.title },
|
||||
});
|
||||
return actionOk({ id: poll.id });
|
||||
})
|
||||
return actionOk({ id: poll.id })
|
||||
},
|
||||
);
|
||||
)
|
||||
|
||||
const updatePollInput = updatePollSchema.extend({
|
||||
id: z.coerce.number().int().positive(),
|
||||
});
|
||||
})
|
||||
|
||||
export const updatePoll = adminAction(
|
||||
{ permission: PERMS.POLLS_EDIT, schema: updatePollInput },
|
||||
async (ctx) => {
|
||||
const { id, ...data } = ctx.data;
|
||||
const existing = await prisma.websitePoll.findUnique({ where: { id } });
|
||||
if (!existing) throw new ActionError("Poll not found");
|
||||
const { id, ...data } = ctx.data
|
||||
const existing = await prisma.websitePoll.findUnique({ where: { id } })
|
||||
if (!existing) throw new ActionError('Poll not found')
|
||||
|
||||
await prisma.websitePoll.update({ where: { id }, data });
|
||||
await prisma.websitePoll.update({ where: { id }, data })
|
||||
logAudit({
|
||||
userId: ctx.session.user.id,
|
||||
action: "poll_update",
|
||||
target: "WebsitePoll",
|
||||
action: 'poll_update',
|
||||
target: 'WebsitePoll',
|
||||
targetId: id,
|
||||
before: { title: existing.title, status: existing.status },
|
||||
after: data,
|
||||
});
|
||||
return actionOk({ id });
|
||||
})
|
||||
return actionOk({ id })
|
||||
},
|
||||
);
|
||||
)
|
||||
|
||||
const deletePollInput = z.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
});
|
||||
})
|
||||
|
||||
export const deletePoll = adminAction(
|
||||
{ permission: PERMS.POLLS_EDIT, schema: deletePollInput },
|
||||
async (ctx) => {
|
||||
const existing = await prisma.websitePoll.findUnique({ where: { id: ctx.data.id } });
|
||||
if (!existing) throw new ActionError("Poll not found");
|
||||
const existing = await prisma.websitePoll.findUnique({ where: { id: ctx.data.id } })
|
||||
if (!existing) throw new ActionError('Poll not found')
|
||||
|
||||
await prisma.websitePoll.delete({ where: { id: ctx.data.id } });
|
||||
await prisma.websitePoll.delete({ where: { id: ctx.data.id } })
|
||||
logAudit({
|
||||
userId: ctx.session.user.id,
|
||||
action: "poll_delete",
|
||||
target: "WebsitePoll",
|
||||
action: 'poll_delete',
|
||||
target: 'WebsitePoll',
|
||||
targetId: ctx.data.id,
|
||||
before: { title: existing.title },
|
||||
});
|
||||
return actionOk();
|
||||
})
|
||||
return actionOk()
|
||||
},
|
||||
);
|
||||
)
|
||||
|
||||
// ── Questions ───────────────────────────────────────────────────────
|
||||
|
||||
export const addPollQuestion = adminAction(
|
||||
{ permission: PERMS.POLLS_EDIT, schema: pollQuestionSchema },
|
||||
async (ctx) => {
|
||||
const question = await prisma.websitePollQuestion.create({ data: ctx.data });
|
||||
return actionOk({ id: question.id });
|
||||
const question = await prisma.websitePollQuestion.create({ data: ctx.data })
|
||||
return actionOk({ id: question.id })
|
||||
},
|
||||
);
|
||||
)
|
||||
|
||||
const updateQuestionInput = pollQuestionSchema.partial().extend({
|
||||
id: z.coerce.number().int().positive(),
|
||||
});
|
||||
})
|
||||
|
||||
export const updatePollQuestion = adminAction(
|
||||
{ permission: PERMS.POLLS_EDIT, schema: updateQuestionInput },
|
||||
async (ctx) => {
|
||||
const { id, ...data } = ctx.data;
|
||||
await prisma.websitePollQuestion.update({ where: { id }, data });
|
||||
return actionOk({ id });
|
||||
const { id, ...data } = ctx.data
|
||||
await prisma.websitePollQuestion.update({ where: { id }, data })
|
||||
return actionOk({ id })
|
||||
},
|
||||
);
|
||||
)
|
||||
|
||||
const deleteQuestionInput = z.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
});
|
||||
})
|
||||
|
||||
export const deletePollQuestion = adminAction(
|
||||
{ permission: PERMS.POLLS_EDIT, schema: deleteQuestionInput },
|
||||
async (ctx) => {
|
||||
await prisma.websitePollQuestion.delete({ where: { id: ctx.data.id } });
|
||||
return actionOk();
|
||||
await prisma.websitePollQuestion.delete({ where: { id: ctx.data.id } })
|
||||
return actionOk()
|
||||
},
|
||||
);
|
||||
)
|
||||
Reference in new issue
Block a user