• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript validator.isEmpty函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了isEmpty函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: update

export function update(req: Request, res: Response): void {
  const [creator, creatorRef] = UTIL.getLoginedUser(req),
    slug: string = req.params.slug,
    title: string = req.body.title,
    body: any = UTIL.sanitizeInput(req.routeVar.contentType, req.body)

  if (!creator || validator.isEmpty(creatorRef)) {
    res.status(422).json({ code: ERRORS.CONTENT.CONTENT_CREATOR_REQUIRED })
  } else if (title && validator.isEmpty(title)) {
    res.status(422).json({ code: ERRORS.CONTENT.CONTENT_TITLE_REQUIRED })
  } else if (slug && validator.isEmpty(slug)) {
    res.status(422).json({ code: ERRORS.CONTENT.CONTENT_SLUG_REQUIRED })
  } else {
    let log: any = {
      creator,
      creatorRef,
      targetRef: req.routeVar.contentType,
      action: CONST.USER_ACTIONS.COMMON.UPDATE,
      ua: req.body.ua || req.ua
    }

    const DataModel = UTIL.getModelFromName(req.routeVar.contentType)

    DataModel
    .findOneAndUpdate({creator, slug}, body, {new: true})
    .then((data: IContent) => {
      if (data) {
        res.status(200).json(data)
        log.target = data._id
        return data
      }

      res.status(404).send()
      return null
    })
    .then((data: IContent) => {
      new Logger(log)
    })
    .catch((err: Error) => {
      new Err(res, err, log)
    })
  }
}
开发者ID:yeegr,项目名称:SingularJS,代码行数:43,代码来源:ContentController.ts


示例2: create

export function create(req: Request, res: Response): void {
  const [creator, creatorRef] = UTIL.getLoginedUser(req),
    title: string = req.body.title,
    slug: string = req.body.slug

  // verify logined user
  if (!creator || validator.isEmpty(creatorRef)) {
    res.status(422).json({ code: ERRORS.CONTENT.CONTENT_CREATOR_REQUIRED })
  // check if content has title
  } else if (!title || validator.isEmpty(title)) {
    res.status(422).json({ code: ERRORS.CONTENT.CONTENT_TITLE_REQUIRED })
  } else {
    const [UserModel, DataModel] = UTIL.getModels(req)

    const data: IContent = new DataModel(Object.assign({}, {
        creator,
        ref: creatorRef
      }, UTIL.sanitizeInput(req.routeVar.contentType, req.body)))

    let log: any = {
      creator,
      creatorRef,
      targetRef: req.routeVar.contentType,
      action: CONST.USER_ACTIONS.COMMON.CREATE,
      ua: req.body.ua || req.ua
    }

    data
    .save()
    .then((content: IContent) => {
      res.status(201).json(content)
      log.target = content._id

      return UserModel.findByIdAndUpdate(creator, UTIL.getIncrement(req, 1))
    })
    .then((user: IUser) => {
      new Logger(log)
    })
    .catch((err: Error) => {
      new Err(res, err, log)
    })
  }
}
开发者ID:yeegr,项目名称:SingularJS,代码行数:43,代码来源:ContentController.ts


