當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript validator.isEmpty函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。