chore: improve validate hosts api v2 team event-types (#19696)

* chore: improve validate hosts api v2 team event-types

* fixup! chore: improve validate hosts api v2 team event-types
This commit is contained in:
Morgan authored and GitHub committed 2025-03-04 08:55:40 +00:00
1 parent 72832354e6
commit ae8180e7c2
2 files changed
+9 -8

No files matched your search

@@ -245,7 +245,11 @@ export class InputOrganizationsEventTypesService {
const membersIds = await this.teamsRepository.getTeamMembersIds(teamId);
const invalidHosts = hosts.filter((host) => !membersIds.includes(host.userId));
if (invalidHosts.length) {
throw new NotFoundException(`Invalid hosts: ${invalidHosts.join(", ")}`);
throw new NotFoundException(
`Invalid hosts: ${invalidHosts
.map((host) => host.userId)
.join(", ")} are not members of team with id ${teamId}.`
);
}
}
}
@@ -31,19 +31,16 @@ export class TeamsRepository {
}
async getTeamMembersIds(teamId: number) {
const team = await this.dbRead.prisma.team.findUnique({
const teamMembers = await this.dbRead.prisma.membership.findMany({
where: {
id: teamId,
},
include: {
members: true,
teamId,
},
});
if (!team) {
if (!teamMembers || teamMembers.length === 0) {
return [];
}
return team.members.map((member) => member.userId);
return teamMembers.map((member) => member.userId);
}
async getTeamsUserIsMemberOf(userId: number) {