server/database/entities/User.ts

86 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-09-11 05:54:14 +02:00
import { getConfig, getHost } from "@config";
2023-09-13 02:29:13 +02:00
import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
2023-09-12 22:48:10 +02:00
import { APIAccount } from "~types/entities/account";
2023-09-11 05:54:14 +02:00
const config = getConfig();
2023-09-11 05:31:08 +02:00
2023-09-12 22:48:10 +02:00
/**
* Stores local and remote users
*/
2023-09-11 05:31:08 +02:00
@Entity({
name: "users",
})
2023-09-12 22:48:10 +02:00
export class User extends BaseEntity {
2023-09-11 05:31:08 +02:00
@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;
2023-09-12 22:48:10 +02:00
@Column("varchar", {
2023-09-13 07:30:45 +02:00
unique: true,
2023-09-12 22:48:10 +02:00
})
2023-09-13 07:30:45 +02:00
display_name!: string;
@Column("varchar")
password!: string;
2023-09-11 05:31:08 +02:00
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
2023-09-12 22:48:10 +02:00
// eslint-disable-next-line @typescript-eslint/require-await
async toAPI(): Promise<APIAccount> {
2023-09-11 05:54:14 +02:00
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-13 02:29:13 +02:00
};
2023-09-11 05:54:14 +02:00
}
2023-09-13 02:29:13 +02:00
}