feat: add folders (#1711)

This commit is contained in:
Catalin Pit
2025-05-01 19:46:59 +03:00
committed by GitHub
parent 12ada567f5
commit 17370749b4
91 changed files with 10497 additions and 183 deletions

View File

@ -20,6 +20,7 @@ export const createTemplate = async ({
userId,
teamId,
templateDocumentDataId,
folderId,
}: CreateTemplateOptions) => {
let team = null;
@ -43,12 +44,38 @@ export const createTemplate = async ({
}
}
const folder = await prisma.folder.findFirstOrThrow({
where: {
id: folderId,
...(teamId
? {
team: {
id: teamId,
members: {
some: {
userId,
},
},
},
}
: {
userId,
teamId: null,
}),
},
});
if (!team) {
throw new AppError(AppErrorCode.NOT_FOUND);
}
return await prisma.template.create({
data: {
title,
userId,
templateDocumentDataId,
teamId,
folderId: folder.id,
templateMeta: {
create: {
language: team?.teamGlobalSettings?.documentLanguage,

View File

@ -12,6 +12,7 @@ export type FindTemplatesOptions = {
type?: Template['type'];
page?: number;
perPage?: number;
folderId?: string;
};
export const findTemplates = async ({
@ -20,6 +21,7 @@ export const findTemplates = async ({
type,
page = 1,
perPage = 10,
folderId,
}: FindTemplatesOptions) => {
const whereFilter: Prisma.TemplateWhereInput[] = [];
@ -67,6 +69,12 @@ export const findTemplates = async ({
);
}
if (folderId) {
whereFilter.push({ folderId });
} else {
whereFilter.push({ folderId: null });
}
const [data, count] = await Promise.all([
prisma.template.findMany({
where: {

View File

@ -6,9 +6,15 @@ export type GetTemplateByIdOptions = {
id: number;
userId: number;
teamId?: number;
folderId?: string | null;
};
export const getTemplateById = async ({ id, userId, teamId }: GetTemplateByIdOptions) => {
export const getTemplateById = async ({
id,
userId,
teamId,
folderId = null,
}: GetTemplateByIdOptions) => {
const template = await prisma.template.findFirst({
where: {
id,
@ -27,6 +33,7 @@ export const getTemplateById = async ({ id, userId, teamId }: GetTemplateByIdOpt
userId,
teamId: null,
}),
...(folderId ? { folderId } : {}),
},
include: {
directLink: true,
@ -41,6 +48,7 @@ export const getTemplateById = async ({ id, userId, teamId }: GetTemplateByIdOpt
email: true,
},
},
folder: true,
},
});