Files
zooqueen fb4e3df0e3 rename: @hanzo/sign-* → @hanzo/esign-* (full eSign brand consistency)
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.
2026-06-21 19:56:09 -07:00

90 lines
2.2 KiB
TypeScript

import { getHighestOrganisationRoleInGroup } from '@hanzo/esign-lib/utils/organisations';
import {
buildTeamWhereQuery,
extractDerivedTeamSettings,
getHighestTeamRoleInGroup,
} from '@hanzo/esign-lib/utils/teams';
import { prisma } from '@hanzo/esign-prisma';
import type { TGetOrganisationSessionResponse } from './get-organisation-session.types';
/**
* Get all the organisations and teams a user belongs to.
*/
export const getOrganisationSession = async ({
userId,
}: {
userId: number;
}): Promise<TGetOrganisationSessionResponse> => {
const organisations = await prisma.organisation.findMany({
where: {
members: {
some: {
userId,
},
},
},
include: {
organisationClaim: true,
organisationGlobalSettings: true,
subscription: true,
groups: {
where: {
organisationGroupMembers: {
some: {
organisationMember: {
userId,
},
},
},
},
},
teams: {
where: buildTeamWhereQuery({ teamId: undefined, userId }),
include: {
teamGlobalSettings: true,
teamGroups: {
where: {
organisationGroup: {
organisationGroupMembers: {
some: {
organisationMember: {
userId,
},
},
},
},
},
include: {
organisationGroup: true,
},
},
},
},
},
});
return organisations.map((organisation) => {
const { organisationGlobalSettings } = organisation;
return {
...organisation,
teams: organisation.teams.map((team) => {
const derivedSettings = extractDerivedTeamSettings(
organisationGlobalSettings,
team.teamGlobalSettings,
);
return {
...team,
currentTeamRole: getHighestTeamRoleInGroup(team.teamGroups),
preferences: {
aiFeaturesEnabled: derivedSettings.aiFeaturesEnabled,
},
};
}),
currentOrganisationRole: getHighestOrganisationRoleInGroup(organisation.groups),
};
});
};