Skip to content

Commit

Permalink
Added admin routes
Browse files Browse the repository at this point in the history
  • Loading branch information
hkirat committed Aug 14, 2024
1 parent 531b82e commit bbb19be
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import {
getCourse,
getCourseContent,
getCurrentContentType,
} from '@/db/course';
import { getCourse, getFullCourseContent } from '@/db/course';
import { AddContent } from '@/components/admin/AddContent';
import { AdminCourseContent } from '@/components/admin/CourseContent';
import findContentById from '@/lib/find-content-by-id';
import { UpdateVideoClient } from '@/components/admin/UpdateVideoClient';

export default async function UpdateCourseContent({
params,
}: {
params: { courseId: string[] };
params: { moduleId: string[]; courseId: string };
}) {
const courseId = params.courseId[0];
const rest = params.courseId.slice(1);
const courseId = params.courseId;
const rest = params.moduleId;
const course = await getCourse(parseInt(courseId, 10));
const courseContent = await getCourseContent(
parseInt(courseId, 10),
rest.map((x: string) => parseInt(x, 10)),
);
const contentType = await getCurrentContentType(
parseInt(courseId, 10),
rest.map((x: string) => parseInt(x, 10)),
const fullCourseContent = await getFullCourseContent(parseInt(courseId, 10));
const courseContent = findContentById(
fullCourseContent,
rest.map((x) => parseInt(x, 10)),
);
const contentType =
courseContent?.length === 1 ? courseContent[0]?.type : 'folder';

if (contentType === 'video') {
return (
<div className="mx-auto max-w-screen-xl justify-between p-4 text-white">
{/* <ContentRenderer nextContent={null} content={{ id: courseContent[0]?.id || 0, title: courseContent[0]?.title || "", type: contentType || "video", thumbnail: courseContent[0]?.thumbnail || "", description: courseContent[0]?.description ?? "" }} /> */}
Video
<UpdateVideoClient content={courseContent[0]} />
</div>
);
}
Expand All @@ -50,7 +46,8 @@ export default async function UpdateCourseContent({
parentContentId={parseFloat(rest[rest.length - 1])}
/>
<AdminCourseContent
courseContent={courseContent.map((x: any) => ({
rest={rest}
courseContent={courseContent?.map((x: any) => ({
title: x?.title || '',
image: x?.thumbnail || '',
id: x?.id || 0,
Expand Down
57 changes: 57 additions & 0 deletions src/app/admin/content/[courseId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { getCourse, getFullCourseContent } from '@/db/course';
import { AddContent } from '@/components/admin/AddContent';
import { AdminCourseContent } from '@/components/admin/CourseContent';
import findContentById from '@/lib/find-content-by-id';

export default async function UpdateCourseContent({
params,
}: {
params: { courseId: string };
}) {
const courseId = params.courseId;
const rest: string[] = [];
const course = await getCourse(parseInt(courseId, 10));
const fullCourseContent = await getFullCourseContent(parseInt(courseId, 10));
const courseContent = findContentById(
fullCourseContent,
rest.map((x) => parseInt(x, 10)),
);
const contentType =
courseContent?.length === 1 ? courseContent[0]?.type : 'folder';

if (contentType === 'video') {
return (
<div className="mx-auto max-w-screen-xl justify-between p-4 text-white">
Video
</div>
);
}

if (contentType === 'notion') {
return (
<div className="text-blacke mx-auto max-w-screen-xl justify-between p-4 dark:text-white">
Notion doc
</div>
);
}

return (
<div className="mx-auto max-w-screen-xl justify-between p-4 text-black dark:text-white">
{course?.title}
<div className="font-bold md:text-5xl lg:text-6xl">Content</div>
<AddContent
courseId={parseInt(courseId, 10)}
parentContentId={parseFloat(rest[rest.length - 1])}
/>
<AdminCourseContent
rest={rest}
courseContent={courseContent?.map((x: any) => ({
title: x?.title || '',
image: x?.thumbnail || '',
id: x?.id || 0,
}))}
courseId={parseInt(courseId, 10)}
/>
</div>
);
}
21 changes: 21 additions & 0 deletions src/app/api/admin/contentmetadata/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import db from '@/db';
import { NextRequest, NextResponse } from 'next/server';

export const POST = async (req: NextRequest) => {
const {
updates,
contentId,
}: {
updates: any;
contentId: number;
} = await req.json();

await db.videoMetadata.update({
where: {
contentId,
},
data: updates,
});

return NextResponse.json({}, { status: 200 });
};
48 changes: 48 additions & 0 deletions src/app/api/admin/updatecontent/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import db from '@/db';
import { NextRequest, NextResponse } from 'next/server';

export const POST = async (req: NextRequest) => {
const {
updates,
contentId,
}: {
updates: any;
contentId: number;
} = await req.json();

await db.videoMetadata.update({
where: {
contentId,
},
data: {
video_360p_1: updates.video_360p,
video_360p_2: updates.video_360p,
video_360p_3: updates.video_360p,
video_360p_4: updates.video_360p,
video_720p_1: updates.video_720p,
video_720p_2: updates.video_720p,
video_720p_3: updates.video_720p,
video_720p_4: updates.video_720p,
video_1080p_1: updates.video_1080p,
video_1080p_2: updates.video_1080p,
video_1080p_3: updates.video_1080p,
video_1080p_4: updates.video_1080p,
/// mp4s

video_1080p_mp4_1: updates.video_1080p_mp4,
video_1080p_mp4_2: updates.video_1080p_mp4,
video_1080p_mp4_3: updates.video_1080p_mp4,
video_1080p_mp4_4: updates.video_1080p_mp4,
video_720p_mp4_1: updates.video_720p_mp4,
video_720p_mp4_2: updates.video_720p_mp4,
video_720p_mp4_3: updates.video_720p_mp4,
video_720p_mp4_4: updates.video_720p_mp4,
video_360p_mp4_1: updates.video_360p_mp4,
video_360p_mp4_2: updates.video_360p_mp4,
video_360p_mp4_3: updates.video_360p_mp4,
video_360p_mp4_4: updates.video_360p_mp4,
},
});

return NextResponse.json({}, { status: 200 });
};
22 changes: 6 additions & 16 deletions src/app/api/discord/redirect/cohort3/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const WEB3_ROLES: string[] = [
'1264392616171016334',
];

const COHORT3_APPX_IDS = ['12', '13', '14', '15', '16'];
const COHORT3_IDS = [13, 14, 15];

export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
Expand Down Expand Up @@ -64,35 +64,25 @@ export async function POST(req: NextRequest) {
);
}
const purchases = res.courses.filter((purchase: any) =>
COHORT3_APPX_IDS.includes(purchase.appxCourseId),
COHORT3_IDS.includes(purchase.id),
);

const purchaseCourseIds = purchases.map(
(purchase: any) => purchase.appxCourseId,
);
const purchaseCourseIds = purchases.map((purchase: any) => purchase.id);
const roles: string[] = [];

let hasWebDev = false;
let hasDevOps = false;
let hasWeb3 = false;

if (
purchaseCourseIds.includes('12') ||
purchaseCourseIds.includes('14') ||
purchaseCourseIds.includes('15')
) {
if (purchaseCourseIds.includes(14)) {
hasWebDev = true;
}

if (
purchaseCourseIds.includes('12') ||
purchaseCourseIds.includes('14') ||
purchaseCourseIds.includes('16')
) {
if (purchaseCourseIds.includes(15)) {
hasDevOps = true;
}

if (purchaseCourseIds.includes('13') || purchaseCourseIds.includes('14')) {
if (purchaseCourseIds.includes(13)) {
hasWeb3 = true;
}

Expand Down
2 changes: 0 additions & 2 deletions src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use client';

import { Button } from '@/components/ui/button';
import { InfoIcon } from 'lucide-react';
import Link from 'next/link';
import { useEffect } from 'react';

export default function ErrorPage({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
Expand Down
12 changes: 9 additions & 3 deletions src/components/admin/CourseContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@ import { ContentCard } from '../ContentCard';
export const AdminCourseContent = ({
courseContent,
courseId,
rest,
}: {
courseId: number;
courseContent: {
title: string;
image: string;
id: number;
}[];
rest: string[];
}) => {
const router = useRouter();
let updatedRoute = `/admin/content/${courseId}`;
for (let i = 0; i < rest.length; i++) {
updatedRoute += `/${rest[i]}`;
}

return (
<div>
Course content
<div className="mx-auto grid max-w-screen-xl cursor-pointer grid-cols-1 justify-between gap-5 p-4 md:grid-cols-3">
{courseContent.map(
{courseContent?.map(
(content: { image: string; id: number; title: string }) => (
<ContentCard
type={'folder'}
title={content.title}
image={content.image || ''}
onClick={() => {
router.push(`/admin/content/${courseId}/${content.id}`);
router.push(`${updatedRoute}/${content.id}`);
}}
key={content.id}
/>
),
)}
) ?? []}
</div>
</div>
);
Expand Down
Loading

0 comments on commit bbb19be

Please sign in to comment.