Skip to content

Commit b85ae33

Browse files
committed
style(template-api): aplicar auto-formateo y arreglar lint errors
Se aplican las reglas estrictas de BiomeJS a los archivos generados en template-api/ para que los proyectos inicien con 0 errores de linter. Se remueven types explícitos y se usa import type de manera consistente.
1 parent d988a78 commit b85ae33

5 files changed

Lines changed: 97 additions & 80 deletions

File tree

template-api/package.json

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
{
2-
"name": "{{PROJECT_NAME}}",
3-
"version": "0.1.0",
4-
"private": true,
5-
"scripts": {
6-
"dev": "next dev --turbopack",
7-
"build": "next build",
8-
"start": "next start",
9-
"lint": "biome check .",
10-
"lint:fix": "biome check --write .",
11-
"typecheck": "tsc --noEmit",
12-
"test": "vitest",
13-
"test:run": "vitest run",
14-
"db:push": "drizzle-kit push",
15-
"db:studio": "drizzle-kit studio"
16-
},
17-
"dependencies": {
18-
"next": "^15.0.0",
19-
"react": "^19.0.0",
20-
"react-dom": "^19.0.0",
21-
"zod": "^3.23.8",
22-
"drizzle-orm": "^0.36.1",
23-
"@libsql/client": "^0.14.0"
24-
},
25-
"devDependencies": {
26-
"@biomejs/biome": "^1.9.0",
27-
"@types/node": "^22.0.0",
28-
"@types/react": "^18.3.12",
29-
"@types/react-dom": "^18.3.1",
30-
"drizzle-kit": "^0.28.0",
31-
"typescript": "^5.6.3",
32-
"vitest": "^2.1.4",
33-
"node-mocks-http": "^1.16.1"
34-
},
35-
"engines": {
36-
"node": ">=20.0.0"
37-
}
2+
"name": "{{PROJECT_NAME}}",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev --turbopack",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "biome check .",
10+
"lint:fix": "biome check --write .",
11+
"typecheck": "tsc --noEmit",
12+
"test": "vitest",
13+
"test:run": "vitest run",
14+
"db:push": "drizzle-kit push",
15+
"db:studio": "drizzle-kit studio"
16+
},
17+
"dependencies": {
18+
"next": "^15.0.0",
19+
"react": "^19.0.0",
20+
"react-dom": "^19.0.0",
21+
"zod": "^3.23.8",
22+
"drizzle-orm": "^0.36.1",
23+
"@libsql/client": "^0.14.0"
24+
},
25+
"devDependencies": {
26+
"@biomejs/biome": "^1.9.0",
27+
"@types/node": "^22.0.0",
28+
"@types/react": "^18.3.12",
29+
"@types/react-dom": "^18.3.1",
30+
"drizzle-kit": "^0.28.0",
31+
"typescript": "^5.6.3",
32+
"vitest": "^2.1.4",
33+
"node-mocks-http": "^1.16.1"
34+
},
35+
"engines": {
36+
"node": ">=20.0.0"
37+
}
3838
}

template-api/src/app/api/users/route.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { type NextRequest } from "next/server";
2-
import { z } from "zod";
3-
import { db } from "@/lib/db";
4-
import { users } from "@/lib/schema";
51
import { errorResponse, successResponse } from "@/lib/api-response";
2+
import { db } from "@/lib/db";
63
import { BadRequestError } from "@/lib/errors";
4+
import { users } from "@/lib/schema";
5+
import type { NextRequest } from "next/server";
6+
import { z } from "zod";
77

