实现添加博客
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user