This commit is contained in:
syuilo 2018-04-02 04:48:38 +09:00
parent ec4c6d48c1
commit 86e1ff6a6f
1 changed files with 44 additions and 41 deletions

View File

@ -39,7 +39,33 @@ export function isValidBirthday(birthday: string): boolean {
return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday); return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
} }
type ILocalAccount = { type IUserBase = {
_id: mongo.ObjectID;
createdAt: Date;
deletedAt: Date;
followersCount: number;
followingCount: number;
name: string;
postsCount: number;
driveCapacity: number;
username: string;
usernameLower: string;
avatarId: mongo.ObjectID;
bannerId: mongo.ObjectID;
data: any;
description: string;
latestPost: IPost;
pinnedPostId: mongo.ObjectID;
isSuspended: boolean;
keywords: string[];
hostLower: string;
};
export type IUser = ILocalUser | IRemoteUser;
export interface ILocalUser extends IUserBase {
host: null;
account: {
keypair: string; keypair: string;
email: string; email: string;
links: string[]; links: string[];
@ -68,8 +94,11 @@ type ILocalAccount = {
clientSettings: any; clientSettings: any;
settings: any; settings: any;
}; };
}
type IRemoteAccount = { export interface IRemoteUser extends IUserBase {
host: string;
account: {
inbox: string; inbox: string;
uri: string; uri: string;
publicKey: { publicKey: {
@ -77,33 +106,7 @@ type IRemoteAccount = {
publicKeyPem: string; publicKeyPem: string;
}; };
}; };
}
type IUserBase = {
_id: mongo.ObjectID;
createdAt: Date;
deletedAt: Date;
followersCount: number;
followingCount: number;
name: string;
postsCount: number;
driveCapacity: number;
username: string;
usernameLower: string;
avatarId: mongo.ObjectID;
bannerId: mongo.ObjectID;
data: any;
description: string;
latestPost: IPost;
pinnedPostId: mongo.ObjectID;
isSuspended: boolean;
keywords: string[];
hostLower: string;
};
export type IUser = ILocalUser | IRemoteUser;
export interface ILocalUser extends IUserBase { host: null; account: ILocalAccount; }
export interface IRemoteUser extends IUserBase { host: string; account: IRemoteAccount; }
export const isLocalUser = (user: any): user is ILocalUser => export const isLocalUser = (user: any): user is ILocalUser =>
user.host === null; user.host === null;