feat: create a banner with custom text by admin

This commit is contained in:
Ephraim Atta-Duncan
2024-02-22 20:13:17 +00:00
parent 15e191f62d
commit c436559787
15 changed files with 291 additions and 12 deletions

View File

@ -1,5 +1,5 @@
import { prisma } from '@documenso/prisma';
import { Role } from '@documenso/prisma/client';
import type { Role } from '@documenso/prisma/client';
export type UpdateUserOptions = {
id: number;

View File

@ -0,0 +1,11 @@
'use server';
import { prisma } from '@documenso/prisma';
export const getBanner = async () => {
return await prisma.banner.findUnique({
where: {
id: 1,
},
});
};

View File

@ -0,0 +1,28 @@
'use server';
import { prisma } from '@documenso/prisma';
import { Role } from '@documenso/prisma/client';
export type UpdateUserOptions = {
userId: number;
show?: boolean;
text?: string | undefined;
};
export const upsertBanner = async ({ userId, show, text }: UpdateUserOptions) => {
const user = await prisma.user.findUnique({
where: {
id: userId,
},
});
if (!user?.roles.includes(Role.ADMIN)) {
throw Error('You are unauthorised to perform this action');
}
return await prisma.banner.upsert({
where: { id: 1, user: {} },
update: { show, text },
create: { show, text: text ?? '' },
});
};