server/database/entities/User.ts

69 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-09-11 05:54:14 +02:00
import { getConfig, getHost } from "@config";
2023-09-11 05:31:08 +02:00
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
2023-09-11 05:54:14 +02:00
import { Account } from "~types/entities/account";
const config = getConfig();
2023-09-11 05:31:08 +02:00
@Entity({
name: "users",
})
export class User extends BaseEntity {
@PrimaryGeneratedColumn("uuid")
id!: string;
2023-09-11 05:54:14 +02:00
@Column("varchar", {
unique: true,
})
2023-09-11 05:31:08 +02:00
username!: string;
@Column("varchar")
password!: string;
2023-09-11 05:54:14 +02:00
@Column("varchar", {
unique: true,
})
email!: string;
@Column("varchar", {
default: "",
})
bio!: string;
2023-09-11 05:31:08 +02:00
@CreateDateColumn()
created_at!: Date;
@UpdateDateColumn()
updated_at!: Date;
2023-09-11 05:54:14 +02:00
toAccount(): Account {
return {
acct: `@${this.username}@${getHost()}`,
avatar: "",
avatar_static: "",
bot: false,
created_at: this.created_at.toISOString(),
display_name: "",
followers_count: 0,
following_count: 0,
group: false,
header: "",
header_static: "",
id: this.id,
locked: false,
moved: null,
noindex: false,
note: this.bio,
suspended: false,
url: `${config.http.base_url}/@${this.username}`,
username: this.username,
emojis: [],
fields: [],
limited: false,
source: undefined,
statuses_count: 0,
discoverable: undefined,
role: undefined,
mute_expires_at: undefined,
}
}
2023-09-11 05:31:08 +02:00
}