mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-01 03:41:59 +01:00
Refactor
This commit is contained in:
parent
86e1ff6a6f
commit
6b6adeaa68
1 changed files with 26 additions and 26 deletions
|
@ -15,30 +15,6 @@ User.createIndex('account.token');
|
|||
|
||||
export default User;
|
||||
|
||||
export function validateUsername(username: string): boolean {
|
||||
return typeof username == 'string' && /^[a-zA-Z0-9\-]{3,20}$/.test(username);
|
||||
}
|
||||
|
||||
export function validatePassword(password: string): boolean {
|
||||
return typeof password == 'string' && password != '';
|
||||
}
|
||||
|
||||
export function isValidName(name: string): boolean {
|
||||
return typeof name == 'string' && name.length < 30 && name.trim() != '';
|
||||
}
|
||||
|
||||
export function isValidDescription(description: string): boolean {
|
||||
return typeof description == 'string' && description.length < 500 && description.trim() != '';
|
||||
}
|
||||
|
||||
export function isValidLocation(location: string): boolean {
|
||||
return typeof location == 'string' && location.length < 50 && location.trim() != '';
|
||||
}
|
||||
|
||||
export function isValidBirthday(birthday: string): boolean {
|
||||
return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
|
||||
}
|
||||
|
||||
type IUserBase = {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
|
@ -61,8 +37,6 @@ type IUserBase = {
|
|||
hostLower: string;
|
||||
};
|
||||
|
||||
export type IUser = ILocalUser | IRemoteUser;
|
||||
|
||||
export interface ILocalUser extends IUserBase {
|
||||
host: null;
|
||||
account: {
|
||||
|
@ -108,12 +82,38 @@ export interface IRemoteUser extends IUserBase {
|
|||
};
|
||||
}
|
||||
|
||||
export type IUser = ILocalUser | IRemoteUser;
|
||||
|
||||
export const isLocalUser = (user: any): user is ILocalUser =>
|
||||
user.host === null;
|
||||
|
||||
export const isRemoteUser = (user: any): user is IRemoteUser =>
|
||||
!isLocalUser(user);
|
||||
|
||||
export function validateUsername(username: string): boolean {
|
||||
return typeof username == 'string' && /^[a-zA-Z0-9\-]{3,20}$/.test(username);
|
||||
}
|
||||
|
||||
export function validatePassword(password: string): boolean {
|
||||
return typeof password == 'string' && password != '';
|
||||
}
|
||||
|
||||
export function isValidName(name: string): boolean {
|
||||
return typeof name == 'string' && name.length < 30 && name.trim() != '';
|
||||
}
|
||||
|
||||
export function isValidDescription(description: string): boolean {
|
||||
return typeof description == 'string' && description.length < 500 && description.trim() != '';
|
||||
}
|
||||
|
||||
export function isValidLocation(location: string): boolean {
|
||||
return typeof location == 'string' && location.length < 50 && location.trim() != '';
|
||||
}
|
||||
|
||||
export function isValidBirthday(birthday: string): boolean {
|
||||
return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
|
||||
}
|
||||
|
||||
export function init(user): IUser {
|
||||
user._id = new mongo.ObjectID(user._id);
|
||||
user.avatarId = new mongo.ObjectID(user.avatarId);
|
||||
|
|
Loading…
Reference in a new issue