Skip to content
Snippets Groups Projects
Commit 4f5928c5 authored by syuilo's avatar syuilo
Browse files

[API] Fix bug and extract validator

parent 4b906791
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
*/
import * as mongo from 'mongodb';
import User from '../../models/user';
import { isValidBirthday } from '../../models/user';
import { isValidName, isValidBirthday } from '../../models/user';
import serialize from '../../serializers/user';
import event from '../../event';
import config from '../../../conf';
......@@ -25,8 +25,8 @@ module.exports = async (params, user, _, isSecure) =>
// Get 'name' parameter
const name = params.name;
if (name !== undefined && name !== null) {
if (name.length > 50) {
return rej('too long name');
if (!isValidName(name)) {
return rej('invalid name');
}
user.name = name;
......
......@@ -15,6 +15,10 @@ export function validatePassword(password: string): boolean {
return typeof password == 'string' && password != '';
}
export function isValidName(name: string): boolean {
return typeof name == 'string' && name.length > 50 && name.trim() != '';
}
export function isValidBirthday(birthday: string): boolean {
return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment