feat(FE) : setting access page master
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
interface Halaman {
|
||||
id: number;
|
||||
name: string;
|
||||
url: string;
|
||||
level: number;
|
||||
parent?: number;
|
||||
icon?: string;
|
||||
role: string[];
|
||||
}
|
||||
|
||||
const filePath = path.resolve('data/mock/halaman.json');
|
||||
|
||||
// Helper to read JSON file
|
||||
const readData = (): Halaman[] => {
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, 'utf-8');
|
||||
return JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error('Error reading halaman.json:', error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const method = event.method;
|
||||
|
||||
// GET - Get all halaman
|
||||
if (method === 'GET') {
|
||||
try {
|
||||
const data = readData();
|
||||
return {
|
||||
success: true,
|
||||
data
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Gagal memuat data halaman',
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: 'Method not allowed'
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user