本文整理汇总了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)
})
}
}
示例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)
})
}
}
示例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
})
示例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');
示例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');