Coerce values to string before using validator methods

This commit is contained in:
Berkeley Martinez
2016-03-13 18:04:24 -07:00
parent cf4b862c4c
commit e657b96dbc
3 changed files with 7 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import { isAlphanumeric, isHexadecimal } from 'validator';
import { isAlphanumeric, isMongoId } from 'validator';
import debug from 'debug';
const log = debug('fcc:models:promo');
@@ -6,16 +6,16 @@ const log = debug('fcc:models:promo');
export default function promo(Promo) {
Promo.getButton = function getButton(id, code, type = 'isNot') {
const Job = Promo.app.models.Job;
if (!id || !isHexadecimal(id)) {
if (!id || !isMongoId('' + id)) {
return Promise.reject(new Error(
'Must include job id'
));
}
if (
!isAlphanumeric(code) &&
!isAlphanumeric('' + code) &&
type &&
!isAlphanumeric(type)
!isAlphanumeric('' + type)
) {
return Promise.reject(new Error(
'Code or Type should be an alphanumeric'