feat: build main page for DAV project and integrate database with Supabase and Prisma
This commit is contained in:
26
server/api/articles/index.get.ts
Normal file
26
server/api/articles/index.get.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import prisma from '~/lib/prisma';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const articles = await prisma.article.findMany();
|
||||
|
||||
if (!articles || articles.length === 0) {
|
||||
return {
|
||||
success: false,
|
||||
data: null,
|
||||
message: 'No articles found.',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: articles,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error fetching articles:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user