本文整理汇总了TypeScript中article.IViewArticle.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IViewArticle.default方法的具体用法?TypeScript IViewArticle.default怎么用?TypeScript IViewArticle.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类article.IViewArticle
的用法示例。
在下文中一共展示了IViewArticle.default方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const convertArticle2APIResult = (article: IArticle): SafeSimpleArticle => {
const viewArticle = convertArticle2View(article)
return {
_id: viewArticle._id,
title: viewArticle.title,
key: viewArticle.key,
author: {
nickName: viewArticle.author.nickName,
},
summary: viewArticle.summary,
poster: viewArticle.poster,
song: viewArticle.song,
other: {
summaryHTML: viewArticle.other.summaryHTML,
},
info: {
likeCount: viewArticle.info.likeCount,
createTime: viewArticle.info.createTime,
updateTime: viewArticle.info.updateTime,
pv: viewArticle.info.pv,
createTimeString: viewArticle.info.createTimeString,
localDate: viewArticle.info.localDate,
}
}
}
示例2: updateArticlePV
export const detail = async (req: Request, res: Response) => {
if (!regMatchKey.test(req.params.key)) {
res.redirect('/404')
return
}
const articleModel = await getArticleByKey(req.params.key)
if (!articleModel) {
res.redirect('/404')
return
}
// 查询用户是否 like 了这篇文章
const userLike = await userLiked(res.locals.user._id, articleModel._id, LikeType.ARTICLE)
let likeIt = false
if (userLike > 0) {
likeIt = true
}
// 累加文章 pv
await updateArticlePV(articleModel._id)
const article = convertArticle2View(articleModel.toJSON() as IArticle)
article.info.pv++
if (res.locals.device === DEVICE.MOBILE) {
res.render('said/said-mobile-detail', {
title: `${article.title} - 听说`,
likeIt,
article,
})
} else {
res.render('said/said-detail', {
title: `${article.title} - 听说`,
pageIndex: 2,
likeIt,
article,
})
}
}