Finalize template

This commit is contained in:
Toni Koskinen
2026-03-26 13:45:33 +02:00
parent 1786acc75c
commit 4517620d9e
12 changed files with 158 additions and 3 deletions

View File

@@ -1,9 +1,10 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PostsModule } from '../modules/users/posts.module';
@Module({
imports: [],
imports: [PostsModule],
controllers: [AppController],
providers: [AppService],
})

View File

@@ -0,0 +1,25 @@
import { Controller, Get, NotFoundException, Param } from '@nestjs/common';
import { Post } from '@shared/prisma-generated/src/types';
import { prisma } from '@shared/prisma-generated/src/prisma';
@Controller('posts')
export class PostsController {
@Get()
async findAll(): Promise<Post[]> {
const posts = await prisma.post.findMany();
return posts;
}
@Get(':id')
async findById(@Param('id') id: string): Promise<Post> {
const post = await prisma.post.findUnique({
where: { id },
});
if (!post) {
throw new NotFoundException(`Post with id ${id} not found`);
}
return post;
}
}

View File

@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { PostsController } from './controllers/posts/posts.controller';
@Module({
controllers: [PostsController],
})
export class PostsModule {}