export async function getServerSideProps({ params }: any) {
const articleID = params?.id;
const db = await prepareConnection();
const articleRepo = db.getRepository(Article);
const article = await articleRepo.findOne({
where: {
id: articleID,
},
relations: [
‘user’, ‘like_users’,
‘comments’,
‘comments.user’,
],
});
if (article) {
// 阅读次数 +1
article.views = article?.views + 1;
await articleRepo.save(article);
}
return {
props: {
article: JSON.parse(JSON.stringify(article)),
},
};
}
老师,这里的relations里面的数据能不能做一次筛选?还是说返回前端页面后再去写?我在typeorm查不到相关的用法,我想做的是过滤掉已经被删除的评论。目前是在接收props后处理