feat: enhance API response handling and add new components for module management
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
"exports": {
|
||||
"./actions": "./src/actions/index.ts",
|
||||
"./safe-action": "./src/actions/safe-action-client.ts",
|
||||
"./routes": "./src/routes/index.ts"
|
||||
"./routes": "./src/routes/index.ts",
|
||||
"./route-helpers": "./src/routes/api-helpers.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "git clean -xdf .turbo node_modules",
|
||||
|
||||
28
packages/next/src/routes/api-helpers.ts
Normal file
28
packages/next/src/routes/api-helpers.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'server-only';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import * as z from 'zod';
|
||||
|
||||
/**
|
||||
* Shared Zod schemas for public API route validation.
|
||||
*/
|
||||
export const emailSchema = z.string().email('Ungültige E-Mail-Adresse');
|
||||
|
||||
export const requiredString = (fieldName: string) =>
|
||||
z.string().min(1, `${fieldName} ist erforderlich`);
|
||||
|
||||
/**
|
||||
* Create a success JSON response.
|
||||
* Shape: { success: true, data: T }
|
||||
*/
|
||||
export function apiSuccess<T>(data: T, status = 200) {
|
||||
return NextResponse.json({ success: true, data }, { status });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an error JSON response.
|
||||
* Shape: { success: false, error: string }
|
||||
*/
|
||||
export function apiError(error: string, status = 400) {
|
||||
return NextResponse.json({ success: false, error }, { status });
|
||||
}
|
||||
Reference in New Issue
Block a user