示例3: if

  .then((data: IContent) => {
    if (data) {
      if (data.status === CONST.STATUSES.CONTENT.PENDING || data.status === CONST.STATUSES.CONTENT.APPROVED) {
        res.status(422).json({ code: ERRORS.CONTENT.CONTENT_ALREADY_SUMMITED })
      } else if (validator.isEmpty(data.title)) {
        res.status(422).json({ code: ERRORS.CONTENT.CONTENT_TITLE_REQUIRED })
      } else if (validator.isEmpty(data.slug)) {
        res.status(422).json({ code: ERRORS.CONTENT.CONTENT_SLUG_REQUIRED })
      } else if (validator.isEmpty(data.content)) {
        res.status(422).json({ code: ERRORS.CONTENT.CONTENT_CONTENT_REQUIRED })
      } else {
        // approval ? pending : approved
        switch (targetRef) {
          case CONST.ACTION_TARGETS.POST:
            if (CONFIG.POST_REQUIRES_APPROVAL && roles.indexOf(CONFIG.POST_SELF_PUBLISH_ROLE) < 0) {
              data.status = CONST.STATUSES.CONTENT.PENDING
            } else {
              data.status = CONST.STATUSES.CONTENT.APPROVED
            }
          break

          case CONST.ACTION_TARGETS.EVENT:
            if (CONFIG.PUBLIC_EVENT_REQURIES_APPROVAL && data.isPublic && roles.indexOf(CONFIG.PUBLIC_EVENT_PUBLISH_ROLE) > -1) {
              data.status = CONST.STATUSES.CONTENT.PENDING
            } else {
              data.status = CONST.STATUSES.CONTENT.APPROVED
            }
          break

          default:
            data.status = CONST.STATUSES.CONTENT.APPROVED
          break
        }

        return data.save()
      }
    }

    res.status(404).send({ code: ERRORS.CONTENT.NO_ELIGIBLE_CONTENT_FOUND })
    return null
  })
开发者ID:yeegr,项目名称:SingularJS,代码行数:41,代码来源:UserController.ts


示例4:

  result = validator.isCurrency('sample', isCurrencyOptions);

  result = validator.isDataURI('sample');

  let isDecimalOptions: ValidatorJS.IsDecimalOptions = {};
  result = validator.isDecimal('sample');
  result = validator.isDecimal('sample', isDecimalOptions);

  result = validator.isDivisibleBy('sample', 2);

  let isEmailOptions: ValidatorJS.IsEmailOptions = {};
  result = validator.isEmail('sample');
  result = validator.isEmail('sample', isEmailOptions);

  let isEmptyOptions: ValidatorJS.IsEmptyOptions = {};
  result = validator.isEmpty('sample');
  result = validator.isEmpty('sample', isEmptyOptions);

  let isFQDNOptions: ValidatorJS.IsFQDNOptions = {};
  result = validator.isFQDN('sample');
  result = validator.isFQDN('sample', isFQDNOptions);

  let isFloatOptions: ValidatorJS.IsFloatOptions = {};
  result = validator.isFloat('sample');
  result = validator.isFloat('sample', isFloatOptions);

  result = validator.isFullWidth('sample');

  result = validator.isHalfWidth('sample');

  result = validator.isHash('sample', 'md4');
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:31,代码来源:validator-tests.ts


示例5:

  result = validator.isCurrency('sample');
  result = validator.isCurrency('sample', isCurrencyOptions);

  result = validator.isDataURI('sample');

  let isDecimalOptions: ValidatorJS.IsDecimalOptions = {};
  result = validator.isDecimal('sample');
  result = validator.isDecimal('sample', isDecimalOptions);

  result = validator.isDivisibleBy('sample', 2);

  let isEmailOptions: ValidatorJS.IsEmailOptions = {};
  result = validator.isEmail('sample');
  result = validator.isEmail('sample', isEmailOptions);

  result = validator.isEmpty('sample');

  let isFQDNOptions: ValidatorJS.IsFQDNOptions = {};
  result = validator.isFQDN('sample');
  result = validator.isFQDN('sample', isFQDNOptions);

  let isFloatOptions: ValidatorJS.IsFloatOptions = {};
  result = validator.isFloat('sample');
  result = validator.isFloat('sample', isFloatOptions);

  result = validator.isFullWidth('sample');

  result = validator.isHalfWidth('sample');

  result = validator.isHash('sample', 'md4');
  result = validator.isHash('sample', 'md5');
开发者ID:Rick-Kirkham,项目名称:DefinitelyTyped,代码行数:31,代码来源:validator-tests.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript validator.isFQDN函数代码示例发布时间:2022-05-25
下一篇:
TypeScript validator.isEmail函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap