mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
Add a template page view to allow users to see more details about a template at a glance.
61 lines
1.2 KiB
TypeScript
61 lines
1.2 KiB
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import type { Prisma } from '@documenso/prisma/client';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
|
|
export interface GetTemplateByIdOptions {
|
|
id: number;
|
|
userId: number;
|
|
teamId?: number;
|
|
}
|
|
|
|
export const getTemplateById = async ({ id, userId, teamId }: GetTemplateByIdOptions) => {
|
|
const whereFilter: Prisma.TemplateWhereInput = {
|
|
id,
|
|
OR:
|
|
teamId === undefined
|
|
? [
|
|
{
|
|
userId,
|
|
teamId: null,
|
|
},
|
|
]
|
|
: [
|
|
{
|
|
teamId,
|
|
team: {
|
|
members: {
|
|
some: {
|
|
userId,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
const template = await prisma.template.findFirst({
|
|
where: whereFilter,
|
|
include: {
|
|
directLink: true,
|
|
templateDocumentData: true,
|
|
templateMeta: true,
|
|
Recipient: true,
|
|
Field: true,
|
|
User: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
email: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!template) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, 'Template not found');
|
|
}
|
|
|
|
return template;
|
|
};
|