Skip to content

Commit e8e725f

Browse files
committed
fixed types in route handlers
1 parent 1b624d5 commit e8e725f

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

src/app/(stories)/learn/welcome.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use client";
22
import styles from "./learn.module.css";
33
import { signIn } from "next-auth/react";
4-
import styles2 from "../auth/register.module.css";
4+
import styles2 from "../../auth/register.module.css";
55
import Link from "next/link";
66
import React from "react";
77

8-
export default async function Page() {
8+
export default function Page() {
99
return (
1010
<div className={styles.container}>
1111
<div>

src/app/editor/(course)/approve/[story_id]/route.js renamed to src/app/editor/(course)/approve/[story_id]/route.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { sql } from "@/lib/db";
2-
import { NextResponse } from "next/server";
2+
import { NextRequest, NextResponse } from "next/server";
33
import { revalidateTag } from "next/cache";
44
import { getUser } from "@/lib/userInterface";
55

6-
export async function GET(req, { params: { story_id } }) {
7-
const token = await getUser(req);
6+
export async function GET(
7+
request: Request,
8+
{ params }: { params: Promise<{ story_id: string }> },
9+
) {
10+
const token = await getUser();
811

9-
if (!token.role) return new Response("Error not allowed", { status: 401 });
12+
if (!token || !token.role || !token.id)
13+
return new Response("Error not allowed", { status: 401 });
1014

1115
let answer = await set_approve({
12-
story_id: parseInt(story_id),
13-
user_id: token?.id,
16+
story_id: parseInt((await params).story_id),
17+
user_id: parseInt(token.id),
1418
});
1519

1620
if (answer === undefined)
@@ -19,14 +23,20 @@ export async function GET(req, { params: { story_id } }) {
1923
return NextResponse.json(answer);
2024
}
2125

22-
async function set_status(data) {
26+
async function set_status(data: { status: string | undefined; id: number }) {
2327
return sql`
2428
UPDATE story SET ${sql(data, "status")}
2529
WHERE id = ${data.id}
2630
`;
2731
}
2832

29-
async function set_approve({ story_id, user_id }) {
33+
async function set_approve({
34+
story_id,
35+
user_id,
36+
}: {
37+
story_id: number;
38+
user_id: number;
39+
}) {
3040
let res =
3141
await sql`SELECT id FROM story_approval WHERE story_id = ${story_id} AND user_id = ${user_id};`;
3242
let action;

src/app/editor/(course)/course/[course_id]/import/send/[story_id]/route.js renamed to src/app/editor/(course)/course/[course_id]/import/send/[story_id]/route.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ import { upload_github } from "@/lib/editor/upload_github";
33
import { NextResponse } from "next/server";
44
import { getUser } from "@/lib/userInterface";
55

6-
export async function GET(req, { params: { course_id, story_id } }) {
7-
const token = await getUser(req);
6+
export async function GET(
7+
req: Request,
88

9-
if (!token.role)
9+
{ params }: { params: Promise<{ course_id: string; story_id: string }> },
10+
) {
11+
const token = await getUser();
12+
13+
if (!token || !token.role || !token.id || !token.name)
1014
return new Response("You need to be a registered contributor.", {
1115
status: 401,
1216
});
1317

1418
let answer = await set_import(
15-
{ id: story_id, course_id: course_id },
16-
{ user_id: token?.id, username: token?.name },
19+
{ id: (await params).story_id, course_id: (await params).course_id },
20+
{ user_id: token.id, username: token.name },
1721
);
1822

1923
if (answer === undefined)
@@ -22,7 +26,10 @@ export async function GET(req, { params: { course_id, story_id } }) {
2226
return NextResponse.json(answer);
2327
}
2428

25-
async function set_import({ id, course_id }, { user_id, username }) {
29+
async function set_import(
30+
{ id, course_id }: { id: string; course_id: string },
31+
{ user_id, username }: { user_id: string; username: string },
32+
) {
2633
let data = (
2734
await sql`SELECT duo_id, name, image, set_id, set_index, text, json FROM story WHERE id = ${id};`
2835
)[0];

src/components/login/LoggedInButtonWrappedClient.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function LoggedInButtonWrappedClient(props: {
1515
page,
1616
);
1717
const user = session?.user;
18-
console.log("user", user);
18+
1919
return (
2020
<>
2121
{user ? (

src/components/login/LoggedInButtonWrappedServer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export async function LoggedInButtonWrapped(props: {
77
page: string;
88
}) {
99
const { course_id, page } = props;
10-
console.log("------------------------LoggedInButtonWrapped", course_id, page);
1110
const user = await getUser();
12-
console.log("user", user);
11+
1312
return (
1413
<>
1514
{user ? (

src/lib/userInterface.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
import { redirect } from "next/navigation";
33
import { auth } from "@/auth";
44
import { NextApiRequest, NextApiResponse } from "next";
5+
import { NextRequest } from "next/server";
56

67
export async function getUser(
7-
req?: NextApiRequest | undefined,
8+
req?: NextRequest | undefined,
89
response?: NextApiResponse | undefined,
910
) {
1011
if (typeof req !== "undefined" && typeof response !== "undefined") {
11-
const session = await auth(req, response);
12+
const session = await auth();
1213
//console.log("sessionAPI", session);
1314

1415
return session?.user;
1516
}
1617
const session = await auth();
1718
//console.log("sessionHTML", session);
1819
return session?.user;
19-
return { admin: false };
2020
}
2121

2222
export async function requireAdmin() {

0 commit comments

Comments
 (0)