Files
var-monorepo/apps/hub/app/(app)/admin/changelog/action.ts
2025-07-25 16:53:22 -07:00

34 lines
834 B
TypeScript

"use server";
import { prisma, Prisma, Changelog } from "@repo/db";
export const upsertChangelog = async (
changelog: Prisma.ChangelogCreateInput,
id?: Changelog["id"],
options?: {
skipUserUpdate?: boolean;
},
) => {
const newChangelog = id
? await prisma.changelog.update({
where: { id: id },
data: changelog,
})
: await prisma.$transaction(async (prisma) => {
const createdChangelog = await prisma.changelog.create({ data: changelog });
if (!options?.skipUserUpdate) {
// Update all users to acknowledge the new changelog
await prisma.user.updateMany({
data: { changelogAck: false },
});
}
return createdChangelog;
});
return newChangelog;
};
export const deleteChangelog = async (id: Changelog["id"]) => {
await prisma.changelog.delete({ where: { id: id } });
};