Skip to content

Commit fe874e0

Browse files
Merge pull request #42 from Eshvar-Thevar/Reports
lint
2 parents 80eb089 + 0454a0c commit fe874e0

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/app/api/reports/route.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// This file defines the API route for POST /api/reports
22
// It lets logged-in users submit a report for a specific file.
33

4-
import { NextResponse } from "next/server"; // Used to send HTTP responses (JSON, status codes)
5-
import { z } from "zod"; // Zod validates and parses input data
4+
import { NextResponse } from 'next/server'; // Used to send HTTP responses (JSON, status codes)
5+
import { z } from 'zod'; // Zod validates and parses input data
66

77
// Import database connection and the "report" table schema
8-
import { db } from "@src/server/db";
9-
import { report } from "@src/server/db/schema/reports";
8+
import { db } from '@src/server/db';
9+
import { report } from '@src/server/db/schema/reports';
1010

1111
// Import session helper to check if a user is logged in
12-
import { getServerAuthSession } from "@src/server/auth";
12+
import { getServerAuthSession } from '@src/server/auth';
1313

1414
// This ensures the API only accepts the correct fields
1515
const CreateReportSchema = z.object({
16-
fileId: z.string().min(1),
16+
fileId: z.string().min(1),
1717
category: z
18-
.enum(["inappropriate", "copyright", "spam", "other"])
19-
.default("other"),
18+
.enum(['inappropriate', 'copyright', 'spam', 'other'])
19+
.default('other'),
2020
details: z.string().min(1),
2121
});
2222

@@ -26,7 +26,7 @@ export async function POST(req: Request) {
2626

2727
// If there’s no session or no user ID, reject the request
2828
if (!session?.user?.id) {
29-
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
29+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
3030
}
3131

3232
// Try to parse and validate the incoming request body
@@ -35,8 +35,8 @@ export async function POST(req: Request) {
3535
body = CreateReportSchema.parse(await req.json());
3636
} catch (e) {
3737
return NextResponse.json(
38-
{ error: "Invalid body", details: (e as Error).message },
39-
{ status: 400 }
38+
{ error: 'Invalid body', details: (e as Error).message },
39+
{ status: 400 },
4040
);
4141
}
4242

src/server/db/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { env } from '@src/env.mjs';
44
import * as user from './schema/user';
55
import * as file from './schema/file';
66
import * as section from './schema/section';
7-
import * as report from "./schema/reports";
7+
import * as report from './schema/reports';
88
const schema = {
99
...file,
1010
...section,
1111
...user,
12-
...report
12+
...report,
1313
};
1414

1515
export const db = drizzle(env.DATABASE_URL, {

src/server/db/schema/reports.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
// Minimal table so API can insert a report.
22

3-
import { sql } from "drizzle-orm";
4-
import { pgTable, text, varchar, timestamp } from "drizzle-orm/pg-core";
5-
import { user } from "./user";
6-
import { file } from "./file";
3+
import { sql } from 'drizzle-orm';
4+
import { pgTable, text, varchar, timestamp } from 'drizzle-orm/pg-core';
5+
import { user } from './user';
6+
import { file } from './file';
77

8-
export const report = pgTable("report", {
9-
id: text("id")
8+
export const report = pgTable('report', {
9+
id: text('id')
1010
.default(sql`nanoid(20)`)
1111
.primaryKey(),
1212

13-
userId: text("user_id")
13+
userId: text('user_id')
1414
.notNull()
1515
.references(() => user.id),
1616

17-
fileId: text("file_id")
17+
fileId: text('file_id')
1818
.notNull()
1919
.references(() => file.id),
2020

2121
// Short category (e.g., "inappropriate", "copyright", "spam", "other")
22-
category: varchar("category", { length: 32 })
23-
.notNull()
24-
.default("other"),
22+
category: varchar('category', { length: 32 }).notNull().default('other'),
2523

2624
// Free-text explanation
27-
details: text("details").notNull(),
25+
details: text('details').notNull(),
2826

2927
// Created timestamp
30-
createdAt: timestamp("created_at", { mode: "date" })
28+
createdAt: timestamp('created_at', { mode: 'date' })
3129
.notNull()
3230
.default(sql`now()`),
3331
});

0 commit comments

Comments
 (0)