当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript article.IViewArticle类代码示例

本文整理汇总了TypeScript中article.IViewArticle的典型用法代码示例。如果您正苦于以下问题:TypeScript IViewArticle类的具体用法?TypeScript IViewArticle怎么用?TypeScript IViewArticle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IViewArticle类的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,
    }
  }
}
开发者ID:linkFly6,项目名称:Said,代码行数:25,代码来源:article.ts

示例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,
    })
  }
}
开发者ID:linkFly6,项目名称:Said,代码行数:39,代码来源:article.ts


注:本文中的article.IViewArticle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。