This commit is contained in:
syuilo 2017-03-03 09:15:38 +09:00
parent b654c9df66
commit 101e0a4430
2 changed files with 34 additions and 48 deletions

View File

@ -23,9 +23,9 @@ module.exports = async (params, user, _, isSecure) =>
new Promise(async (res, rej) =>
{
// Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().validate(isValidName).qed();
const [name, nameErr] = it(params.name).expect.string().notNull().validate(isValidName).qed();
if (nameErr) return rej('invalid name param');
user.name = name;
if (name) user.name = name;
// Get 'description' parameter
const description = params.description;

View File

@ -53,8 +53,16 @@ class QueryCore implements Query {
this.error = null;
}
get isUndefined() {
return this.value === undefined;
}
get isNull() {
return this.value === null;
}
get isEmpty() {
return this.value === undefined || this.value === null;
return this.isUndefined || this.isNull;
}
/**
@ -65,7 +73,7 @@ class QueryCore implements Query {
}
/**
*
*
*/
required() {
if (this.error === null && this.isEmpty) {
@ -75,10 +83,30 @@ class QueryCore implements Query {
}
/**
*
* (=undefined)
*/
notUndefined() {
if (this.error === null && this.isUndefined) {
this.error = new Error('required');
}
return this;
}
/**
* null
*/
notNull() {
if (this.error === null && this.isNull) {
this.error = new Error('required');
}
return this;
}
/**
* (=undefined)
*/
default(value: any) {
if (this.isEmpty) {
if (this.isUndefined) {
this.value = value;
}
return this;
@ -119,13 +147,6 @@ class BooleanQuery extends QueryCore {
}
}
/**
* undefined  null
*/
required() {
return super.required();
}
/**
*
*/
@ -198,13 +219,6 @@ class NumberQuery extends QueryCore {
return this;
}
/**
* undefined  null
*/
required() {
return super.required();
}
/**
*
*/
@ -259,13 +273,6 @@ class StringQuery extends QueryCore {
return this;
}
/**
* undefined  null
*/
required() {
return super.required();
}
/**
*
*/
@ -361,13 +368,6 @@ class ArrayQuery extends QueryCore {
return this;
}
/**
* undefined  null
*/
required() {
return super.required();
}
/**
*
*/
@ -403,13 +403,6 @@ class IdQuery extends QueryCore {
}
}
/**
* undefined  null
*/
required() {
return super.required();
}
/**
*
*/
@ -445,13 +438,6 @@ class ObjectQuery extends QueryCore {
}
}
/**
* undefined  null
*/
required() {
return super.required();
}
/**
*
*/