88
const createUserSchema = z.object({
99
name: z.string().min(2, "Name must be at least 2 characters long"),
@@ -25,18 +25,29 @@ export async function POST(request: NextRequest) {
2525
const validation = createUserSchema.safeParse(body);
2626

2727
if (!validation.success) {
28-
throw new BadRequestError("Validation failed", validation.error.flatten().fieldErrors);
28+
throw new BadRequestError(
29+
"Validation failed",
30+
validation.error.flatten().fieldErrors,
31+
);
2932
}
3033

3134
const { name, email } = validation.data;
3235

3336
// Insert user and return inserted record
34-
const [newUser] = await db.insert(users).values({ name, email }).returning();
37+
const [newUser] = await db
38+
.insert(users)
39+
.values({ name, email })
40+
.returning();
3541

3642
return successResponse(newUser, 201);
37-
} catch (error: any) {
43+
} catch (error: unknown) {
3844
// Drizzle SQLite error for unique constraint
39-
if (error?.code === "SQLITE_CONSTRAINT_UNIQUE") {
45+
if (
46+
typeof error === "object" &&
47+
error !== null &&
48+
"code" in error &&
49+
(error as Record<string, unknown>).code === "SQLITE_CONSTRAINT_UNIQUE"
50+
) {
4051
return errorResponse(new BadRequestError("Email is already registered"));
4152
}
4253
return errorResponse(error);

template-api/src/middleware.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ export function middleware(request: NextRequest) {
66
const authHeader = request.headers.get("authorization");
77

88
// Si quieres proteger todas las rutas excepto /health, puedes hacerlo así:
9-
if (request.nextUrl.pathname.startsWith("/api") && !request.nextUrl.pathname.startsWith("/api/health")) {
9+
if (
10+
request.nextUrl.pathname.startsWith("/api") &&
11+
!request.nextUrl.pathname.startsWith("/api/health")
12+
) {
1013
if (!authHeader || !authHeader.startsWith("Bearer ")) {
1114
return NextResponse.json(
12-
{ success: false, error: "Unauthorized - Missing or invalid Bearer token" },
13-
{ status: 401 }
15+
{
16+
success: false,
17+
error: "Unauthorized - Missing or invalid Bearer token",
18+
},
19+
{ status: 401 },
1420
);
1521
}
1622

@@ -19,7 +25,7 @@ export function middleware(request: NextRequest) {
1925
if (token !== "demo-token-123") {
2026
return NextResponse.json(
2127
{ success: false, error: "Forbidden - Invalid token" },
22-
{ status: 403 }
28+
{ status: 403 },
2329
);
2430
}
2531
}

template-api/src/test/health.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { describe, expect, it } from "vitest";
2-
import { createMocks } from "node-mocks-http";
31
import { GET } from "@/app/api/health/route";
2+
import { createMocks } from "node-mocks-http";
3+
import { describe, expect, it } from "vitest";
44

55
describe("Healthcheck API", () => {
66
it("should return 200 and ok status", async () => {

template-api/tsconfig.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES2022",
4-
"module": "ESNext",
5-
"moduleResolution": "Bundler",
6-
"lib": ["ES2022"],
7-
"outDir": "./dist",
8-
"rootDir": "./",
9-
"strict": true,
10-
"noUncheckedIndexedAccess": true,
11-
"noImplicitOverride": true,
12-
"noFallthroughCasesInSwitch": true,
13-
"esModuleInterop": true,
14-
"skipLibCheck": true,
15-
"forceConsistentCasingInFileNames": true,
16-
"resolveJsonModule": true,
17-
"declaration": true,
18-
"sourceMap": true,
19-
"isolatedModules": true,
20-
"verbatimModuleSyntax": true,
21-
"plugins": [
22-
{
23-
"name": "next"
24-
}
25-
],
26-
"paths": {
27-
"@/*": ["./src/*"]
28-
}
29-
},
30-
"include": ["src/**/*", ".next/types/**/*.ts", "drizzle.config.ts"],
31-
"exclude": ["node_modules", "dist"]
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "Bundler",
6+
"lib": ["ES2022"],
7+
"outDir": "./dist",
8+
"rootDir": "./",
9+
"strict": true,
10+
"noUncheckedIndexedAccess": true,
11+
"noImplicitOverride": true,
12+
"noFallthroughCasesInSwitch": true,
13+
"esModuleInterop": true,
14+
"skipLibCheck": true,
15+
"forceConsistentCasingInFileNames": true,
16+
"resolveJsonModule": true,
17+
"declaration": true,
18+
"sourceMap": true,
19+
"isolatedModules": true,
20+
"verbatimModuleSyntax": true,
21+
"plugins": [
22+
{
23+
"name": "next"
24+
}
25+
],
26+
"paths": {
27+
"@/*": ["./src/*"]
28+
}
29+
},
30+
"include": ["src/**/*", ".next/types/**/*.ts", "drizzle.config.ts"],
31+
"exclude": ["node_modules", "dist"]
3232
}

0 commit comments

Comments
 (0)