Files
d43e5f9378 docs: Convert relative imports to @ aliases in examples (#83813)
## For Contributors

### Improving Documentation

This PR improves the Next.js examples by converting relative imports to
@ aliases, making them more readable and maintainable.

## Description

Fixes #83717 by converting deep relative imports to clean @ aliases in
Next.js examples.

Currently, Next.js examples use long relative imports like:
```typescript
import { i18n, type Locale } from "../../../i18n-config";
```
This PR updates them to use clean @ aliases:
```typescript
import { i18n, type Locale } from "@/i18n-config";
```

## Changes Made

- **Added path alias configuration** `"@/*": ["./*"]` to tsconfig.json
files
- **Converted deep relative imports** (d:) to clean @ aliases (`@/`)
- **Updated examples**:
  - `i18n-routing` (specifically mentioned in issue #83717) - 5 files
  - `with-typescript` - 2 files  
  - `with-grafbase` - 2 files
  - `with-mongodb-mongoose` - 2 files

## Benefits

-  **Improved readability**: `@/config` vs `../../../config`
-  **Reduced errors**: No need to count `../` levels when refactoring
-  **Better maintainability**: Easier to move files around
-  **Modern standards**: Aligns with production Next.js practices
-  **Better IDE support**: Enhanced autocomplete and navigation

## Examples of Changes

### Before:
```typescript
import { i18n, type Locale } from "../../../i18n-config";
import { getDictionary } from "../../get-dictionary";
import { grafbase } from "../../../lib/grafbase";
```

### After:
```typescript
import { i18n, type Locale } from "@/i18n-config";
import { getDictionary } from "@/get-dictionary";
import { grafbase } from "@/lib/grafbase";
```

## Testing

-  TypeScript compilation works correctly
-  @ imports resolve properly in IDE
-  Runtime functionality preserved
-  No breaking changes to example functionality

This change is purely a developer experience improvement and doesn't
affect runtime behavior.

---------

Co-authored-by: dharunr36 <[email protected]>
Co-authored-by: Joseph <[email protected]>
2025-09-16 15:53:53 +02:00

37 lines
928 B
TypeScript

import { NextApiRequest, NextApiResponse } from "next";
import dbConnect from "@/lib/dbConnect";
import Pet from "@/models/Pet";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const { method } = req;
await dbConnect();
switch (method) {
case "GET":
try {
const pets = await Pet.find({}); /* find all the data in our database */
res.status(200).json({ success: true, data: pets });
} catch (error) {
res.status(400).json({ success: false });
}
break;
case "POST":
try {
const pet = await Pet.create(
req.body,
); /* create a new model in the database */
res.status(201).json({ success: true, data: pet });
} catch (error) {
res.status(400).json({ success: false });
}
break;
default:
res.status(400).json({ success: false });
break;
}
}