实现添加博客

This commit is contained in:
2025-05-16 21:58:33 +08:00
parent 65303ac988
commit 59a68b372b
13 changed files with 260 additions and 39 deletions

View File

@@ -15,9 +15,28 @@ export class BlogService {
return this.blogRepository.find({
where: { deletedAt: null },
order: {
publishAt: 'DESC',
createdAt: 'DESC',
}
})
}
async create(blog: Partial<Blog>) {
const newBlog = this.blogRepository.create(blog);
return this.blogRepository.save(newBlog);
}
async update(id: string, blog: Partial<Blog>) {
await this.blogRepository.update(id, blog);
return this.blogRepository.findOneBy({ id });
}
async remove(id: string) {
const blog = await this.blogRepository.findOneBy({ id });
if (!blog) return null;
return this.blogRepository.softRemove(blog);
}
async findById(id: string) {
return this.blogRepository.findOneBy({ id });
}
}