get all posts

This commit is contained in:
Guillaume Dorce 2022-08-25 12:26:00 +02:00
parent b7966be9ea
commit 5bcd23b3d3
2 changed files with 16 additions and 2 deletions

View File

@ -1,9 +1,16 @@
import { Router } from 'express'; import { Router } from 'express';
import { Post } from '@prisma/client';
import { getAllPosts } from '@/controller/PostController';
const posts = Router(); const posts = Router();
posts.get('/', (req, res) => { posts.get('/', async (req, res) => {
res.send('Hello World!'); try {
const postList: Post[] = await getAllPosts();
return res.status(200).send(postList);
} catch (error) {
res.status(500).send(error);
}
}); });
export default posts; export default posts;

View File

@ -0,0 +1,7 @@
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const getAllPosts = () => prisma.post.findMany();
export { getAllPosts };