Finalize template
This commit is contained in:
17
apps/api/Dockerfile.dev
Normal file
17
apps/api/Dockerfile.dev
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM node:20-bookworm-slim
|
||||
|
||||
WORKDIR /app
|
||||
RUN corepack enable
|
||||
|
||||
# Dependencies (from workspace root)
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install
|
||||
|
||||
# Monorepo structure
|
||||
COPY nx.json tsconfig.base.json ./
|
||||
COPY apps/api ./apps/api
|
||||
COPY libs ./libs
|
||||
COPY prisma ./prisma
|
||||
|
||||
ENV PORT=3000
|
||||
CMD ["pnpm", "nx", "serve", "api"]
|
||||
@@ -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