admin can delete status changes from post timeline
This commit is contained in:
@@ -509,6 +509,26 @@ export default async function adminPostRoutes(app: FastifyInstance) {
|
||||
}
|
||||
);
|
||||
|
||||
// delete a status change entry
|
||||
app.delete<{ Params: { id: string } }>(
|
||||
"/admin/status-changes/:id",
|
||||
{ preHandler: [app.requireAdmin], config: { rateLimit: { max: 20, timeWindow: "1 minute" } } },
|
||||
async (req, reply) => {
|
||||
const sc = await prisma.statusChange.findUnique({ where: { id: req.params.id }, select: { id: true, postId: true, toStatus: true } });
|
||||
if (!sc) {
|
||||
reply.status(404).send({ error: "Status change not found" });
|
||||
return;
|
||||
}
|
||||
// delete related notifications
|
||||
await prisma.notification.deleteMany({
|
||||
where: { postId: sc.postId, type: "status_changed" },
|
||||
});
|
||||
await prisma.statusChange.delete({ where: { id: sc.id } });
|
||||
req.log.info({ adminId: req.adminId, statusChangeId: sc.id }, "status change deleted");
|
||||
reply.status(204).send();
|
||||
}
|
||||
);
|
||||
|
||||
app.post<{ Params: { id: string }; Body: z.infer<typeof rollbackBody> }>(
|
||||
"/admin/posts/:id/rollback",
|
||||
{ preHandler: [app.requireAdmin], config: { rateLimit: { max: 10, timeWindow: "1 minute" } } },
|
||||
|
||||
Reference in New Issue
Block a user