Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

fix: makes challenge data not allow banned users. (#292)

Jim Burbridge6c988c33ea51
diff --git a/src/app/challenge/[id]/getChallengeRouteData.ts b/src/app/challenge/[id]/getChallengeRouteData.ts
index 81210484..67107b14 100644
--- a/src/app/challenge/[id]/getChallengeRouteData.ts
+++ b/src/app/challenge/[id]/getChallengeRouteData.ts
@@ -8,7 +8,14 @@ export type ChallengeRouteData = NonNullable<Awaited<ReturnType<typeof getChalle
// this is to data to populate the description tab (default tab on challenge page)
export const getChallengeRouteData = cache(async (id: string, session: Session | null) => {
const challenge = await prisma.challenge.findFirst({
- where: { id: +id },
+ where: {
+ id: +id,
+ user: {
+ NOT: {
+ status: 'BANNED'
+ }
+ }
+ },
include: {
user: true,
_count: {
diff --git a/src/app/challenge/[id]/layout.tsx b/src/app/challenge/[id]/layout.tsx
index 96d9cce4..6da2facb 100644
--- a/src/app/challenge/[id]/layout.tsx
+++ b/src/app/challenge/[id]/layout.tsx
@@ -3,6 +3,7 @@ import { Wrapper } from './wrapper';
import { getChallengeRouteData } from './getChallengeRouteData';
import { getServerAuthSession } from '~/server/auth';
import { LeftWrapper } from './left-wrapper';
+import { redirect } from 'next/navigation';
export default async function LayoutData({
children,
@@ -13,7 +14,8 @@ export default async function LayoutData({
}) {
const session = await getServerAuthSession();
const challenge = await getChallengeRouteData(id, session);
- if (!challenge) return <div>loading</div>;
+
+ if (!challenge) return redirect('/explore');
return (
<ChallengeLayout
diff --git a/src/components/explore/index.tsx b/src/components/explore/index.tsx
index 29851510..5edd0b08 100644
--- a/src/components/explore/index.tsx
+++ b/src/components/explore/index.tsx
@@ -37,6 +37,11 @@ async function getEasyChallenges() {
where: {
visibility: 'VISIBLE',
difficulty: { in: ['EASY'] },
+ user: {
+ NOT: {
+ status: 'BANNED'
+ }
+ }
},
include: {
_count: {
@@ -53,6 +58,11 @@ async function getMediumChallenges() {
where: {
visibility: 'VISIBLE',
difficulty: { in: ['MEDIUM'] },
+ user: {
+ NOT: {
+ status: 'BANNED'
+ }
+ }
},
include: {
_count: {
@@ -69,6 +79,11 @@ async function getHardChallenges() {
where: {
visibility: 'VISIBLE',
difficulty: { in: ['HARD'] },
+ user: {
+ NOT: {
+ status: 'BANNED'
+ }
+ }
},
include: {
_count: {