task-d.7.4
This commit is contained in:
39
src/app/api/setup/templates/route.ts
Normal file
39
src/app/api/setup/templates/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { AuthError, requireSystemRole } from '@/lib/auth/session';
|
||||
|
||||
type SetupTemplateMetadata = {
|
||||
version: string;
|
||||
generatedFrom: string;
|
||||
templates: Array<{
|
||||
file: string;
|
||||
seedType: string;
|
||||
importOrder: number;
|
||||
supported: boolean;
|
||||
requiredColumns: string[];
|
||||
description: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await requireSystemRole('super_admin');
|
||||
const metadataPath = path.join(process.cwd(), 'setup', 'templates', 'templates.json');
|
||||
const metadata = JSON.parse(await readFile(metadataPath, 'utf8')) as SetupTemplateMetadata;
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
time: new Date().toISOString(),
|
||||
version: metadata.version,
|
||||
generatedFrom: metadata.generatedFrom,
|
||||
templates: metadata.templates
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
return NextResponse.json({ message: error.message }, { status: error.status });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: 'Unable to load setup templates' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user