import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Post } from './Post.entity'; @Injectable() export class PostsService { constructor( @InjectRepository(Post) private PostsRepository: Repository, ) {} findAll(): Promise { return this.PostsRepository.find(); } findOne(id: number): Promise { return this.PostsRepository.findOneBy({ id }); } async create(title: string, body: string) Promise { const newPost = this.PostsRepository.create({ title: title, body: body }); const post = await this.PostsRepository.save(newPost); return post.id; } async remove(id: number): Promise { await this.PostsRepository.delete(id); } }