mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign). Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files) and align docker/Dockerfile turbo --scope/--filter to the actual remix package name @hanzo/esign (was a pre-existing mismatch with -remix that broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { AppError, AppErrorCode } from '@hanzo/esign-lib/errors/app-error';
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import { TEAM_DOCUMENT_VISIBILITY_MAP } from '../../constants/teams';
|
|
import { buildTeamWhereQuery, canAccessTeamDocument } from '../../utils/teams';
|
|
import { getTeamById } from '../team/get-team';
|
|
|
|
export interface DeleteFolderOptions {
|
|
userId: number;
|
|
teamId: number;
|
|
folderId: string;
|
|
}
|
|
|
|
export const deleteFolder = async ({ userId, teamId, folderId }: DeleteFolderOptions) => {
|
|
const team = await getTeamById({ userId, teamId });
|
|
|
|
const folder = await prisma.folder.findFirst({
|
|
where: {
|
|
id: folderId,
|
|
team: buildTeamWhereQuery({
|
|
teamId,
|
|
userId,
|
|
}),
|
|
visibility: {
|
|
in: TEAM_DOCUMENT_VISIBILITY_MAP[team.currentTeamRole],
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!folder) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Folder not found',
|
|
});
|
|
}
|
|
|
|
const hasPermission = canAccessTeamDocument(team.currentTeamRole, folder.visibility);
|
|
|
|
if (!hasPermission) {
|
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
|
message: 'You do not have permission to delete this folder',
|
|
});
|
|
}
|
|
|
|
return await prisma.folder.delete({
|
|
where: {
|
|
id: folder.id,
|
|
},
|
|
});
|
|
};
|