spotify controls
This commit is contained in:
@@ -6,11 +6,6 @@ import { toServerResult } from "@/lib/tanstack-query/utils/to-server-result";
|
||||
import { teamInputSchema, teamUpdateSchema } from "./types";
|
||||
import { logger } from "@/lib/logger";
|
||||
|
||||
export const listTeams = createServerFn()
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async () =>
|
||||
toServerResult(() => pbAdmin.listTeams())
|
||||
);
|
||||
|
||||
export const listTeamInfos = createServerFn()
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
@@ -40,22 +35,10 @@ export const createTeam = createServerFn()
|
||||
const userId = context.userAuthId;
|
||||
const isAdmin = context.roles.includes("Admin");
|
||||
|
||||
// Check if user is trying to create a team with themselves as a player
|
||||
if (!isAdmin && !data.players.includes(userId)) {
|
||||
throw new Error("You can only create teams that include yourself as a player");
|
||||
}
|
||||
|
||||
// Additional validation: ensure user is not already on another team
|
||||
if (!isAdmin) {
|
||||
const userTeams = await pbAdmin.listTeams();
|
||||
const existingTeam = userTeams.find(team =>
|
||||
team.players.some(player => player.id === userId)
|
||||
);
|
||||
if (existingTeam) {
|
||||
throw new Error(`You are already a member of team "${existingTeam.name}"`);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Creating team", { name: data.name, userId, isAdmin });
|
||||
return pbAdmin.createTeam(data);
|
||||
})
|
||||
@@ -88,10 +71,3 @@ export const updateTeam = createServerFn()
|
||||
return pbAdmin.updateTeam(id, updates);
|
||||
})
|
||||
);
|
||||
|
||||
export const deleteTeam = createServerFn()
|
||||
.validator(z.string())
|
||||
.middleware([superTokensAdminFunctionMiddleware])
|
||||
.handler(async ({ data: teamId }) =>
|
||||
toServerResult(() => pbAdmin.deleteTeam(teamId))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user