mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
feat: create a banner with custom text by admin
This commit is contained in:
@ -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;
|
||||
|
||||
11
packages/lib/server-only/banner/get-banner.ts
Normal file
11
packages/lib/server-only/banner/get-banner.ts
Normal file
@ -0,0 +1,11 @@
|
||||
'use server';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export const getBanner = async () => {
|
||||
return await prisma.banner.findUnique({
|
||||
where: {
|
||||
id: 1,
|
||||
},
|
||||
});
|
||||
};
|
||||
28
packages/lib/server-only/banner/upsert-banner.ts
Normal file
28
packages/lib/server-only/banner/upsert-banner.ts
Normal 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 ?? '' },
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user