Files
documenso/packages/trpc/server/organisation-router/get-organisation.ts
ephraimduncan 138d663c25 chore: merge main, resolve biome formatting conflicts
Merge origin/main into feat/external-2fa-codes. Resolve formatting
conflicts caused by biome rollout; preserve both feature streams:
PR's external 2FA token + signing-session 2FA proof additions plus
main's RateLimit/RecipientExpired/signingReminders/date-auto-insert.

In complete-document-with-token.ts, drop the duplicate early
field-fetching block introduced when main moved that logic later
with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH
check using derivedRecipientActionAuth.
2026-05-12 11:46:11 +00:00

85 lines
1.9 KiB
TypeScript

import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import { prisma } from '@documenso/prisma';
import { authenticatedProcedure } from '../trpc';
import { ZGetOrganisationRequestSchema, ZGetOrganisationResponseSchema } from './get-organisation.types';
export const getOrganisationRoute = authenticatedProcedure
// .meta(getOrganisationMeta)
.input(ZGetOrganisationRequestSchema)
.output(ZGetOrganisationResponseSchema)
.query(async ({ input, ctx }) => {
const { organisationReference } = input;
ctx.logger.info({
input: {
organisationReference,
},
});
return await getOrganisation({
userId: ctx.user.id,
organisationReference,
});
});
type GetOrganisationOptions = {
userId: number;
/**
* The ID or URL of the organisation.
*/
organisationReference: string;
};
export const getOrganisation = async ({ userId, organisationReference }: GetOrganisationOptions) => {
const organisation = await prisma.organisation.findFirst({
where: {
OR: [{ id: organisationReference }, { url: organisationReference }],
members: {
some: {
userId,
},
},
},
include: {
organisationGlobalSettings: true,
subscription: true,
organisationClaim: true,
members: {
select: {
id: true,
},
},
teams: {
where: {
teamGroups: {
some: {
organisationGroup: {
organisationGroupMembers: {
some: {
organisationMember: {
userId,
},
},
},
},
},
},
},
},
},
});
if (!organisation) {
throw new AppError(AppErrorCode.NOT_FOUND, {
message: 'Organisation not found',
});
}
return {
...organisation,
teams: organisation.teams,
};
};