diff --git a/src/modules/post/post.controller.ts b/src/modules/post/post.controller.ts index 5ef33dd..51bebea 100644 --- a/src/modules/post/post.controller.ts +++ b/src/modules/post/post.controller.ts @@ -1,4 +1,14 @@ -import { Controller } from '@nestjs/common'; +import { Controller, Post, Body } from '@nestjs/common'; +import { PostService } from './post.service'; @Controller('posts') -export class PostController {} +export class PostController { + constructor( + private readonly postService: PostService, + ) { } + + @Post() + async store(@Body() data) { + return await this.postService.store(data); + } +} diff --git a/src/modules/post/post.module.ts b/src/modules/post/post.module.ts index af735ef..a43b068 100644 --- a/src/modules/post/post.module.ts +++ b/src/modules/post/post.module.ts @@ -1,9 +1,14 @@ import { Module } from '@nestjs/common'; import { PostController } from './post.controller'; import { PostService } from './post.service'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Post } from './post.entity'; @Module({ + imports: [ + TypeOrmModule.forFeature([Post]), + ], controllers: [PostController], - providers: [PostService] + providers: [PostService], }) export class PostModule {} diff --git a/src/modules/post/post.service.ts b/src/modules/post/post.service.ts index 1e36a92..8a4d974 100644 --- a/src/modules/post/post.service.ts +++ b/src/modules/post/post.service.ts @@ -1,4 +1,17 @@ import { Injectable } from '@nestjs/common'; +import { Repository } from 'typeorm'; +import { Post } from './post.entity'; +import { InjectRepository } from '@nestjs/typeorm'; @Injectable() -export class PostService {} +export class PostService { + constructor( + @InjectRepository(Post) + private readonly postRepository: Repository, + ) { } + + async store(data) { + const entity = await this.postRepository.create(data); + return await this.postRepository.save(entity); + } +}