现在可以添加实体数据记录
This commit is contained in:
parent
359b7c9533
commit
607d3d86be
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {}
|
||||
|
|
|
@ -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<Post>,
|
||||
) { }
|
||||
|
||||
async store(data) {
|
||||
const entity = await this.postRepository.create(data);
|
||||
return await this.postRepository.save(entity);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue