26 lines
993 B
TypeScript
26 lines
993 B
TypeScript
import { findMemberProjectChatLink, type MemberProjectChatLink } from "@hivegrid/chat/project-link.server";
|
|
import { CatalogError } from "@hivegrid/foundation";
|
|
|
|
import { loadChatContext } from "../routes/chatAccess.server";
|
|
|
|
export async function loadOptionalProjectChatLink(input: {
|
|
readonly request: Request;
|
|
readonly params: Record<string, string | undefined>;
|
|
readonly projectId: string;
|
|
}): Promise<MemberProjectChatLink | null> {
|
|
try {
|
|
const context = await loadChatContext({ request: input.request, params: input.params });
|
|
return await findMemberProjectChatLink({
|
|
tenantId: context.tenantId,
|
|
userId: context.userId,
|
|
permissions: context.permissions,
|
|
projectId: input.projectId,
|
|
});
|
|
} catch (error) {
|
|
// Chat is optional on the project surface. Missing module, permission or
|
|
// membership all resolve to the same absent affordance.
|
|
if (error instanceof CatalogError && error.status === 404) return null;
|
|
throw error;
|
|
}
|
|
}
|