mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: add organisations (#1820)
This commit is contained in:
56
packages/trpc/server/admin-router/get-admin-organisation.ts
Normal file
56
packages/trpc/server/admin-router/get-admin-organisation.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { adminProcedure } from '../trpc';
|
||||
import {
|
||||
ZGetAdminOrganisationRequestSchema,
|
||||
ZGetAdminOrganisationResponseSchema,
|
||||
} from './get-admin-organisation.types';
|
||||
|
||||
export const getAdminOrganisationRoute = adminProcedure
|
||||
.input(ZGetAdminOrganisationRequestSchema)
|
||||
.output(ZGetAdminOrganisationResponseSchema)
|
||||
.query(async ({ input }) => {
|
||||
const { organisationId } = input;
|
||||
|
||||
return await getAdminOrganisation({
|
||||
organisationId,
|
||||
});
|
||||
});
|
||||
|
||||
type GetOrganisationOptions = {
|
||||
organisationId: string;
|
||||
};
|
||||
|
||||
export const getAdminOrganisation = async ({ organisationId }: GetOrganisationOptions) => {
|
||||
const organisation = await prisma.organisation.findFirst({
|
||||
where: {
|
||||
id: organisationId,
|
||||
},
|
||||
include: {
|
||||
organisationClaim: true,
|
||||
organisationGlobalSettings: true,
|
||||
teams: true,
|
||||
members: {
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
subscription: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!organisation) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Organisation not found',
|
||||
});
|
||||
}
|
||||
|
||||
return organisation;
|
||||
};
|
||||
Reference in New Issue
Block a user