本文整理匯總了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');