Finalize template
This commit is contained in:
@@ -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],
|
||||
})
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
7
apps/api/src/modules/users/posts.module.ts
Normal file
7
apps/api/src/modules/users/posts.module.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PostsController } from './controllers/posts/posts.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [PostsController],
|
||||
})
|
||||
export class PostsModule {}
|
||||
Reference in New Issue
Block a user