-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(team): implement editing team name, kicking team member and leav…
…ing team
- Loading branch information
1 parent
fd13d75
commit 3109cf0
Showing
8 changed files
with
259 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use server"; | ||
|
||
import { prisma } from "@/services/prisma"; | ||
import { revalidatePath } from "next/cache"; | ||
import requireTeamOwnerSession from "@/server/services/helpers/requireTeamOwnerSession"; | ||
|
||
type EditTeamNameInput = { | ||
newName: string; | ||
}; | ||
const editTeamName = async ({ newName }: EditTeamNameInput) => { | ||
const { team } = await requireTeamOwnerSession(); | ||
|
||
await prisma.team.update({ | ||
where: { | ||
id: team.id, | ||
}, | ||
data: { | ||
name: newName, | ||
}, | ||
}); | ||
|
||
revalidatePath("/application", "page"); | ||
}; | ||
|
||
export default editTeamName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use server"; | ||
|
||
import { prisma } from "@/services/prisma"; | ||
import { revalidatePath } from "next/cache"; | ||
import requireTeamOwnerSession from "@/server/services/helpers/requireTeamOwnerSession"; | ||
|
||
type KickTeamMemberInput = { | ||
memberId: number; | ||
}; | ||
const kickTeamMember = async ({ memberId }: KickTeamMemberInput) => { | ||
const { hacker } = await requireTeamOwnerSession(); | ||
|
||
if (memberId === hacker.id) { | ||
throw new Error("You cannot kick yourself"); | ||
} | ||
|
||
await prisma.hacker.update({ | ||
where: { | ||
id: memberId, | ||
}, | ||
data: { | ||
teamId: null, | ||
}, | ||
}); | ||
|
||
revalidatePath("/application", "page"); | ||
}; | ||
|
||
export default kickTeamMember; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"use server"; | ||
|
||
import { prisma } from "@/services/prisma"; | ||
import requireHackerSession from "@/server/services/helpers/requireHackerSession"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
const leaveTeam = async () => { | ||
const hacker = await requireHackerSession(); | ||
|
||
if (!hacker.teamId) { | ||
throw new Error("Hacker is not in a team"); | ||
} | ||
|
||
const teamId = hacker.teamId; | ||
|
||
const team = await prisma.team.findUnique({ | ||
where: { | ||
id: teamId, | ||
}, | ||
select: { | ||
id: true, | ||
ownerId: true, | ||
}, | ||
}); | ||
|
||
if (!team) { | ||
throw new Error("Team not found"); | ||
} | ||
|
||
if (team.ownerId === hacker.id) { | ||
throw new Error("Owner cannot leave team"); | ||
} | ||
|
||
await prisma.hacker.update({ | ||
where: { | ||
id: hacker.id, | ||
}, | ||
data: { | ||
teamId: null, | ||
}, | ||
}); | ||
|
||
revalidatePath("/application", "page"); | ||
}; | ||
|
||
export default leaveTeam; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.