mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
feat: add organisations (#1820)
This commit is contained in:
@ -4,9 +4,11 @@ import { Prisma } from '@prisma/client';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import type { FindResultResponse } from '../../types/search-params';
|
||||
import { getHighestTeamRoleInGroup } from '../../utils/teams';
|
||||
|
||||
export interface FindTeamsOptions {
|
||||
userId: number;
|
||||
organisationId: string;
|
||||
query?: string;
|
||||
page?: number;
|
||||
perPage?: number;
|
||||
@ -18,6 +20,7 @@ export interface FindTeamsOptions {
|
||||
|
||||
export const findTeams = async ({
|
||||
userId,
|
||||
organisationId,
|
||||
query,
|
||||
page = 1,
|
||||
perPage = 10,
|
||||
@ -27,9 +30,20 @@ export const findTeams = async ({
|
||||
const orderByDirection = orderBy?.direction ?? 'desc';
|
||||
|
||||
const whereClause: Prisma.TeamWhereInput = {
|
||||
members: {
|
||||
organisation: {
|
||||
id: organisationId,
|
||||
},
|
||||
teamGroups: {
|
||||
some: {
|
||||
userId,
|
||||
organisationGroup: {
|
||||
organisationGroupMembers: {
|
||||
some: {
|
||||
organisationMember: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -50,9 +64,17 @@ export const findTeams = async ({
|
||||
[orderByColumn]: orderByDirection,
|
||||
},
|
||||
include: {
|
||||
members: {
|
||||
teamGroups: {
|
||||
where: {
|
||||
userId,
|
||||
organisationGroup: {
|
||||
organisationGroupMembers: {
|
||||
some: {
|
||||
organisationMember: {
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -64,8 +86,7 @@ export const findTeams = async ({
|
||||
|
||||
const maskedData = data.map((team) => ({
|
||||
...team,
|
||||
currentTeamMember: team.members[0],
|
||||
members: undefined,
|
||||
currentTeamRole: getHighestTeamRoleInGroup(team.teamGroups),
|
||||
}));
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user