"use strict";
const httpError = require("./http-error-mkY8Ke7V.cjs");
const index = require("./user-v6mfWQ2d.cjs");
const throwIfNotHaveAdminAccessToTeam = async ({
  teamId,
  userId
}) => {
  if (!teamId) {
    return;
  }
  const userRepo = new index.UserRepository(index.prisma);
  const userAdminTeams = await userRepo.getUserAdminTeams({ userId });
  const teamsUserHasAdminAccessFor = userAdminTeams?.teams?.map(({ team }) => team.id) ?? [];
  const hasAdminAccessToTeam = teamsUserHasAdminAccessFor.some((id) => id === teamId);
  if (!hasAdminAccessToTeam) {
    throw new httpError.HttpError({ statusCode: 401, message: "You must be an admin of the team to do this" });
  }
};
exports.throwIfNotHaveAdminAccessToTeam = throwIfNotHaveAdminAccessToTeam;
