mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
ESLint 10's recommended set added no-useless-assignment, which fails on a value no later statement can read. Fourteen places had one: - An initial value every path overwrites before reading: `let x = null` ahead of a try that assigns it or leaves, the webhook response body both branches set, the rate-limit loop's counter, the avatar's previous id and the license response. They are declared without one; TypeScript still checks each is assigned before use. - Konva stages and layers set to null after destroy(), just before the function returns and the variable goes out of scope. The nulls go, and the variables are const. - Two in the v1 PDF field writer: textFieldBoxY recomputed after the only read of it had already been copied into adjustedFieldY, and a line reset to '' that both following branches overwrite. - The folder breadcrumbs' currentFolderId, reassigned in a loop that walks by currentFolder.parentId; the first query reads folderId directly. No output changes: each removed value was provably never read. Co-authored-by: Hanzo Dev <[email protected]>
78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import { TeamMemberRole } from '@prisma/client';
|
|
import { match } from 'ts-pattern';
|
|
|
|
import { prisma } from '@hanzo/esign-prisma';
|
|
|
|
import { DocumentVisibility } from '../../types/document-visibility';
|
|
import type { TFolderType } from '../../types/folder-type';
|
|
import { getTeamById } from '../team/get-team';
|
|
|
|
export interface GetFolderBreadcrumbsOptions {
|
|
userId: number;
|
|
teamId: number;
|
|
folderId: string;
|
|
type?: TFolderType;
|
|
}
|
|
|
|
export const getFolderBreadcrumbs = async ({
|
|
userId,
|
|
teamId,
|
|
folderId,
|
|
type,
|
|
}: GetFolderBreadcrumbsOptions) => {
|
|
const team = await getTeamById({ userId, teamId });
|
|
|
|
const visibilityFilters = match(team.currentTeamRole)
|
|
.with(TeamMemberRole.ADMIN, () => ({
|
|
visibility: {
|
|
in: [
|
|
DocumentVisibility.EVERYONE,
|
|
DocumentVisibility.MANAGER_AND_ABOVE,
|
|
DocumentVisibility.ADMIN,
|
|
],
|
|
},
|
|
}))
|
|
.with(TeamMemberRole.MANAGER, () => ({
|
|
visibility: {
|
|
in: [DocumentVisibility.EVERYONE, DocumentVisibility.MANAGER_AND_ABOVE],
|
|
},
|
|
}))
|
|
.otherwise(() => ({ visibility: DocumentVisibility.EVERYONE }));
|
|
|
|
const whereClause = (folderId: string) => ({
|
|
id: folderId,
|
|
...(type ? { type } : {}),
|
|
OR: [
|
|
{ teamId, ...visibilityFilters },
|
|
{ userId, teamId },
|
|
],
|
|
});
|
|
|
|
const breadcrumbs = [];
|
|
|
|
const currentFolder = await prisma.folder.findFirst({
|
|
where: whereClause(folderId),
|
|
});
|
|
|
|
if (!currentFolder) {
|
|
return [];
|
|
}
|
|
|
|
breadcrumbs.push(currentFolder);
|
|
|
|
while (currentFolder?.parentId) {
|
|
const parentFolder = await prisma.folder.findFirst({
|
|
where: whereClause(currentFolder.parentId),
|
|
});
|
|
|
|
if (!parentFolder) {
|
|
break;
|
|
}
|
|
|
|
breadcrumbs.unshift(parentFolder);
|
|
currentFolder.parentId = parentFolder.parentId;
|
|
}
|
|
|
|
return breadcrumbs;
|
|
};
|