Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsFlash10 committed Oct 20, 2024
1 parent 45668f6 commit cdb5086
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function checkUserContentAccess(userId: string, contentId: string) {
course: {
purchasedBy: {
some: {
userId: userId,
userId,
},
},
},
Expand All @@ -21,13 +21,19 @@ async function checkUserContentAccess(userId: string, contentId: string) {
return userContent !== null;
}

export async function GET(req : NextRequest,{ params }: { params: { contentId: string } }) {
export async function GET(
req: NextRequest,
{ params }: { params: { contentId: string } },
) {
try {
const { contentId } = params;
const user = JSON.parse(req.headers.get('g') || '');
const userContentAccess = await checkUserContentAccess(user.id, contentId);
if (!userContentAccess) {
return NextResponse.json({ message: 'User does not have access to this content' }, { status: 403 });
return NextResponse.json(
{ message: 'User does not have access to this content' },
{ status: 403 },
);
}
const contents = await db.content.findUnique({
where: {
Expand Down
16 changes: 11 additions & 5 deletions src/app/api/mobile/courses/[courseId]/[collectionId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ async function checkUserCollectionAccess(userId: string, collectionId: string) {
course: {
purchasedBy: {
some: {
userId: userId,
userId,
},
},
},
},
},
},
},
Expand All @@ -31,11 +31,17 @@ export async function GET(
if (!user) {
return NextResponse.json({ message: 'User not found' }, { status: 401 });
}

const { collectionId } = params;
const userHasCollectionAccess = await checkUserCollectionAccess(user.id, collectionId);
const userHasCollectionAccess = await checkUserCollectionAccess(
user.id,
collectionId,
);
if (!userHasCollectionAccess) {
return NextResponse.json({ message: 'User does not have access to this collection' }, { status: 403 });
return NextResponse.json(
{ message: 'User does not have access to this collection' },
{ status: 403 },
);
}
const collectionData = await db.content.findMany({
where: {
Expand Down
3 changes: 1 addition & 2 deletions src/app/api/mobile/courses/[courseId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function checkUserCourseAccess(userId: string, courseId: string) {
where: {
purchasedBy: {
some: {
userId: userId,
userId,
},
},
id: parseInt(courseId, 10),
Expand All @@ -16,7 +16,6 @@ async function checkUserCourseAccess(userId: string, courseId: string) {
return userCourse !== null;
}


export async function GET(
request: NextRequest,
{ params }: { params: { courseId: string } },
Expand Down

0 comments on commit cdb5086

Please sign in to comment.