[API] Implement birthday setting
This commit is contained in:
parent
901ec06f3f
commit
fe691bccbf
3 changed files with 16 additions and 1 deletions
|
@ -38,7 +38,7 @@ block content
|
||||||
tr.nullable
|
tr.nullable
|
||||||
td birthday
|
td birthday
|
||||||
td String
|
td String
|
||||||
td 誕生日
|
td 誕生日(YYYY-MM-DD)
|
||||||
tr
|
tr
|
||||||
td created_at
|
td created_at
|
||||||
td Date
|
td Date
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
|
import { isValidBirthday } from '../../models/user';
|
||||||
import serialize from '../../serializers/user';
|
import serialize from '../../serializers/user';
|
||||||
import event from '../../event';
|
import event from '../../event';
|
||||||
|
|
||||||
|
@ -50,6 +51,16 @@ module.exports = async (params, user, _, isSecure) =>
|
||||||
user.bio = bio;
|
user.bio = bio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get 'birthday' parameter
|
||||||
|
const birthday = params.birthday;
|
||||||
|
if (birthday != null) {
|
||||||
|
if (!isValidBirthday(birthday)) {
|
||||||
|
return rej('invalid birthday');
|
||||||
|
}
|
||||||
|
|
||||||
|
user.birthday = birthday;
|
||||||
|
}
|
||||||
|
|
||||||
// Get 'avatar_id' parameter
|
// Get 'avatar_id' parameter
|
||||||
const avatar = params.avatar_id;
|
const avatar = params.avatar_id;
|
||||||
if (avatar !== undefined && avatar !== null) {
|
if (avatar !== undefined && avatar !== null) {
|
||||||
|
|
|
@ -8,3 +8,7 @@ export default collection;
|
||||||
export function validateUsername(username: string): boolean {
|
export function validateUsername(username: string): boolean {
|
||||||
return /^[a-zA-Z0-9\-]{3,20}$/.test(username);
|
return /^[a-zA-Z0-9\-]{3,20}$/.test(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isValidBirthday(birthday: string): boolean {
|
||||||
|
return /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue